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 
27 #include <RobotComponents/interface/components/FunctionApproximatorBase.h>
28 #include <dmp/functionapproximation/radialbasisfunctioninterpolator.h>
29 #include <dmp/functionapproximation/functionapproximation.h>
30 #include <dmp/functionapproximation/locallyweightedlearning.h>
31 #include <dmp/functionapproximation/functionapproximationregistration.h>
32 
33 #include <boost/archive/text_oarchive.hpp>
34 #include <boost/archive/text_iarchive.hpp>
35 
36 #include <boost/archive/xml_iarchive.hpp>
37 #include <boost/archive/xml_oarchive.hpp>
38 
39 #include <boost/archive/binary_iarchive.hpp>
40 #include <boost/archive/binary_oarchive.hpp>
41 
42 namespace armarx
43 {
44  /**
45  * @class FunctionApproximatorPropertyDefinitions
46  * @brief
47  */
50  {
51  public:
54  {
55  //defineRequiredProperty<std::string>("PropertyName", "Description");
56  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
57  }
58  };
59 
60  /**
61  * @defgroup Component-FunctionApproximator FunctionApproximator
62  * @ingroup RobotComponents-Components
63  * A description of the component FunctionApproximator.
64  *
65  * @class FunctionApproximator
66  * @ingroup Component-FunctionApproximator
67  * @brief Brief description of class FunctionApproximator.
68  *
69  * Detailed description of class FunctionApproximator.
70  */
71  using FuncAppMap = std::map<std::string, DMP::FunctionApproximationInterfacePtr>;
72  using FuncAppPair = std::pair<std::string, DMP::FunctionApproximationInterfacePtr> ;
74  virtual public Component,
75  virtual public armarx::FunctionApproximatorBase
76  {
77  public:
78 
80  dimension(2)
81  {
82  DMP::DVec widthFactor;
83  widthFactor.push_back(10);
84  widthFactor.push_back(10);
85  }
86 
87  /**
88  * @see armarx::ManagedIceObject::getDefaultName()
89  */
90  std::string getDefaultName() const override
91  {
92  return "FunctionApproximator";
93  }
94 
95 
96  protected:
97  /**
98  * @see armarx::ManagedIceObject::onInitComponent()
99  */
100  void onInitComponent() override;
101 
102  /**
103  * @see armarx::ManagedIceObject::onConnectComponent()
104  */
105  void onConnectComponent() override;
106 
107  /**
108  * @see armarx::ManagedIceObject::onDisconnectComponent()
109  */
110  void onDisconnectComponent() override;
111 
112  /**
113  * @see armarx::ManagedIceObject::onExitComponent()
114  */
115  void onExitComponent() override;
116 
117  /**
118  * @see PropertyUser::createPropertyDefinitions()
119  */
120  // virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions();
121 
122  // FunctionApproximatorBase interface
123  public:
124 
125  void initialize(const std::string& fappName, const Ice::DoubleSeq& factors, const Ice::Current&) override;
126  void learn(const std::string& name, const DVector2d&, const DVector2d&, const Ice::Current&) override;
127  Ice::Double predict(const std::string& name, const Ice::DoubleSeq&, const Ice::Current&) override;
128  void ilearn(const std::string& name, const Ice::DoubleSeq&, Ice::Double, const Ice::Current&) override;
129  void blearn(const std::string& name, const Ice::DoubleSeq&, const Ice::DoubleSeq&, const Ice::Current&) override;
130  Ice::DoubleSeq bpredict(const std::string& name, const Ice::DoubleSeq& x, const Ice::Current&) override;
131 
132  void getFunctionApproximatorFromFile(const std::string& funcName, const std::string& name, const Ice::Current&) override; //TODO: deserialization;
133  void getFunctionApproximatorsFromFile(const std::vector<std::string>& funcNameList, const std::string& filename, const Ice::Current&) override;
134  void saveFunctionApproximatorInFile(const std::string& funcName, const std::string& name, const Ice::Current&) override; //TODO: serialization;
135 
136  // void getWeightsFromFile(const std::string & funcName, const std::string& filename, const Ice::Current&);
137  // void writeWeightsToFile(const std::string & funcName, const std::string& filename, const Ice::Current&);
138 
139  void reset(const Ice::Current&) override;
140 
141  void saveFunctionApproximatorInFileTest(const std::string& funcName, const std::string& name);
142  void initializeTest(const std::string& fappName, const Ice::DoubleSeq& widthFactors);
143  private:
144  FuncAppMap funcAppPool;
145  int dimension;
146  int num;
147 
148  };
150 
151 }
152 
armarx::FunctionApproximatorPropertyDefinitions
Definition: FunctionApproximator.h:48
armarx::FuncAppPair
std::pair< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppPair
Definition: FunctionApproximator.h:72
armarx::FunctionApproximator::onInitComponent
void onInitComponent() override
Definition: FunctionApproximator.cpp:29
armarx::FuncAppMap
std::map< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppMap
Definition: FunctionApproximator.h:71
armarx::FunctionApproximator::onDisconnectComponent
void onDisconnectComponent() override
Definition: FunctionApproximator.cpp:46
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::FunctionApproximator::getDefaultName
std::string getDefaultName() const override
Definition: FunctionApproximator.h:90
armarx::FunctionApproximator::predict
Ice::Double predict(const std::string &name, const Ice::DoubleSeq &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:103
armarx::FunctionApproximator::bpredict
Ice::DoubleSeq bpredict(const std::string &name, const Ice::DoubleSeq &x, const Ice::Current &) override
Definition: FunctionApproximator.cpp:167
armarx::FunctionApproximator::learn
void learn(const std::string &name, const DVector2d &, const DVector2d &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:59
armarx::FunctionApproximatorPropertyDefinitions::FunctionApproximatorPropertyDefinitions
FunctionApproximatorPropertyDefinitions(std::string prefix)
Definition: FunctionApproximator.h:52
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FunctionApproximator::onExitComponent
void onExitComponent() override
Definition: FunctionApproximator.cpp:53
armarx::FunctionApproximator::saveFunctionApproximatorInFile
void saveFunctionApproximatorInFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
Definition: FunctionApproximator.cpp:252
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::FunctionApproximator::onConnectComponent
void onConnectComponent() override
Definition: FunctionApproximator.cpp:40
armarx::FunctionApproximator::reset
void reset(const Ice::Current &) override
Definition: FunctionApproximator.cpp:188
armarx::FunctionApproximator::saveFunctionApproximatorInFileTest
void saveFunctionApproximatorInFileTest(const std::string &funcName, const std::string &name)
Definition: FunctionApproximator.cpp:279
armarx::FunctionApproximator::FunctionApproximator
FunctionApproximator()
Definition: FunctionApproximator.h:79
filename
std::string filename
Definition: VisualizationRobot.cpp:84
armarx::FunctionApproximator::initialize
void initialize(const std::string &fappName, const Ice::DoubleSeq &factors, const Ice::Current &) override
Definition: FunctionApproximator.cpp:207
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:95
armarx::FunctionApproximator::blearn
void blearn(const std::string &name, const Ice::DoubleSeq &, const Ice::DoubleSeq &, const Ice::Current &) override
Definition: FunctionApproximator.cpp:147
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::FunctionApproximator::ilearn
void ilearn(const std::string &name, const Ice::DoubleSeq &, Ice::Double, const Ice::Current &) override
Definition: FunctionApproximator.cpp:126
armarx::FunctionApproximator::getFunctionApproximatorFromFile
void getFunctionApproximatorFromFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
Definition: FunctionApproximator.cpp:217
armarx::FunctionApproximator::getFunctionApproximatorsFromFile
void getFunctionApproximatorsFromFile(const std::vector< std::string > &funcNameList, const std::string &filename, const Ice::Current &) override
Definition: FunctionApproximator.cpp:232
armarx::FunctionApproximator::initializeTest
void initializeTest(const std::string &fappName, const Ice::DoubleSeq &widthFactors)
Definition: FunctionApproximator.cpp:269
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28