CommonPlacesLearner.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 at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
27 
30 #include <MemoryX/interface/components/CommonPlacesLearnerInterface.h>
31 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
32 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
33 
34 // memoryx helpers
36 
37 namespace memoryx
38 {
39 
41  {
42  public:
45  {
46  defineOptionalProperty<std::string>(
47  "LTMSegment",
48  "objects",
49  "Name of segment in LTM to store learned CommonPlaces / to run queries on");
50  defineOptionalProperty<float>(
51  "AgingFactor", 0.8, "Discount factor to make older observations less significant");
52  defineOptionalProperty<float>(
53  "PruningThreshold", 0.0, "Maximum weight of Gauss component to be pruned");
54  defineOptionalProperty<std::string>(
55  "MergingDistanceType",
56  "KL",
57  "Distance type to be used for association/merging: Mahalanobis, ISD, KL");
58  defineOptionalProperty<float>(
59  "MergingThreshold",
60  0.0,
61  "Maximum distance value for association (meaning depends upon measure used)");
62  defineOptionalProperty<std::string>(
63  "GMMReducerAlgorithm",
64  "West",
65  "A GMM reducing algorithm to be used for queries: West, Runnalls, Williams");
66  }
67  };
68 
70  virtual public CommonPlacesLearnerInterface,
71  virtual public armarx::Component
72  {
73  public:
74  // inherited from Component
75  std::string
76  getDefaultName() const override
77  {
78  return "CommonPlacesLearner";
79  };
80 
81  void onInitComponent() override;
82  void onConnectComponent() override;
83  void onExitComponent() override;
84 
85  // inherited from CommonPlacesLearnerInterface
86  void setLTMSegmentName(const ::std::string& segmentName,
87  const ::Ice::Current& = Ice::emptyCurrent) override;
88  void setAgingFactor(float factor, const ::Ice::Current& = Ice::emptyCurrent) override;
89  void setMergingThreshold(float threshold,
90  const ::Ice::Current& = Ice::emptyCurrent) override;
91 
92  void learnFromSnapshot(const ::std::string& snapshotName,
93  const ::Ice::Current& = Ice::emptyCurrent) override;
94  void learnFromObject(const ObjectInstanceBasePtr& newObject,
95  const ::Ice::Current& = Ice::emptyCurrent) override;
96  void learnFromObjectMCA(const ::std::string& objectName,
97  const MultivariateNormalDistributionBasePtr& posDist,
98  const ::Ice::Current& = Ice::emptyCurrent) override;
99 
100  // inherited from CommonPlacesQueryInterface
101  GaussianMixtureDistributionBasePtr
102  getPositionFull(const ::std::string& objectName,
103  const ::Ice::Current& = Ice::emptyCurrent) override;
104  GaussianMixtureDistributionBasePtr
105  getPositionReducedByComponentCount(const ::std::string& objectName,
106  Ice::Int compCount,
107  const ::Ice::Current& = Ice::emptyCurrent) override;
108  GaussianMixtureDistributionBasePtr
109  getPositionReducedByMaxDeviation(const ::std::string& objectName,
110  Ice::Float maxDeviation,
111  DeviationType devType,
112  const ::Ice::Current& = Ice::emptyCurrent) override;
113  NormalDistributionBasePtr
114  getPositionAsGaussian(const ::std::string& objectName,
115  const ::Ice::Current& = Ice::emptyCurrent) override;
116 
117  Cluster3DList
118  getPositionClustersByComponentCount(const ::std::string& objectName,
119  Ice::Int compCount,
120  const ::Ice::Current& = Ice::emptyCurrent) override;
121  Cluster3DList
122  getPositionClustersByMaxDeviation(const ::std::string& objectName,
123  Ice::Float maxDeviation,
124  DeviationType devType,
125  const ::Ice::Current& = Ice::emptyCurrent) override;
126 
127  private:
128  PriorKnowledgeInterfacePrx priorKnowledgePrx;
129 
130  LongtermMemoryInterfacePrx longtermMemoryPrx;
131  PersistentObjectInstanceSegmentBasePrx ltmInstancesSegmentPrx;
132 
135  GMMReducerPtr gmmReducer;
136 
137  //
138  DeviationMeasure convertDeviationType(DeviationType devType);
139  Cluster3DList gmmToClusterList(const GaussianMixtureDistributionBasePtr& gmm);
140  void getChildClasses(std::string className, NameList& result);
141 
142  public:
143  /**
144  * @see PropertyUser::createPropertyDefinitions()
145  */
148  {
150  new CommonPlacesLearnerPropertyDefinitions(getConfigIdentifier()));
151  }
152  };
153 
155 } // namespace memoryx
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
GaussianMixtureAssociationMethod.h
memoryx::CommonPlacesLearner
Definition: CommonPlacesLearner.h:69
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::DeviationMeasure
DeviationMeasure
Definition: GMMReducer.h:37
memoryx::CommonPlacesLearnerPropertyDefinitions
Definition: CommonPlacesLearner.h:40
memoryx::CommonPlacesLearner::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CommonPlacesLearner.h:147
IceInternal::Handle< GaussianMixtureAssociationMethod >
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::CommonPlacesLearner::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: CommonPlacesLearner.h:76
GaussianMixturePositionFusion.h
GMMReducer.h
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
memoryx::CommonPlacesLearnerPropertyDefinitions::CommonPlacesLearnerPropertyDefinitions
CommonPlacesLearnerPropertyDefinitions(std::string prefix)
Definition: CommonPlacesLearner.h:43
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
memoryx::GMMReducerPtr
std::shared_ptr< GMMReducer > GMMReducerPtr
Definition: GMMReducer.h:104
ImportExportComponent.h