/Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/ApproximateBeliefState/BSUObjectiveFunction.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 "BSUObjectiveFunction.h"
00015 
00016 #ifdef _MSC_VER
00017 #pragma warning( disable : 4786 )
00018 #endif
00019 
00020 #include <Mers/Estimation/Discrete/ProbabilityRules/RuleTriggering/RuleTrigger.h>
00021 #include <Mers/Estimation/Discrete/ProbabilityRules/ObsProbRule.h>
00022 #include <Mers/Estimation/Discrete/ProbabilityRules/Rule.h>
00023 
00024 #include <Mers/Models/Base/BaseModelVariableArray.h>
00025 #include <Mers/Models/Base/BaseModelAssignment.h>
00026 
00027 
00028 using Mers::Estimation::Discrete::ApproximateBeliefState::BSUObjectiveFunction;
00029 using Mers::Estimation::Discrete::ProbabilityRules::RuleTriggering::RuleTrigger;
00030 using Mers::Estimation::Discrete::ProbabilityRules::ObsProbRule;
00031 using Mers::Estimation::Discrete::ProbabilityRules::Rule;
00032 using Mers::Models::Base::BaseModelVariableArray;
00033 using Mers::Models::Base::BaseModelAssignment;
00034 using std::vector;
00035 using std::cout;
00036 using std::endl;
00037 using std::map;
00038 
00040 //      CONSTRUCTOR
00042 
00043 BSUObjectiveFunction::BSUObjectiveFunction(BaseModelVariableArray const * dVs,
00044                 const map<unsigned int,unsigned int> pMap, vector<double> allTransProbs, 
00045                 map<unsigned int,double> sProbs, vector<const ObsProbRule *> & theObsProbabilityRules)
00046 : BSEObjectiveFunction(dVs, pMap, allTransProbs, sProbs) 
00047 {
00048         while(theObsProbabilityRules.size() > 0)
00049         {
00050                 triggerRules.push_back((ObsProbRule *)theObsProbabilityRules.back());
00051                 theObsProbabilityRules.pop_back();
00052         }
00053         obsProbabilityRuleTrigger = new RuleTrigger(triggerRules);
00054 }
00055 
00057 
00058 BSUObjectiveFunction::~BSUObjectiveFunction()
00059 {
00060         delete obsProbabilityRuleTrigger;
00061 }
00062 
00063 
00065 //      PUBLIC METHODS
00067 
00068 
00070 //      PROTECTED METHODS
00072 
00073 double 
00074 BSUObjectiveFunction::calculateUtility(vector<BaseModelAssignment const *> & bmAssignments,
00075                                                                            int sourceStateIndex) const
00076 {
00077         (void)sourceStateIndex; // Not used by BSEObjectiveFunction
00078 
00079         // The BSEObjectiveFunction handles the propagation equation. The complete solution is the
00080         // product of that and the observation probabilities.
00081         double fX = BSEObjectiveFunction::calculateUtility(bmAssignments);
00082         
00083         // First reset the trigger
00084         obsProbabilityRuleTrigger->reset();
00085 
00086         // Add in all the current mode variable assignments
00087         for(size_t i=0; i<bmAssignments.size(); i++)
00088                 obsProbabilityRuleTrigger->loadAssignment(bmAssignments[i]->getVariable()->getUID(), 
00089                                 bmAssignments[i]->getValue()->getUID());
00090 
00091         // Determine which rules are fired and multiply the total probability by them
00092         vector<Rule *> enabledProbabilityRules = obsProbabilityRuleTrigger->getTriggeredRules();
00093         while(enabledProbabilityRules.size() > 0)
00094         {
00095                 fX *= ((ObsProbRule *) enabledProbabilityRules.back() )->getProbability();
00096                 enabledProbabilityRules.pop_back();
00097         }
00098 
00099         return fX;
00100 }
00101 
00103 //      PRIVATE METHODS
00105 

Generated on Mon Dec 4 14:16:42 2006 for Mers by  doxygen 1.5.0