Go to the documentation of this file.00001 #include "NoisyVariableRel.h"
00002
00003
00004 NoisyVariableRel::NoisyVariableRel(SharedPointer<VariableRelation> origRel, SharedPointer<IVariableValue> noisyValue, double noisyProbability, SharedPointer<IVariableValue> otherValue)
00005 {
00006 this->origRel = origRel;
00007 this->noisyValue = noisyValue;
00008 this->noisyProbability = noisyProbability;
00009 this->otherValue = otherValue;
00010
00011 for(int i = 0 ; i < origRel->getSourceVars().size() ; i ++)
00012 {
00013 SharedPointer<IVariable> srcVar = origRel->getSourceVars()[i];
00014 this->addSourceVar(srcVar);
00015 }
00016
00017 this->setDestVariable(origRel->getDestVariable());
00018 }
00019
00020 NoisyVariableRel::~NoisyVariableRel(void)
00021 {
00022 }
00023
00024 vector<SharedPointer<RelEntry> > NoisyVariableRel::getProb(map<string, SharedPointer<IVariableValue> > sourceVals)
00025 {
00026 vector<SharedPointer<RelEntry> > result = origRel->getProb(sourceVals);
00027
00028 string destVarName = origRel->getDestVariable()->getVariableName();
00029
00030 vector<SharedPointer<RelEntry> > result2;
00031 for(int j = 0 ; j < result.size(); j ++)
00032 {
00033 SharedPointer<RelEntry>& srcEntry = result[j];
00034 SharedPointer<IVariableValue>& val = srcEntry->destValues[destVarName];
00035 if(val->getIndex() == noisyValue->getIndex())
00036 {
00037
00038 {
00039 SharedPointer<IVariableValue> resultValue = this->noisyValue;
00040 assert(otherValue->getVariableName() == this->getDestVariable()->getVariableName());
00041 SharedPointer<RelEntry> newEntry (new RelEntry());
00042
00043 newEntry->destValues[destVarName] = resultValue;
00044 newEntry->prob = this->noisyProbability;
00045 result2.push_back(newEntry);
00046 }
00047 {
00048 SharedPointer<IVariableValue> resultValue = this->otherValue;
00049 assert(otherValue->getVariableName() == this->getDestVariable()->getVariableName());
00050 SharedPointer<RelEntry> newEntry (new RelEntry());
00051
00052 newEntry->destValues[destVarName] = resultValue;
00053 newEntry->prob = 1- this->noisyProbability;
00054 result2.push_back(newEntry);
00055 }
00056 }
00057 else
00058 {
00059
00060 result2.push_back(srcEntry);
00061 }
00062
00063
00064
00065 }
00066
00067 return result2;
00068 }