Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "mixture.h"
00021
00022 namespace BFL
00023 {
00024 using namespace MatrixWrapper;
00025
00026
00027
00028
00029 template <> inline
00030 ColumnVector Mixture<ColumnVector>::ExpectedValueGet ( ) const
00031 {
00032 TestNotInit();
00033 ColumnVector expectedValue(DimensionGet());
00034 expectedValue = 0.0;
00035 for (int i=0; i<NumComponentsGet();i++)
00036 expectedValue = expectedValue + ( (*_componentPdfs)[i]->ExpectedValueGet() * (double)((*_componentWeights)[i]) );
00037 return expectedValue;
00038 }
00039
00040
00041
00042
00043
00044 template <> inline
00045 unsigned int Mixture<unsigned int>::ExpectedValueGet ( ) const
00046 {
00047 TestNotInit();
00048 unsigned int expectedValue =0;
00049 double probState = 0.0;
00050 double mostProbState = -1.0;
00051 int numStates = ((DiscretePdf*)((*_componentPdfs)[0]))->NumStatesGet();
00052 for (int i=0; i<NumComponentsGet();i++)
00053 {
00054 if(numStates != ((DiscretePdf*)((*_componentPdfs)[i]))->NumStatesGet())
00055 {
00056 cerr << "Mixture::ExpectedValueGet failed since the different components in the mixture don't have the same number of states" << endl;
00057 assert(0);
00058 }
00059 }
00060 for (int j=0; j<numStates ;j++ )
00061 {
00062 probState = 0.0;
00063 for (int i=0; i<NumComponentsGet();i++)
00064 {
00065 probState += ( ((double)(*_componentPdfs)[i]->ProbabilityGet(j)) * (double)((*_componentWeights)[i]) );
00066 }
00067 if (probState > mostProbState)
00068 {
00069 expectedValue = (unsigned int)j;
00070 mostProbState = probState;
00071 }
00072 }
00073 return expectedValue;
00074 }
00075
00076
00077
00078
00079
00080 template <> inline
00081 int Mixture<int>::ExpectedValueGet ( ) const
00082 {
00083 TestNotInit();
00084 int expectedValue =0;
00085 double probState = 0.0;
00086 double mostProbState = -1.0;
00087 int numStates = ((DiscretePdf*)((*_componentPdfs)[0]))->NumStatesGet();
00088 for (int i=0; i<NumComponentsGet();i++)
00089 {
00090 if(numStates != ((DiscretePdf*)((*_componentPdfs)[i]))->NumStatesGet())
00091 {
00092 cerr << "Mixture::ExpectedValueGet failed since the different components in the mixture don't have the same number of states" << endl;
00093 assert(0);
00094 }
00095 }
00096 for (int j=0; j< numStates;j++ )
00097 {
00098 probState = 0.0;
00099 for (int i=0; i<NumComponentsGet();i++)
00100 {
00101 probState += ( ((double)(*_componentPdfs)[i]->ProbabilityGet(j)) * (double)((*_componentWeights)[i]) );
00102 }
00103 if (probState > mostProbState)
00104 {
00105 expectedValue = j;
00106 mostProbState = probState;
00107 }
00108 }
00109 return expectedValue;
00110 }
00111
00112
00113
00114 template <> inline
00115 double Mixture<double>::ExpectedValueGet ( ) const
00116 {
00117 TestNotInit();
00118 double expectedValue;
00119 expectedValue = 0.0;
00120 for (int i=0; i<NumComponentsGet();i++)
00121 expectedValue = expectedValue + ( (*_componentPdfs)[i]->ExpectedValueGet() * (double)((*_componentWeights)[i]) );
00122 return expectedValue;
00123 }
00124 }
00125
bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Fri Aug 28 2015 10:10:21