FunctionApproximator.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 RobotComponents::ArmarXObjects::FunctionApproximator
17  * @author zhou ( you dot zhou at kit dot edu )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
26 #include <boost/archive/binary_iarchive.hpp>
27 #include <boost/archive/binary_oarchive.hpp>
28 #include <boost/archive/text_iarchive.hpp>
29 #include <boost/archive/text_oarchive.hpp>
30 #include <boost/archive/xml_iarchive.hpp>
31 #include <boost/archive/xml_oarchive.hpp>
32 
34 
35 #include <RobotComponents/interface/components/FunctionApproximatorBase.h>
36 
37 #include <dmp/functionapproximation/functionapproximation.h>
38 #include <dmp/functionapproximation/functionapproximationregistration.h>
39 #include <dmp/functionapproximation/locallyweightedlearning.h>
40 #include <dmp/functionapproximation/radialbasisfunctioninterpolator.h>
41 
42 namespace armarx
43 {
44  /**
45  * @class FunctionApproximatorPropertyDefinitions
46  * @brief
47  */
49  {
50  public:
53  {
54  //defineRequiredProperty<std::string>("PropertyName", "Description");
55  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
56  }
57  };
58 
59  /**
60  * @defgroup Component-FunctionApproximator FunctionApproximator
61  * @ingroup RobotComponents-Components
62  * A description of the component FunctionApproximator.
63  *
64  * @class FunctionApproximator
65  * @ingroup Component-FunctionApproximator
66  * @brief Brief description of class FunctionApproximator.
67  *
68  * Detailed description of class FunctionApproximator.
69  */
70  using FuncAppMap = std::map<std::string, DMP::FunctionApproximationInterfacePtr>;
71  using FuncAppPair = std::pair<std::string, DMP::FunctionApproximationInterfacePtr>;
72 
74  virtual public Component,
75  virtual public armarx::FunctionApproximatorBase
76  {
77  public:
78  FunctionApproximator() : dimension(2)
79  {
80  DMP::DVec widthFactor;
81  widthFactor.push_back(10);
82  widthFactor.push_back(10);
83  }
84 
85  /**
86  * @see armarx::ManagedIceObject::getDefaultName()
87  */
88  std::string
89  getDefaultName() const override
90  {
91  return "FunctionApproximator";
92  }
93 
94 
95  protected:
96  /**
97  * @see armarx::ManagedIceObject::onInitComponent()
98  */
99  void onInitComponent() override;
100 
101  /**
102  * @see armarx::ManagedIceObject::onConnectComponent()
103  */
104  void onConnectComponent() override;
105 
106  /**
107  * @see armarx::ManagedIceObject::onDisconnectComponent()
108  */
109  void onDisconnectComponent() override;
110 
111  /**
112  * @see armarx::ManagedIceObject::onExitComponent()
113  */
114  void onExitComponent() override;
115 
116  /**
117  * @see PropertyUser::createPropertyDefinitions()
118  */
119  // virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions();
120 
121  // FunctionApproximatorBase interface
122  public:
123  void initialize(const std::string& fappName,
124  const Ice::DoubleSeq& factors,
125  const Ice::Current&) override;
126  void learn(const std::string& name,
127  const DVector2d&,
128  const DVector2d&,
129  const Ice::Current&) override;
131  predict(const std::string& name, const Ice::DoubleSeq&, const Ice::Current&) override;
132  void ilearn(const std::string& name,
133  const Ice::DoubleSeq&,
134  Ice::Double,
135  const Ice::Current&) override;
136  void blearn(const std::string& name,
137  const Ice::DoubleSeq&,
138  const Ice::DoubleSeq&,
139  const Ice::Current&) override;
140  Ice::DoubleSeq
141  bpredict(const std::string& name, const Ice::DoubleSeq& x, const Ice::Current&) override;
142 
143  void getFunctionApproximatorFromFile(const std::string& funcName,
144  const std::string& name,
145  const Ice::Current&) override; //TODO: deserialization;
146  void getFunctionApproximatorsFromFile(const std::vector<std::string>& funcNameList,
147  const std::string& filename,
148  const Ice::Current&) override;
149  void saveFunctionApproximatorInFile(const std::string& funcName,
150  const std::string& name,
151  const Ice::Current&) override; //TODO: serialization;
152 
153  // void getWeightsFromFile(const std::string & funcName, const std::string& filename, const Ice::Current&);
154  // void writeWeightsToFile(const std::string & funcName, const std::string& filename, const Ice::Current&);
155 
156  void reset(const Ice::Current&) override;
157 
158  void saveFunctionApproximatorInFileTest(const std::string& funcName,
159  const std::string& name);
160  void initializeTest(const std::string& fappName, const Ice::DoubleSeq& widthFactors);
161 
162  private:
163  FuncAppMap funcAppPool;
164  int dimension;
165  int num;
166  };
167 
169 
170 } // namespace armarx
armarx::FunctionApproximatorPropertyDefinitions
Definition: FunctionApproximator.h:48
armarx::FuncAppPair
std::pair< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppPair
Definition: FunctionApproximator.h:71
armarx::FunctionApproximator::onInitComponent
void onInitComponent() override
Definition: FunctionApproximator.cpp:29
armarx::FuncAppMap
std::map< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppMap
Definition: FunctionApproximator.h:70
armarx::FunctionApproximator::onDisconnectComponent
void onDisconnectComponent() override
Definition: FunctionApproximator.cpp:43
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::FunctionApproximator::getDefaultName
std::string getDefaultName() const override
Definition: FunctionApproximator.h:89
armarx::FunctionApproximator::predict
Ice::Double predict(const std::string &name, const Ice::DoubleSeq &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:101
armarx::FunctionApproximator::bpredict
Ice::DoubleSeq bpredict(const std::string &name, const Ice::DoubleSeq &x, const Ice::Current &) override
Definition: FunctionApproximator.cpp:174
armarx::FunctionApproximator::learn
void learn(const std::string &name, const DVector2d &, const DVector2d &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:55
armarx::FunctionApproximatorPropertyDefinitions::FunctionApproximatorPropertyDefinitions
FunctionApproximatorPropertyDefinitions(std::string prefix)
Definition: FunctionApproximator.h:51
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FunctionApproximator::onExitComponent
void onExitComponent() override
Definition: FunctionApproximator.cpp:49
armarx::FunctionApproximator::saveFunctionApproximatorInFile
void saveFunctionApproximatorInFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
Definition: FunctionApproximator.cpp:268
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::FunctionApproximator::onConnectComponent
void onConnectComponent() override
Definition: FunctionApproximator.cpp:38
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:47
armarx::FunctionApproximator::reset
void reset(const Ice::Current &) override
Definition: FunctionApproximator.cpp:198
armarx::FunctionApproximator::saveFunctionApproximatorInFileTest
void saveFunctionApproximatorInFileTest(const std::string &funcName, const std::string &name)
Definition: FunctionApproximator.cpp:298
armarx::FunctionApproximator::FunctionApproximator
FunctionApproximator()
Definition: FunctionApproximator.h:78
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::FunctionApproximator::initialize
void initialize(const std::string &fappName, const Ice::DoubleSeq &factors, const Ice::Current &) override
Definition: FunctionApproximator.cpp:215
armarx::FunctionApproximator
Brief description of class FunctionApproximator.
Definition: FunctionApproximator.h:73
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::FunctionApproximator::blearn
void blearn(const std::string &name, const Ice::DoubleSeq &, const Ice::DoubleSeq &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:150
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::FunctionApproximator::ilearn
void ilearn(const std::string &name, const Ice::DoubleSeq &, Ice::Double, const Ice::Current &) override
Definition: FunctionApproximator.cpp:125
armarx::FunctionApproximator::getFunctionApproximatorFromFile
void getFunctionApproximatorFromFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
Definition: FunctionApproximator.cpp:227
armarx::FunctionApproximator::getFunctionApproximatorsFromFile
void getFunctionApproximatorsFromFile(const std::vector< std::string > &funcNameList, const std::string &filename, const Ice::Current &) override
Definition: FunctionApproximator.cpp:245
armarx::FunctionApproximator::initializeTest
void initializeTest(const std::string &fappName, const Ice::DoubleSeq &widthFactors)
Definition: FunctionApproximator.cpp:286
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27