GaussianMixtureAssociationMethod.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::CommonPlacesLearner
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>
27 #include <MemoryX/interface/core/FusionMethods.h>
31 
32 namespace memoryx
33 {
34  /**
35  * @class MahalanobisAssociationMethod
36  * @ingroup CommonPlacesLearner
37  */
39  virtual public GaussianMixtureAssociationMethodBase
40  {
41  public:
42  /**
43  * Creates a new GaussianMixtureAssociationMethod
44  */
45  GaussianMixtureAssociationMethod(float threshold, GMMDistancePtr gmmDistance) :
46  threshold(threshold), gmmDistance(gmmDistance)
47  {
48  }
49 
50  void setThreshold(float threshold)
51  {
52  this->threshold = threshold;
53  }
54 
55  /**
56  * Returns an index of GM component, which is "closest" to the specified gaussian
57  *
58  * @param gmDistr GaussianMixture to associate (e.g. current belief state)
59  * @param newComp new gaussian (e.g. new observation)
60  *
61  * @return index of associated GM component, or -1 if none found
62  */
63  Ice::Int getAssociatedComponentIndex(const GaussianMixtureDistributionBasePtr& gmDistr, const GaussianMixtureComponent& newComp, const ::Ice::Current& = Ice::emptyCurrent) override
64  {
65  if (threshold < 0.)
66  {
67  return -1;
68  }
69 
70  gmDistr->addComponent(newComp);
71  gmDistr->normalize();
72 
73  float minDist = threshold + 100.;
74  int result = -1;
75 
76  for (int i = 0; i < gmDistr->size() - 1; ++i)
77  {
78  float curDist = gmmDistance->getDistance(gmDistr->getComponent(i), newComp);
79  std::cout << "Cur dist: " << curDist << std::endl;
80 
81  if (curDist < minDist && curDist < threshold)
82  {
83  minDist = curDist;
84  result = i;
85  }
86  }
87 
88  std::cout << "Min dist: " << minDist << " , threshold: " << threshold << std::endl;
89 
90  return result;
91  };
92 
93  private:
94  float threshold;
95  GMMDistancePtr gmmDistance;
96 
97  };
98 
100 
101 }
102 
memoryx::GaussianMixtureAssociationMethod::getAssociatedComponentIndex
Ice::Int getAssociatedComponentIndex(const GaussianMixtureDistributionBasePtr &gmDistr, const GaussianMixtureComponent &newComp, const ::Ice::Current &=Ice::emptyCurrent) override
Returns an index of GM component, which is "closest" to the specified gaussian.
Definition: GaussianMixtureAssociationMethod.h:63
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
GMMDistance.h
IceInternal::Handle< GaussianMixtureAssociationMethod >
ProbabilityMeasures.h
ObjectInstance.h
memoryx::GaussianMixtureAssociationMethod
Definition: GaussianMixtureAssociationMethod.h:38
memoryx::GMMDistancePtr
std::shared_ptr< GMMDistance > GMMDistancePtr
Definition: GMMDistance.h:61
memoryx::GaussianMixtureAssociationMethod::setThreshold
void setThreshold(float threshold)
Definition: GaussianMixtureAssociationMethod.h:50
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
memoryx::GaussianMixtureAssociationMethod::GaussianMixtureAssociationMethod
GaussianMixtureAssociationMethod(float threshold, GMMDistancePtr gmmDistance)
Creates a new GaussianMixtureAssociationMethod.
Definition: GaussianMixtureAssociationMethod.h:45