RunnallsKLDistance.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::GaussianMixtureHelpers
17 * @author Alexey Kozlov <kozlov@kit.edu>
18 * @copyright 2013 Alexey Kozlov
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include "GMMDistance.h"
26 
29 
30 #include <Eigen/Dense>
31 
32 #include <string>
33 
34 namespace memoryx
35 {
36 
37  /**
38  * @class RunnallsKLDistance
39  * @ingroup CommonPlacesLearner
40  */
42  {
43  public:
44  /**
45  * Creates a new RunnallsKLDistance
46  */
48  {
49  }
50 
51  /**
52  *
53  *
54  */
55  float getDistance(const GaussianMixtureDistributionBasePtr& gmm1, const GaussianMixtureDistributionBasePtr& gmm2) override
56  {
57  return -1; // NYI
58  }
59 
60  float getDistance(const GaussianMixtureComponent& comp1, const GaussianMixtureComponent& comp2) override
61  {
62  NormalDistributionPtr gaussian1 = NormalDistributionPtr::dynamicCast(comp1.gaussian);
63  NormalDistributionPtr gaussian2 = NormalDistributionPtr::dynamicCast(comp2.gaussian);
64 
65  const float w1 = comp1.weight;
66  const float w2 = comp2.weight;
67  const float k = 1. / (w1 + w2);
68  const Eigen::VectorXf x1 = gaussian1->toEigenMean();
69  const Eigen::VectorXf x2 = gaussian2->toEigenMean();
70  const Eigen::MatrixXf p1 = gaussian1->toEigenCovariance();
71  const Eigen::MatrixXf p2 = gaussian2->toEigenCovariance();
72  const Eigen::VectorXf d = x1 - x2;
73 
74  const Eigen::MatrixXf p12 = k * (w1 * p1 + w2 * p2 + k * w1 * w2 * d * d.transpose());
75 
76  const float result = 0.5 * ((w1 + w2) * logf(p12.determinant()) -
77  w1 * logf(p1.determinant()) - w2 * logf(p2.determinant()));
78 
79  return result;
80  }
81 
82  };
83 }
84 
memoryx::RunnallsKLDistance::getDistance
float getDistance(const GaussianMixtureDistributionBasePtr &gmm1, const GaussianMixtureDistributionBasePtr &gmm2) override
Definition: RunnallsKLDistance.h:55
memoryx::RunnallsKLDistance::getDistance
float getDistance(const GaussianMixtureComponent &comp1, const GaussianMixtureComponent &comp2) override
Definition: RunnallsKLDistance.h:60
memoryx::GMMDistance
Definition: GMMDistance.h:39
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::RunnallsKLDistance::RunnallsKLDistance
RunnallsKLDistance()
Creates a new RunnallsKLDistance.
Definition: RunnallsKLDistance.h:47
GMMDistance.h
IceInternal::Handle
Definition: forward_declarations.h:8
ProbabilityMeasures.h
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
memoryx::RunnallsKLDistance
Definition: RunnallsKLDistance.h:41