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 <string>
26
27#include <Eigen/Dense>
28
30
31#include "GMMDistance.h"
33
34namespace memoryx
35{
36
37 /**
38 * @class RunnallsKLDistance
39 * @ingroup CommonPlacesLearner
40 */
42 {
43 public:
44 /**
45 * Creates a new RunnallsKLDistance
46 */
50
51 /**
52 *
53 *
54 */
55 float
56 getDistance(const GaussianMixtureDistributionBasePtr& gmm1,
57 const GaussianMixtureDistributionBasePtr& gmm2) override
58 {
59 return -1; // NYI
60 }
61
62 float
63 getDistance(const GaussianMixtureComponent& comp1,
64 const GaussianMixtureComponent& comp2) override
65 {
66 NormalDistributionPtr gaussian1 = NormalDistributionPtr::dynamicCast(comp1.gaussian);
67 NormalDistributionPtr gaussian2 = NormalDistributionPtr::dynamicCast(comp2.gaussian);
68
69 const float w1 = comp1.weight;
70 const float w2 = comp2.weight;
71 const float k = 1. / (w1 + w2);
72 const Eigen::VectorXf x1 = gaussian1->toEigenMean();
73 const Eigen::VectorXf x2 = gaussian2->toEigenMean();
74 const Eigen::MatrixXf p1 = gaussian1->toEigenCovariance();
75 const Eigen::MatrixXf p2 = gaussian2->toEigenCovariance();
76 const Eigen::VectorXf d = x1 - x2;
77
78 const Eigen::MatrixXf p12 = k * (w1 * p1 + w2 * p2 + k * w1 * w2 * d * d.transpose());
79
80 const float result = 0.5 * ((w1 + w2) * logf(p12.determinant()) -
81 w1 * logf(p1.determinant()) - w2 * logf(p2.determinant()));
82
83 return result;
84 }
85 };
86} // namespace memoryx
#define ARMARXCORE_IMPORT_EXPORT
GMMDistance()
Creates a new GMMDistance.
Definition GMMDistance.h:45
float getDistance(const GaussianMixtureDistributionBasePtr &gmm1, const GaussianMixtureDistributionBasePtr &gmm2) override
RunnallsKLDistance()
Creates a new RunnallsKLDistance.
float getDistance(const GaussianMixtureComponent &comp1, const GaussianMixtureComponent &comp2) override
VirtualRobot headers.
IceInternal::Handle< NormalDistribution > NormalDistributionPtr