35 ARMARX_INFO <<
"successfully initialized DMP component" ;
48 ARMARX_INFO <<
"disconnecting FunctionApproximator component";
55 ARMARX_INFO <<
"exiting FunctionApproximator component";
62 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool.find(name)->second;
65 if (x.size() != y.size())
67 ARMARX_ERROR <<
"The factors dimension should be the same as the responds dimension.";
77 for (
size_t i = 0; i < x.size(); ++i)
82 for (
size_t j = 0; j < x[i].size(); ++j)
84 cx.push_back(x[i][j]);
85 cy.push_back(y[i][j]);
93 approximator->learn(xx, yy);
98 ARMARX_ERROR <<
"predict: function approximator not found.";
105 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool.find(name)->second;
110 for (
size_t i = 0; i < x.size(); ++i)
112 xx.push_back(x.at(i));
115 double res = (*approximator)(xx).at(0);
121 ARMARX_ERROR <<
"predict: function approximator not found.";
128 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool.find(name)->second;
133 for (
size_t i = 0; i < x.size(); ++i)
135 factors.push_back(x.at(i));
138 approximator->ilearn(factors, y);
142 ARMARX_ERROR <<
"ilearn: function approximator not found.";
149 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool.find(name)->second;
153 DMP::DVec2d responds;
158 approximator->learn(factors, responds);
162 ARMARX_ERROR <<
"ilearn: function approximator not found.";
169 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool.find(name)->second;
172 Ice::DoubleSeq responds;
174 for (
size_t i = 0; i < x.size(); ++i)
176 responds.push_back((*approximator)(x.at(i)).at(0));
183 ARMARX_ERROR <<
"ilearn: function approximator not found.";
184 return std::vector<double>();
191 for (FuncAppMap::iterator it = funcAppPool.begin(); it != funcAppPool.end(); ++it)
193 it->second.reset(
new DMP::RBFInterpolator<DMP::GaussRadialBasisFunction>(2));
211 DMP::FunctionApproximationInterfacePtr approximator(
new DMP::LWR<DMP::GaussKernel>(100));
213 funcAppPool.insert(
FuncAppPair(fappName, approximator));
219 std::ifstream file(name);
221 DMP::FunctionApproximationInterface* readPtr;
223 boost::archive::xml_iarchive ar(file);
224 ar >> boost::serialization::make_nvp(
"approximator", readPtr);
228 DMP::FunctionApproximationInterfacePtr approximator(readPtr);
229 funcAppPool.insert(
FuncAppPair(funcName, approximator));
236 std::vector<DMP::FunctionApproximationInterface*> readPtr;
238 boost::archive::xml_iarchive ar(file);
239 ar >> boost::serialization::make_nvp(
"approximator", readPtr);
243 for (
size_t i = 0; i < readPtr.size(); i++)
246 DMP::FunctionApproximationInterfacePtr approximator(readPtr[i]);
247 funcAppPool.insert(
FuncAppPair(funcName[i], approximator));
255 std::cout <<
"save function approximator in file ... " << std::endl;
256 std::ofstream file(name);
258 boost::archive::xml_oarchive ar(file);
260 DMP::FunctionApproximationInterface* savedPtr = funcAppPool[funcName].get();
262 ar << boost::serialization::make_nvp(
"approximator", savedPtr);
271 int dim = widthFactors.size();
273 DMP::FunctionApproximationInterfacePtr approximator(
new DMP::RBFInterpolator<DMP::GaussRadialBasisFunction>(dim, widthFactors));
275 funcAppPool.insert(
FuncAppPair(fappName, approximator));
282 std::cout <<
"save function approximator in file ... " << std::endl;
283 std::ofstream file(name);
284 DMP::FunctionApproximationInterfacePtr approximator = funcAppPool[funcName];
286 boost::archive::text_oarchive ar(file);
287 DMP::FunctionApproximationInterface* savedPtr = approximator.get();
288 ar << boost::serialization::make_nvp(
"approximator", savedPtr);
290 DMP::FunctionApproximationInterface* appPtr = approximator.get();
291 std::stringstream
str;
293 boost::archive::xml_oarchive ar1(
str);
294 ar1 << boost::serialization::make_nvp(
"approximator", appPtr);
296 std::cout <<
str.str() << std::endl;
298 boost::archive::xml_iarchive ari(
str);
299 DMP::FunctionApproximationInterface* newPtr;
300 ari >> boost::serialization::make_nvp(
"approximator", newPtr);