GaussianMixtureDistribution.cpp
Go to the documentation of this file.
1 
19 
21 
23  : mDimension(pDimension)
24  {
25  }
26 
28  {
29  }
30 
31  void GaussianMixtureDistribution::load(boost::property_tree::ptree& pPt, std::string pNode)
32  {
33  // Load the gaussian kernels.
34  BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pPt.get_child(pNode))
35  {
36  // Only access the 'distribution' child nodes.
37  if(!std::strcmp(v.first.c_str(), "kernel"))
38  mKernels.push_back(PSMInference::GaussianKernel(mDimension, v.second));
39  }
40 
41  // Sum up all mixture weights.
42  double sum = 0.0;
43  BOOST_FOREACH(PSMInference::GaussianKernel kernel, mKernels)
44  sum += kernel.getWeight();
45 
46  // Check, if the mixture weights summed up before are one.
47  if(sum < 0.999 || sum > 1.001)
48  throw std::invalid_argument("Unable to procees loading. The weights of the mixture of gaussian do not sum up to one (" + boost::lexical_cast<std::string>(sum) + ").");
49  }
50 
52  {
53  // Iterate over all gaussian kernels and add them to the visualizer.
55  kernel.initializeVisualizer(pVisualizer);
56  }
57 
59  {
60  double result = 0.0;
61 
62  // Copy evidence into an 7D eigen vector.
63  Eigen::VectorXd evidence = getVectorFromObject(pPose);
64 
65  // Marginalize over all kernels to get the probability.
66  // Normalization is already done by the mixture weights in the kernel.
67  BOOST_FOREACH(PSMInference::GaussianKernel kernel, mKernels)
68  result += kernel.evaluate(evidence);
69 
70  // The result is a marginalisation over all gaussian kernels.
71  return result;
72  }
73 
76  {
77  // Reset the certainty to zero, so that we can use the value from the best fitting kernel.
78  mVisualizer->resetCertainty();
79 
80  // Iterate over all kernels and take the best score.
82  kernel.visualize(mVisualizer, getVectorFromObject(pPose));
83  }
84 
86  {
87  Eigen::VectorXd evidence(mDimension);
88 
89  if(mDimension == 3)
90  {
91  Eigen::Vector3d position = pPose->point->getEigen();
92  evidence[0] = position[0];
93  evidence[1] = position[1];
94  evidence[2] = position[2];
95  } else if (mDimension == 4) {
96  Eigen::Quaternion<double> orientation = pPose->quat->getEigen();
97  evidence[0] = orientation.w();
98  evidence[1] = orientation.x();
99  evidence[2] = orientation.y();
100  evidence[3] = orientation.z();
101  } else {
102  throw std::invalid_argument("Unable to evaluate gaussian mixture distribution. It has an invalid number of dimensions (" + boost::lexical_cast<std::string>(mDimension) + ").");
103  }
104  return evidence;
105  }
106 
107 }
void visualize(boost::shared_ptr< Visualization::ProbabilisticSecondarySceneObjectVisualization > pVisualizer, boost::shared_ptr< ISM::Pose > pPose)
void initializeVisualizer(boost::shared_ptr< Visualization::ProbabilisticSecondarySceneObjectVisualization > pVisualizer)
void load(boost::property_tree::ptree &pPt, std::string pNode)
Eigen::VectorXd getVectorFromObject(boost::shared_ptr< ISM::Pose > pPose)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54