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 "mcpdf.h"
00021
00022 namespace BFL
00023 {
00024 using namespace MatrixWrapper;
00025
00026
00027
00028
00029
00030
00031 template <> inline MCPdf<ColumnVector>::MCPdf(unsigned int num_samples, unsigned int dimension) :
00032 Pdf<ColumnVector>(dimension)
00033 , _CumSum(dimension)
00034 , _mean(dimension)
00035 , _diff(dimension)
00036 , _covariance(dimension)
00037 , _diffsum(dimension,dimension)
00038 {
00039 _SumWeights = 0;
00040 WeightedSample<ColumnVector> my_sample(dimension);
00041 _listOfSamples.insert(_listOfSamples.begin(),num_samples,my_sample);
00042 _CumPDF.insert(_CumPDF.begin(),num_samples+1,0.0);
00043
00044 _los.assign(num_samples,WeightedSample<ColumnVector>(dimension));
00045 _it_los = _los.begin();
00046 #ifdef __CONSTRUCTOR__
00047
00048 cout << "MCPDF Constructor: NumSamples = " << _listOfSamples.size()
00049 << ", CumPDF Samples = " << _CumPDF.size()
00050 << ", _SumWeights = " << _SumWeights << endl;
00051 #endif // __CONSTRUCTOR__
00052 }
00053
00054
00055
00056 template <> inline
00057 MCPdf<ColumnVector>::MCPdf(const MCPdf & pdf) : Pdf<ColumnVector>(pdf)
00058 , _CumSum(pdf.DimensionGet())
00059 , _mean(pdf.DimensionGet())
00060 , _diff(pdf.DimensionGet())
00061 , _covariance(pdf.DimensionGet())
00062 , _diffsum(pdf.DimensionGet(),pdf.DimensionGet())
00063 {
00064 this->_listOfSamples = pdf._listOfSamples;
00065 this->_CumPDF = pdf._CumPDF;
00066 _SumWeights = pdf._SumWeights;
00067 this->_los = pdf._listOfSamples;
00068 _it_los = _los.begin();
00069 #ifdef __CONSTRUCTOR__
00070 cout << "MCPDF Copy Constructor: NumSamples = " << _listOfSamples.size()
00071 << ", CumPDF Samples = " << _CumPDF.size()
00072 << ", SumWeights = " << _SumWeights << endl;
00073 #endif // __CONSTRUCTOR__
00074 }
00075
00076 template <> inline
00077 ColumnVector MCPdf<ColumnVector>::ExpectedValueGet ( ) const
00078 {
00079 _CumSum = 0.0;
00080 _los = _listOfSamples;
00081 for ( _it_los = _los.begin() ; _it_los != _los.end() ; _it_los++ )
00082 _CumSum += ( _it_los->ValueGet() * _it_los->WeightGet() );
00083 return _CumSum/_SumWeights;
00084 }
00085
00086
00087 template <> inline
00088 SymmetricMatrix MCPdf<ColumnVector>::CovarianceGet ( ) const
00089 {
00090 _mean = (this->ExpectedValueGet());
00091 _los = _listOfSamples;
00092 _diffsum = 0.0;
00093
00094 for (_it_los = _los.begin(); _it_los != _los.end(); _it_los++)
00095 {
00096 _diff = ( _it_los->ValueGet() - _mean);
00097 _diffsum += _diff * (_diff.transpose() * _it_los->WeightGet());
00098 }
00099
00100 (_diffsum/_SumWeights).convertToSymmetricMatrix(_covariance);
00101 return _covariance;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 template <> inline
00111 unsigned int MCPdf<unsigned int>::ExpectedValueGet ( ) const
00112 {
00113 unsigned int result;
00114 double CumSum = 0;
00115 _los = _listOfSamples;
00116 double current_weight;
00117 for ( _it_los = _los.begin() ; _it_los != _los.end() ; _it_los++ )
00118 {
00119 current_weight = _it_los->WeightGet();
00120 CumSum += ( ((double)_it_los->ValueGet()) * current_weight );
00121 }
00122 result = (unsigned int)((CumSum/_SumWeights) + 0.5);
00123 return result;
00124 }
00125
00126
00127
00128
00129 template <> inline
00130 SymmetricMatrix MCPdf<unsigned int>::CovarianceGet ( ) const
00131 {
00132 unsigned int mean = this->ExpectedValueGet();
00133 unsigned int diff;
00134 double diffsum, current_weight;
00135 _los = _listOfSamples;
00136 diffsum = 0.0;
00137
00138 for (_it_los = _los.begin(); _it_los != _los.end(); _it_los++)
00139 {
00140 current_weight = _it_los->WeightGet();
00141 diff = (_it_los->ValueGet() - mean);
00142 diffsum += (((double)(diff * diff)) * current_weight);
00143 }
00144
00145
00146 _covariance(1,1) = (diffsum / _SumWeights);
00147 return _covariance;
00148 }
00149
00150 }
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