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