24 #include <boost/serialization/export.hpp> 25 #include <boost/archive/text_iarchive.hpp> 26 #include <boost/archive/text_oarchive.hpp> 27 #include <boost/archive/xml_iarchive.hpp> 28 #include <boost/archive/xml_oarchive.hpp> 45 using namespace Eigen;
50 ModelParametersLWPR::ModelParametersLWPR(LWPR_Object* lwpr_object)
52 lwpr_object_(lwpr_object)
57 void ModelParametersLWPR::countLengths(
void)
64 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
66 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
68 n_centers_ += lwpr_object_->nIn();
69 n_slopes_ += lwpr_object_->model.sub[iDim].rf[iRF]->nReg;
73 n_widths_ = n_centers_;
77 ModelParametersLWPR::~ModelParametersLWPR(
void)
84 LWPR_Object* lwpr_object_clone =
new LWPR_Object(*lwpr_object_);
119 return lwpr_object_->nIn();
124 selected_values_labels = set<string>();
125 selected_values_labels.insert(
"centers");
126 selected_values_labels.insert(
"widths");
127 selected_values_labels.insert(
"slopes");
128 selected_values_labels.insert(
"offsets");
137 selected_mask.fill(0);
144 if (selected_values_labels.find(
"centers")!=selected_values_labels.end())
145 selected_mask.segment(offset,size).fill(1);
150 if (selected_values_labels.find(
"widths")!=selected_values_labels.end())
151 selected_mask.segment(offset,size).fill(2);
156 if (selected_values_labels.find(
"offsets")!=selected_values_labels.end())
157 selected_mask.segment(offset,size).fill(3);
162 if (selected_values_labels.find(
"slopes")!=selected_values_labels.end())
163 selected_mask.segment(offset,size).fill(4);
174 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
175 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
176 for (
int j = 0; j < lwpr_object_->nIn(); j++)
177 values[ii++] = lwpr_object_->model.sub[iDim].rf[iRF]->c[j];
179 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
180 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
181 for (
int j = 0; j < lwpr_object_->nIn(); j++)
182 values[ii++] = lwpr_object_->model.sub[iDim].rf[iRF]->D[j*lwpr_object_->model.nInStore+j];
184 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
185 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
186 for (
int j = 0; j < lwpr_object_->model.sub[iDim].rf[iRF]->nReg; j++)
187 values[ii++] = lwpr_object_->model.sub[iDim].rf[iRF]->beta[j];
189 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
190 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
191 values[ii++] = lwpr_object_->model.sub[iDim].rf[iRF]->beta0;
200 cerr << __FILE__ <<
":" << __LINE__ <<
": values is of wrong size." << endl;
205 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
206 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
207 for (
int j = 0; j < lwpr_object_->nIn(); j++)
208 lwpr_object_->model.sub[iDim].rf[iRF]->c[j] = values[ii++];
210 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
211 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
212 for (
int j = 0; j < lwpr_object_->nIn(); j++)
213 lwpr_object_->model.sub[iDim].rf[iRF]->D[j*lwpr_object_->model.nInStore+j] = values[ii++];
215 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
216 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
217 for (
int j = 0; j < lwpr_object_->model.sub[iDim].rf[iRF]->nReg; j++)
218 lwpr_object_->model.sub[iDim].rf[iRF]->beta[j] = values[ii++];
220 for (
int iDim = 0; iDim < lwpr_object_->model.nOut; iDim++)
221 for (
int iRF = 0; iRF < lwpr_object_->model.sub[iDim].numRFS; iRF++)
222 lwpr_object_->model.sub[iDim].rf[iRF]->beta0 = values[ii++];
230 if (lwpr_object_->nIn()!=1)
235 if (lwpr_object_->model.nOut!=1)
244 int n_basis_functions = lwpr_object_->model.sub[i_out].numRFS;
245 VectorXd centers(n_basis_functions);
246 VectorXd widths(n_basis_functions);
247 VectorXd offsets(n_basis_functions);
248 VectorXd slopes(n_basis_functions);
252 for (
int iRF = 0; iRF < lwpr_object_->model.sub[i_out].numRFS; iRF++)
254 LWPR_ReceptiveFieldObject rf = lwpr_object_->getRF(i_out,iRF);
257 centers[iRF] = tmp[i_in];
259 offsets[iRF] = rf.beta0();
262 slopes[iRF] = tmp[i_in];
265 vector<vector<double> > D = rf.D();
266 widths[iRF] = sqrt(1.0/D[i_in][i_in]);
271 vector<double> norm_out = lwpr_object_->normOut();
272 vector<double> norm_in = lwpr_object_->normIn();
280 offsets /= norm_out[i_out];
281 slopes /= norm_out[i_out];
282 centers /= norm_in[i_in];
283 widths /= norm_in[i_in];
291 bool normalized_basis_functions=
true;
292 bool lines_pivot_at_max_activation=
true;
295 normalized_basis_functions, lines_pivot_at_max_activation);
298 template<
class Archive>
299 void ModelParametersLWPR::serialize(Archive & ar,
const unsigned int version)
304 std::cerr <<
"ERROR: Don't know how to serialize ModelParametersLWPR yet..." << std::endl;
UnifiedModel class header file.
void getParameterVectorMask(const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
Get a mask for selecting parameters.
void getSelectableParameters(std::set< std::string > &selected_values_labels) const
Return all the names of the parameter types that can be selected.
void setParameterVectorAll(const Eigen::VectorXd &values)
Set all available parameter values with one vector.
ModelParameters * clone(void) const
Return a pointer to a deep copy of the ModelParameters object.
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...
ModelParametersLWPR class header file.
void getParameterVectorAll(Eigen::VectorXd &all_values) const
Return a vector that returns all available parameter values.
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.
The unified model, which can be used to represent the model of all other function approximators...
Base class for all model parameters of function approximators.
BOOST_CLASS_EXPORT_IMPLEMENT(DmpBbo::ModelParametersLWPR)
For boost::serialization.
UnifiedModel * toUnifiedModel(void) const
Convert these LWPR model parameters to unified model parameters.
std::string toString(void) const
Returns a string representation of the object.
Model parameters for the Locally Weighted Projection Regression (LWPR) function approximator.
int getExpectedInputDim(void) const
The expected dimensionality of the input data.
Header file to generate strings from boost serialized files.
Header file for serialization of Eigen matrices.