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
42namespace 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;
130 Ice::Double
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
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
void initializeTest(const std::string &fappName, const Ice::DoubleSeq &widthFactors)
void blearn(const std::string &name, const Ice::DoubleSeq &, const Ice::DoubleSeq &, const Ice::Current &) override
void reset(const Ice::Current &) override
void getFunctionApproximatorsFromFile(const std::vector< std::string > &funcNameList, const std::string &filename, const Ice::Current &) override
Ice::Double predict(const std::string &name, const Ice::DoubleSeq &, const Ice::Current &) override
void getFunctionApproximatorFromFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
void initialize(const std::string &fappName, const Ice::DoubleSeq &factors, const Ice::Current &) override
Ice::DoubleSeq bpredict(const std::string &name, const Ice::DoubleSeq &x, const Ice::Current &) override
void learn(const std::string &name, const DVector2d &, const DVector2d &, const Ice::Current &) override
void ilearn(const std::string &name, const Ice::DoubleSeq &, Ice::Double, const Ice::Current &) override
void saveFunctionApproximatorInFile(const std::string &funcName, const std::string &name, const Ice::Current &) override
void saveFunctionApproximatorInFileTest(const std::string &funcName, const std::string &name)
std::string getDefaultName() const override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppMap
::IceInternal::Handle<::armarx::FunctionApproximator > FunctionApproximatorPtr
std::pair< std::string, DMP::FunctionApproximationInterfacePtr > FuncAppPair