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> 43 using namespace Eigen;
48 ModelParametersRRRFF::ModelParametersRRRFF(Eigen::VectorXd weights, Eigen::MatrixXd cosines_periodes, Eigen::VectorXd cosines_phase)
51 cosines_periodes_(cosines_periodes),
52 cosines_phase_(cosines_phase)
55 assert(cosines_phase.size() == cosines_periodes.rows());
56 assert(weights.rows() == cosines_periodes.rows());
58 nb_in_dim_ = cosines_periodes.cols();
61 all_values_vector_size_ = 0;
62 all_values_vector_size_ += weights_.rows() * weights_.cols();
63 all_values_vector_size_ += cosines_phase_.size();
64 all_values_vector_size_ += cosines_periodes_.rows() * cosines_periodes_.cols();
78 if ( inputs.rows()==inputs_cached_.rows() && inputs.cols()==inputs_cached_.cols() )
81 if ( (inputs.array()==inputs_cached_.array()).all() )
84 cosine_activations = cosine_activations_cached_;
90 BasisFunction::Cosine::activations(cosines_periodes_,cosines_phase_,inputs,cosine_activations);
95 inputs_cached_ = inputs;
96 cosine_activations_cached_ = cosine_activations;
106 template<
class Archive>
107 void ModelParametersRRRFF::serialize(Archive & ar,
const unsigned int version)
112 ar & BOOST_SERIALIZATION_NVP(weights_);
113 ar & BOOST_SERIALIZATION_NVP(cosines_periodes_);
114 ar & BOOST_SERIALIZATION_NVP(cosines_phase_);
115 ar & BOOST_SERIALIZATION_NVP(nb_in_dim_);
116 ar & BOOST_SERIALIZATION_NVP(all_values_vector_size_);
127 selected_values_labels = set<string>();
128 selected_values_labels.insert(
"weights");
129 selected_values_labels.insert(
"phases");
130 selected_values_labels.insert(
"periods");
136 selected_mask.fill(0);
141 size = weights_.rows() * weights_.cols();
142 if (selected_values_labels.find(
"weights")!=selected_values_labels.end())
143 selected_mask.segment(offset,size).fill(1);
146 size = cosines_phase_.size();
147 if (selected_values_labels.find(
"phases")!=selected_values_labels.end())
148 selected_mask.segment(offset,size).fill(2);
151 size = cosines_periodes_.rows() * cosines_periodes_.cols();
152 if (selected_values_labels.find(
"periods")!=selected_values_labels.end())
153 selected_mask.segment(offset,size).fill(3);
164 for (
int c = 0; c < weights_.cols(); c++)
166 values.segment(offset, weights_.rows()) = weights_.col(c);
167 offset += weights_.rows();
170 values.segment(offset, cosines_phase_.size()) = cosines_phase_;
171 offset += cosines_phase_.size();
173 for (
int c = 0; c < cosines_periodes_.cols(); c++)
175 values.segment(offset, cosines_periodes_.rows()) = cosines_periodes_.col(c);
176 offset += cosines_periodes_.rows();
185 if (all_values_vector_size_ != values.size())
187 cerr << __FILE__ <<
":" << __LINE__ <<
": values is of wrong size." << endl;
192 for (
int c = 0; c < weights_.cols(); c++)
194 weights_.col(c) = values.segment(offset, weights_.rows());
195 offset += weights_.rows();
198 cosines_phase_ = values.segment(offset, cosines_phase_.size());
199 offset += cosines_phase_.size();
201 for (
int c = 0; c < cosines_periodes_.cols(); c++)
203 cosines_periodes_.col(c) = values.segment(offset, cosines_periodes_.rows());
204 offset += cosines_periodes_.rows();
212 return new UnifiedModel(cosines_periodes_, cosines_phase_, weights_);
void getSelectableParameters(std::set< std::string > &selected_values_labels) const
Return all the names of the parameter types that can be selected.
UnifiedModel class header file.
std::string toString(void) const
Returns a string representation of the object.
void getParameterVectorMask(const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
Get a mask for selecting parameters.
ModelParameters * clone(void) const
Return a pointer to a deep copy of the ModelParameters object.
int getExpectedInputDim(void) const
The expected dimensionality of the input data.
BasisFunction header file.
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.
UnifiedModel * toUnifiedModel(void) const
Convert these model parameters to unified model parameters.
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.
void setParameterVectorAll(const Eigen::VectorXd &values)
Set all available parameter values with one vector.
ModelParametersRRRFF class header file.
Model parameters for the RRRFF function approximator.
Header file to generate strings from boost serialized files.
void getParameterVectorAll(Eigen::VectorXd &all_values) const
Return a vector that returns all available parameter values.
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...
void cosineActivations(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &cosine_activations) const
Get the values of the cosine basis functions for given inputs.
Header file for serialization of Eigen matrices.
BOOST_CLASS_EXPORT_IMPLEMENT(DmpBbo::ModelParametersRRRFF)
For boost::serialization.