27 #ifndef _FUNCTIONAPPROXIMATOR_H_ 28 #define _FUNCTIONAPPROXIMATOR_H_ 32 #include <boost/serialization/nvp.hpp> 36 #include <eigen3/Eigen/Core> 42 class ModelParameters;
80 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
81 const Eigen::Ref<const Eigen::MatrixXd>& targets) = 0;
90 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
91 const Eigen::Ref<const Eigen::MatrixXd>& targets,
92 std::string save_directory,
93 bool overwrite=
false);
103 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
104 const Eigen::Ref<const Eigen::MatrixXd>& targets);
116 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
117 const Eigen::Ref<const Eigen::MatrixXd>& targets,
118 std::string save_directory,
119 bool overwrite=
false);
130 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
131 Eigen::MatrixXd& outputs) = 0;
143 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
144 Eigen::MatrixXd& outputs,
145 Eigen::MatrixXd& variances)
161 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
162 Eigen::MatrixXd& outputs,
163 std::vector<Eigen::MatrixXd>& variances)
166 for (
unsigned int i=0; i<variances.size(); i++)
167 variances[i].fill(0);
182 const Eigen::Ref<const Eigen::MatrixXd>& inputs,
183 Eigen::MatrixXd& variances)
193 return (model_parameters_!=NULL);
210 virtual std::string
getName(
void)
const = 0;
224 void getParameterVectorMask(
const std::set<std::string> selected_values_labels, Eigen::VectorXi& selected_mask)
const;
245 output << function_approximator.
toString();
278 static void generateInputsGrid(
const Eigen::VectorXd& min,
const Eigen::VectorXd& max,
const Eigen::VectorXi& n_samples_per_dim, Eigen::MatrixXd& inputs_grid);
292 virtual bool saveGridData(
const Eigen::VectorXd& min,
const Eigen::VectorXd& max,
const Eigen::VectorXi& n_samples_per_dim, std::string directory,
bool overwrite=
false)
const;
328 bool checkModelParametersInitialized(
void)
const;
338 template<
class Archive>
339 void serialize(Archive & ar,
const unsigned int version)
344 ar & BOOST_SERIALIZATION_NVP(meta_parameters_);
345 ar & BOOST_SERIALIZATION_NVP(model_parameters_);
354 #include <boost/serialization/assume_abstract.hpp> 358 #include <boost/serialization/export.hpp> 361 #endif // _FUNCTIONAPPROXIMATOR_H_ Parameterizable class header file.
friend class boost::serialization::access
Give boost serialization access to private members.
virtual bool saveGridData(const Eigen::VectorXd &min, const Eigen::VectorXd &max, const Eigen::VectorXi &n_samples_per_dim, std::string directory, bool overwrite=false) const
Generate a grid of inputs, and output the response of the basis functions and line segments for these...
virtual void train(const Eigen::Ref< const Eigen::MatrixXd > &inputs, const Eigen::Ref< const Eigen::MatrixXd > &targets)=0
Train the function approximator with corresponding input and target examples.
void getParameterVectorSelectedMinMax(Eigen::VectorXd &min, Eigen::VectorXd &max) const
Get the minimum and maximum of the selected parameters in one vector.
friend std::ostream & operator<<(std::ostream &output, const FunctionApproximator &function_approximator)
Print to output stream.
void setParameterVectorSelected(const Eigen::VectorXd &values, bool normalized=false)
Set all the values of the selected parameters with one vector.
void reTrain(const Eigen::Ref< const Eigen::MatrixXd > &inputs, const Eigen::Ref< const Eigen::MatrixXd > &targets)
Re-train the function approximator with corresponding input and target examples.
static void generateInputsGrid(const Eigen::VectorXd &min, const Eigen::VectorXd &max, const Eigen::VectorXi &n_samples_per_dim, Eigen::MatrixXd &inputs_grid)
Generate a input samples that lie on a grid (much like Matlab's meshgrid) For instance, if min = [2 6], and max = [3 8], and n_samples_per_dim = [3 5] then this function first makes linearly spaces samples along each dimension, e.g.
Class for providing access to a model's parameters as a vector.
bool isTrained(void) const
Determine whether the function approximator has already been trained with data or not...
void setParameterVectorAll(const Eigen::VectorXd &values)
Set all available parameter values with one vector.
void getParameterVectorSelected(Eigen::VectorXd &values, bool normalized=false) const
Get the values of the selected parameters in one vector.
virtual void predictVariance(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &variances)
Query the function approximator to get the variance of a prediction This function is not implemented ...
int getExpectedOutputDim(void) const
The expected dimensionality of the output data.
Base class for all function approximators.
void setParameterVectorModifierPrivate(std::string modifier, bool new_value)
Turn certain modifiers on or off, see Parameterizable::setParameterVectorModifier().
virtual void predict(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &outputs)=0
Query the function approximator to make a prediction.
virtual void predict(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &outputs, std::vector< Eigen::MatrixXd > &variances)
Query the function approximator to make a prediction, and also to predict its variance.
The unified model, which can be used to represent the model of all other function approximators...
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...
BOOST_SERIALIZATION_ASSUME_ABSTRACT(DmpBbo::FunctionApproximator)
Tell boost serialization that this class has pure virtual functions.
Base class for all model parameters of function approximators.
virtual FunctionApproximator * clone(void) const =0
Return a pointer to a deep copy of the FunctionApproximator object.
UnifiedModel * getUnifiedModel(void) const
Return a representation of this function approximator's model as a unified model. ...
void setSelectedParameters(const std::set< std::string > &selected_values_labels)
Determine which subset of parameters is represented in the vector returned by Parameterizable::getPar...
const MetaParameters * getMetaParameters(void) const
Accessor for FunctionApproximator::meta_parameters_.
virtual void predict(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &outputs, Eigen::MatrixXd &variances)
Query the function approximator to make a prediction, and also to predict its variance.
virtual std::string getName(void) const =0
Get the name of this function approximator.
void getParameterVectorMask(const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
Get a mask for selecting parameters.
const ModelParameters * getModelParameters(void) const
Accessor for FunctionApproximator::model_parameters_.
std::string toString(void) const
Returns a string representation of the object.
int getParameterVectorSelectedSize(void) const
Get the size of the vector of selected parameters, as returned by getParameterVectorSelected(.
void setModelParameters(ModelParameters *model_parameters)
Accessor for FunctionApproximator::model_parameters_.
FunctionApproximator(void)
Default constructor.
void getSelectableParameters(std::set< std::string > &selected_values_labels) const
Return all the names of the parameter types that can be selected.
int getExpectedInputDim(void) const
The expected dimensionality of the input data.
BOOST_CLASS_IMPLEMENTATION(DmpBbo::FunctionApproximator, boost::serialization::object_serializable)
Don't add version information to archives.
void getParameterVectorAll(Eigen::VectorXd &values) const
Return a vector that returns all available parameter values.