- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/BFTEObjectiveFunction.cpp

    00001
    00002 //
    00003 // Copyright (c) 2005           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:                        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "BFTEObjectiveFunction.h"
    00015
    00016 #ifdef _MSC_VER
    00017 #pragma warning( disable : 4786 )
    00018 #endif
    00019
    00020 #include <Mers/Estimation/Discrete/Trajectories.h>
    00021 #include <Mers/Estimation/Discrete/Estimate.h>
    00022
    00023 #include <Mers/Generators/BFIG/BFIGAssignment.h>
    00024 #include <Mers/Generators/BFIG/BFIGVariable.h>
    00025 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00026 #include <Mers/Models/Base/BaseModelVariable.h>
    00027 #include <Mers/Models/Base/BaseModelValue.h>
    00028 #include <Mers/Models/Base/BaseModelAssignment.h>
    00029 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00030
    00031 using Mers::Estimation::Discrete::BFTEObjectiveFunction;
    00032 using Mers::Estimation::Discrete::Trajectories;
    00033 using Mers::Estimation::Discrete::Estimate;
    00034 using Mers::Generators::BFIG::BFIGAssignment;
    00035 using Mers::Generators::BFIG::BFIGVariable;
    00036 using Mers::Models::Base::BaseModelVariableArray;
    00037 using Mers::Models::Base::BaseModelVariable;
    00038 using Mers::Models::Base::BaseModelValue;
    00039 using Mers::Models::Base::BaseModelAssignment;
    00040 using Mers::Models::Base::BaseModelAssignmentArray;
    00041 using std::vector;
    00042 using std::map;
    00043 using std::pair;
    00044 using std::cout;
    00045 using std::endl;
    00046
    00048 //      CONSTRUCTOR
    00050
    00051 BFTEObjectiveFunction::BFTEObjectiveFunction(BaseModelVariableArray const * dVs,
    00052                 const map<unsigned int,unsigned int> pMap, vector<double> allTransProbs, map<unsigned int,double> sProbs)
    00053 : MEObjectiveFunction(dVs, pMap, allTransProbs, sProbs)
    00054 {}
    00055
    00057
    00058 BFTEObjectiveFunction::~BFTEObjectiveFunction()
    00059 {
    00060 }
    00061
    00062
    00064 //      PUBLIC METHODS
    00066
    00067
    00068
    00069
    00071 //      PROTECTED METHODS
    00073
    00074 double
    00075 BFTEObjectiveFunction::calculateUtility(vector<BaseModelAssignment const *> & bmAssignments,
    00076                                                                                 int sourceStateIndex) const
    00077 {
    00078         double trajectoryProb = 1.0;
    00079         unsigned int j, varUID;
    00080         unsigned int numSourceStates = (unsigned int) sourceStateProbabilities.size();
    00081
    00082         map<unsigned int, bool> wasAssigned;
    00083         map<unsigned int, unsigned int> assignedValue;
    00084         for(j=0; j<decisionVariables->getLength(); j++)
    00085                 wasAssigned[(*decisionVariables)[j]->getUID()] = false;
    00086
    00087         for(j=0; j<bmAssignments.size(); j++)
    00088         {
    00089                 varUID = bmAssignments[j]->getVariable()->getUID();
    00090                 wasAssigned[varUID] = true;
    00091                 assignedValue[varUID] = bmAssignments[j]->getValue()->getUID();                 // Assumes probabilities are still listed in UID order
    00092         }
    00093
    00094         map<unsigned int, double>::const_iterator sProbItr = sourceStateProbabilities.find(sourceStateIndex);
    00095         trajectoryProb = (*sProbItr).second;    // Direct access isn't a constant function so apparently this is required
    00096         for(j=0; j<decisionVariables->getLength(); j++)
    00097         {
    00098                 varUID = (*decisionVariables)[j]->getUID();
    00099                 if(wasAssigned[varUID])
    00100                 {
    00101                         map<unsigned int, unsigned int>::const_iterator pMapItr = probabilityMap.find(varUID);
    00102                         trajectoryProb *= allTransitionProbabilitiesForAllStates[sourceStateIndex*(allTransitionProbabilitiesForAllStates.size() /
    00103                                         numSourceStates) + (*pMapItr).second + assignedValue[varUID]];
    00104                 }
    00105                 else
    00106                 {
    00107                         map<pair<unsigned int, unsigned int>, double>::const_iterator opItr;
    00108                         opItr = optimisticProbabilities.find(pair<unsigned int, unsigned int>(varUID, sourceStateIndex));
    00109                         trajectoryProb *= (*opItr).second;
    00110                 }
    00111         }
    00112
    00113         return trajectoryProb;
    00114 }
    00115
    00117 //      PRIVATE METHODS
    00119
    00120
    00121 double
    00122 BFTEObjectiveFunction::calculatePropagationUtility(vector<BaseModelAssignment const *> & bmAssignments,
    00123                                                                                                    int sourceStateIndex) const
    00124 {
    00125         return BFTEObjectiveFunction::calculateUtility(bmAssignments, sourceStateIndex);
    00126 }
    00127
    00129