WilliamsGMMReducer.cpp
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 #include "WilliamsGMMReducer.h"
24 #include "ISDDistance.h"
25 
26 namespace memoryx
27 {
29  {
30  isdDistance.reset(new ISDDistance());
31  // gmmDistance.reset(isdDistance.get());
32  }
33 
34  float WilliamsGMMReducer::getMergingCost(const GaussianMixtureDistributionBasePtr& gmm, int c1, int c2)
35  {
36  // TODO this could be calculated a way more efficient
37  GaussianMixtureDistributionPtr reducedGMM = GaussianMixtureDistributionPtr::dynamicCast(gmm->clone());
38  mergeGMMComponents(reducedGMM, c1, c2);
39  return gmmDistance->getDistance(gmm, reducedGMM);
40  }
41 
42  void WilliamsGMMReducer::fillMergingCostVector(const GaussianMixtureDistributionBasePtr& gmm, GMMCompPairDistanceVector& costVec)
43  {
44  GaussianMixtureDistributionPtr reducedGMM = GaussianMixtureDistributionPtr::dynamicCast(gmm->clone());
45  float d11 = isdDistance->calcSelfLikeness(gmm);
46  const int GMM_SIZE = gmm->size();
47 
48  for (int i = 0; i < GMM_SIZE - 1; ++i)
49  for (int j = i + 1; j < GMM_SIZE; ++j)
50  {
51  // GaussianMixtureDistributionPtr reducedGMM = GaussianMixtureDistributionPtr::dynamicCast(gmm->clone());
52  GaussianMixtureComponent c1 = reducedGMM->getComponent(i);
53  GaussianMixtureComponent c2 = reducedGMM->getComponent(j);
54  mergeGMMComponents(reducedGMM, i, j);
55  const float cost = isdDistance->getDistance(gmm, reducedGMM, d11);
56  const int index = i * GMM_SIZE + j;
57  costVec.push_back(GMMCompPairDistance(index, cost));
58  reducedGMM->setComponent(i, c1);
59  reducedGMM->addComponent(c2);
60  }
61  }
62 }
memoryx::WilliamsGMMReducer::getMergingCost
float getMergingCost(const GaussianMixtureDistributionBasePtr &gmm, int c1, int c2) override
Definition: WilliamsGMMReducer.cpp:34
memoryx::WilliamsGMMReducer::fillMergingCostVector
void fillMergingCostVector(const GaussianMixtureDistributionBasePtr &gmm, GMMCompPairDistanceVector &costVec) override
Definition: WilliamsGMMReducer.cpp:42
memoryx::GMMCompPairDistanceVector
std::vector< GMMCompPairDistance > GMMCompPairDistanceVector
Definition: GMMReducer.h:45
index
uint8_t index
Definition: EtherCATFrame.h:59
memoryx::GMMCompPairDistance
std::pair< int, float > GMMCompPairDistance
Definition: GMMReducer.h:44
ISDDistance.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::GMMReducer::mergeGMMComponents
void mergeGMMComponents(const GaussianMixtureComponent &comp1, const GaussianMixtureComponent &comp2, GaussianMixtureComponent &mergedComp)
Definition: GMMReducer.cpp:192
IceInternal::Handle
Definition: forward_declarations.h:8
WilliamsGMMReducer.h
memoryx::WilliamsGMMReducer::WilliamsGMMReducer
WilliamsGMMReducer()
Definition: WilliamsGMMReducer.cpp:28
memoryx::GMMReducer
Definition: GMMReducer.h:51
memoryx::GMMReducer::gmmDistance
GMMDistancePtr gmmDistance
Definition: GMMReducer.h:77
memoryx::ISDDistance
Definition: ISDDistance.h:42