DMP_BBO library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
DmpContextual Class Referenceabstract

Implementation of Contextual Dynamical Movement Primitives. More...

#include <DmpContextual.hpp>

Inheritance diagram for DmpContextual:
Inheritance graph
[legend]
Collaboration diagram for DmpContextual:
Collaboration graph
[legend]

Public Member Functions

 DmpContextual (int n_dims_dmp, std::vector< FunctionApproximator * > function_approximators, DmpType dmp_type)
 Initialization constructor for Contextual DMPs of known dimensionality, but with unknown initial and attractor states. More...
 
void set_task_parameters (const Eigen::MatrixXd &task_parameters)
 Set the current task parameters. More...
 
void set_policy_parameter_function_goal (FunctionApproximator *function_approximator)
 Set a function approximator to predict the goal from the task parameters. More...
 
void set_policy_parameter_function_duration (FunctionApproximator *function_approximator)
 Set a function approximator to predict the duration from the task parameters. More...
 
virtual void computeFunctionApproximatorOutput (const Eigen::Ref< const Eigen::MatrixXd > &phase_state, Eigen::MatrixXd &fa_output) const =0
 Compute the outputs of the function approximators. More...
 
virtual void train (const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
 Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful for debugging, i.e. More...
 
void train (const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory)
 Train a contextual DMP with multiple trajectories. More...
 
void train (const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters)
 Train a contextual DMP with multiple trajectories. More...
 
void train (const std::vector< Trajectory > &trajectories, std::string save_directory, bool overwrite)
 Train a contextual DMP with multiple trajectories. More...
 
void train (const std::vector< Trajectory > &trajectories, std::string save_directory)
 Train a contextual DMP with multiple trajectories. More...
 
void train (const std::vector< Trajectory > &trajectories)
 Train a contextual DMP with multiple trajectories. More...
 
- Public Member Functions inherited from Dmp
 Dmp (double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, std::vector< FunctionApproximator * > function_approximators, double alpha_spring_damper, DynamicalSystem *goal_system, DynamicalSystem *phase_system, DynamicalSystem *gating_system, ForcingTermScaling scaling=NO_SCALING)
 Initialization constructor. More...
 
 Dmp (int n_dims_dmp, std::vector< FunctionApproximator * > function_approximators, double alpha_spring_damper, DynamicalSystem *goal_system, DynamicalSystem *phase_system, DynamicalSystem *gating_system, ForcingTermScaling scaling=NO_SCALING)
 Initialization constructor for Dmps of known dimensionality, but with unknown initial and attractor states. More...
 
 Dmp (double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, std::vector< FunctionApproximator * > function_approximators, DmpType dmp_type=KULVICIUS_2012_JOINING, ForcingTermScaling scaling=NO_SCALING)
 Constructor that initializes the DMP with default dynamical systems. More...
 
 Dmp (int n_dims_dmp, std::vector< FunctionApproximator * > function_approximators, DmpType dmp_type=KULVICIUS_2012_JOINING, ForcingTermScaling scaling=NO_SCALING)
 Initialization constructor for Dmps of known dimensionality, but with unknown initial and attractor states. More...
 
 Dmp (double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, double alpha_spring_damper, DynamicalSystem *goal_system)
 Initialization constructor for Dmps without a forcing term. More...
 
 ~Dmp (void)
 Destructor. More...
 
Dmpclone (void) const
 Return a deep copy of this object. More...
 
virtual void integrateStart (Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd) const
 Start integrating the system. More...
 
void differentialEquation (const Eigen::Ref< const Eigen::VectorXd > &x, Eigen::Ref< Eigen::VectorXd > xd) const
 The differential equation which defines the system. More...
 
void analyticalSolution (const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds, Eigen::MatrixXd &forcing_terms, Eigen::MatrixXd &fa_output) const
 Return analytical solution of the system at certain times (and return forcing terms) More...
 
void analyticalSolution (const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds, Eigen::MatrixXd &forcing_terms) const
 Return analytical solution of the system at certain times (and return forcing terms) More...
 
void analyticalSolution (const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds) const
 Return analytical solution of the system at certain times. More...
 
virtual void analyticalSolution (const Eigen::VectorXd &ts, Trajectory &trajectory) const
 Return analytical solution of the system at certain times. More...
 
void analyticalSolution (const Eigen::VectorXd &ts, Trajectory &trajectory, Eigen::MatrixXd &forcing_terms) const
 Return analytical solution of the system at certain times. More...
 
virtual void statesAsTrajectory (const Eigen::MatrixXd &x_in, const Eigen::MatrixXd &xd_in, Eigen::MatrixXd &y_out, Eigen::MatrixXd &yd_out, Eigen::MatrixXd &ydd_out) const
 Get the output of a DMP dynamical system as a trajectory. More...
 
virtual void statesAsTrajectory (const Eigen::VectorXd &ts, const Eigen::MatrixXd &x_in, const Eigen::MatrixXd &xd_in, Trajectory &trajectory) const
 Get the output of a DMP dynamical system as a trajectory. More...
 
virtual void train (const Trajectory &trajectory)
 Train a DMP with a trajectory. More...
 
virtual void train (const Trajectory &trajectory, std::string save_directory, bool overwrite=false)
 Train a DMP with a trajectory, and write results to file. More...
 
virtual void set_tau (double tau)
 Accessor function for the time constant. More...
 
virtual void set_initial_state (const Eigen::VectorXd &y_init)
 Accessor function for the initial state of the system. More...
 
virtual void set_attractor_state (const Eigen::VectorXd &y_attr)
 Accessor function for the attractor state of the system. More...
 
void set_damping_coefficient (double damping_coefficient)
 Accessor function for damping coefficient of spring-damper system. More...
 
void set_spring_constant (double spring_constant)
 Accessor function for spring constant of spring-damper system. More...
 
std::string toString (void) const
 Returns a string representation of the object. More...
 
void getSelectableParameters (std::set< std::string > &selectable_values_labels) const
 Return all the names of the parameter types that can be selected. More...
 
void setSelectedParameters (const std::set< std::string > &selected_values_labels)
 Determine which subset of parameters is represented in the vector returned by Parameterizable::getParameterVectorSelected. More...
 
int getParameterVectorAllSize (void) const
 Get the size of the parameter values vector when it contains all available parameter values. More...
 
void getParameterVectorAll (Eigen::VectorXd &values) const
 Return a vector that returns all available parameter values. More...
 
void setParameterVectorAll (const Eigen::VectorXd &values)
 Set all available parameter values with one vector. More...
 
void getParameterVectorMask (const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
 Get a mask for selecting parameters. More...
 
void computeFunctionApproximatorInputsAndTargets (const Trajectory &trajectory, Eigen::VectorXd &fa_inputs_phase, Eigen::MatrixXd &fa_targets) const
 Given a trajectory, compute the inputs and targets for the function approximators. More...
 
void set_perturbation_analytical_solution (double perturbation_standard_deviation)
 Add a perturbation to the forcing term when computing the analytical solution. More...
 
double get_perturbation_analytical_solution () const
 Get the perturbation to the forcing term when computing the analytical solution. More...
 
- Public Member Functions inherited from DynamicalSystem
 DynamicalSystem (int order, double tau, Eigen::VectorXd initial_state, Eigen::VectorXd attractor_state, std::string name)
 Initialization constructor. More...
 
virtual ~DynamicalSystem (void)
 Destructor.
 
void integrateStart (const Eigen::VectorXd &x_init, Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd)
 Start integrating the system with a new initial state. More...
 
virtual void integrateStep (double dt, const Eigen::Ref< const Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > x_updated, Eigen::Ref< Eigen::VectorXd > xd_updated) const
 Integrate the system one time step. More...
 
void set_integration_method (IntegrationMethod integration_method)
 Choose the integration method. More...
 
int dim (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
int dim_orig (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
double tau (void) const
 Accessor function for the time constant. More...
 
Eigen::VectorXd initial_state (void) const
 Accessor function for the initial state of the dynamical system. More...
 
void initial_state (Eigen::VectorXd &initial_state) const
 Accessor function for the initial state of the dynamical system. More...
 
Eigen::VectorXd attractor_state (void) const
 Accessor function for the attractor state of the dynamical system. More...
 
void attractor_state (Eigen::VectorXd &attractor_state) const
 Accessor function for the attractor state of the dynamical system. More...
 
virtual void set_attractor_state (const Eigen::Ref< const Eigen::VectorXd > &attractor_state)
 Mutator function for the attractor state of the dynamical system. More...
 
std::string name (void) const
 Accessor function for the name of the dynamical system. More...
 
virtual void set_name (std::string name)
 Mutator function for the name of the dynamical system. More...
 
- Public Member Functions inherited from Parameterizable
virtual ~Parameterizable (void)
 Destructor.
 
virtual int getParameterVectorSelectedSize (void) const
 Get the size of the vector of selected parameters, as returned by getParameterVectorSelected(. More...
 
virtual void getParameterVectorSelected (Eigen::VectorXd &values, bool normalized=false) const
 Get the values of the selected parameters in one vector. More...
 
virtual void getParameterVectorSelectedNormalized (Eigen::VectorXd &values) const
 Get the normalized values of the selected parameters in one vector. More...
 
void getParameterVectorSelectedMinMax (Eigen::VectorXd &min, Eigen::VectorXd &max) const
 Get the minimum and maximum of the selected parameters in one vector. More...
 
void getParameterVectorAllMinMax (Eigen::VectorXd &min, Eigen::VectorXd &max) const
 Get the minimum and maximum values of the current parameter vector. More...
 
void getParameterVectorSelectedRanges (Eigen::VectorXd &ranges) const
 Get the ranges of the selected parameters, i.e. More...
 
virtual void setParameterVectorSelected (const Eigen::VectorXd &values, bool normalized=false)
 Set all the values of the selected parameters with one vector. More...
 
virtual void setParameterVectorSelectedNormalized (const Eigen::VectorXd &values)
 Set all the values of the selected parameters with one vector of normalized values. More...
 
void setSelectedParametersOne (std::string selected)
 Set the parameters that are currently selected. More...
 
void setParameterVectorModifier (std::string modifier, bool new_value)
 Turn certain modifiers on or off. More...
 
void setVectorLengthsPerDimension (const Eigen::VectorXi &lengths_per_dimension)
 The vector (VectorXd) with parameter values can be split into different parts (as vector<VectorXd>; this function specifices the length of each sub-vector. More...
 
Eigen::VectorXi getVectorLengthsPerDimension (void) const
 Get the specified length of each vector in each dimension. More...
 
void getParameterVectorSelected (std::vector< Eigen::VectorXd > &values, bool normalized=false) const
 Get the values of the selected parameters in one vector. More...
 
void setParameterVectorSelected (const std::vector< Eigen::VectorXd > &values, bool normalized=false)
 Set all the values of the selected parameters with a vector of vectors. More...
 

Protected Member Functions

void trainLocal (const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)
 Train a contextual DMP. More...
 
void checkTrainTrajectories (const std::vector< Trajectory > &trajectories)
 Check if several trajectories have the same duration and initial/final states. More...
 
- Protected Member Functions inherited from Dmp
FunctionApproximatorfunction_approximator (int i_dim) const
 Get a pointer to the function approximator for a certain dimension. More...
 
- Protected Member Functions inherited from DynamicalSystem
 DynamicalSystem (void)
 Default constructor. More...
 
void set_dim (int dim)
 Set the dimensionality of the dynamical system, i.e. More...
 

Protected Attributes

Eigen::MatrixXd task_parameters_
 The current task parameters.
 
std::vector< FunctionApproximator * > policy_parameter_function_goal_
 FunctionApproximators that relate task parameters the goal of the DMP.
 
FunctionApproximatorpolicy_parameter_function_duration_
 FunctionApproximator that relates task parameters the duration of the DMP.
 

Friends

class boost::serialization::access
 Give boost serialization access to private members. More...
 

Additional Inherited Members

- Public Types inherited from Dmp
enum  DmpType { IJSPEERT_2002_MOVEMENT, KULVICIUS_2012_JOINING, COUNTDOWN_2013 }
 Different types of DMPs that can be initialized. More...
 
enum  ForcingTermScaling { NO_SCALING, G_MINUS_Y0_SCALING, AMPLITUDE_SCALING }
 Different ways to scale the forcing term. More...
 
- Public Types inherited from DynamicalSystem
enum  IntegrationMethod { EULER, RUNGE_KUTTA }
 The possible integration methods that can be used. More...
 

Detailed Description

Implementation of Contextual Dynamical Movement Primitives.

Contextual Dmp extends a 'standard' Dmp by adapting to task parameters.

See [12], [7], [2], [6]

This is how a 'standard' Dmp would be integrated

VectorXd x, xd, x_updated;
dmp->integrateStart(x,xd);
for (int t=1; t<T; t++) {
dmp->integrateStep(dt,x,x_updated,xd);
x = x_updated;
}

A contextual Dmp is integrated as follows.

VectorXd x, xd, x_updated;
dmp->set_task_parameters(some_task_parameters);
dmp->integrateStart(x,xd);
for (int t=1; t<T; t++) {
dmp->integrateStep(dt,x,x_updated,xd);
x = x_updated;
}

Or, if the task parameters change over time.

VectorXd x, xd, x_updated;
dmp->integrateStart(x,xd);
for (int t=1; t<T; t++) {
dmp->set_task_parameters(some_task_parameters);
dmp->integrateStep(dt,x,x_updated,xd);
x = x_updated;
}

Definition at line 79 of file DmpContextual.hpp.

Constructor & Destructor Documentation

DmpContextual ( int  n_dims_dmp,
std::vector< FunctionApproximator * >  function_approximators,
DmpType  dmp_type 
)

Initialization constructor for Contextual DMPs of known dimensionality, but with unknown initial and attractor states.

Initializes the DMP with default dynamical systems.

Parameters
n_dims_dmpDimensionality of the DMP
function_approximatorsFunction approximators for the forcing term
dmp_typeThe type of DMP, see Dmp::DmpType

Definition at line 39 of file DmpContextual.cpp.

40 : Dmp(n_dims_dmp, function_approximators, dmp_type)
41 {
42  policy_parameter_function_goal_ = std::vector<FunctionApproximator*>(0);
44 }
std::vector< FunctionApproximator * > policy_parameter_function_goal_
FunctionApproximators that relate task parameters the goal of the DMP.
FunctionApproximator * policy_parameter_function_duration_
FunctionApproximator that relates task parameters the duration of the DMP.
Dmp(double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, std::vector< FunctionApproximator * > function_approximators, double alpha_spring_damper, DynamicalSystem *goal_system, DynamicalSystem *phase_system, DynamicalSystem *gating_system, ForcingTermScaling scaling=NO_SCALING)
Initialization constructor.
Definition: Dmp.cpp:85

Member Function Documentation

void set_task_parameters ( const Eigen::MatrixXd &  task_parameters)

Set the current task parameters.

Parameters
[in]task_parametersCurrent task parameters

Definition at line 140 of file DmpContextual.cpp.

141 {
142  assert(task_parameters_.cols()==task_parameters.cols());
143  task_parameters_ = task_parameters; // This will be used for the forcing term later
144 
145  // Compute new attractor state now, if necessary.
146  if (policy_parameter_function_goal_.size()>0)
147  {
148  // TODO: Check size of task_parameters
149  VectorXd goal(dim_orig());
150  MatrixXd outputs;
151  for (int i_dim=0; i_dim<dim_orig(); i_dim++)
152  {
153  policy_parameter_function_goal_[i_dim]->predict(task_parameters,outputs);
154  goal(i_dim) = outputs(0,0);
155  }
156  set_attractor_state(goal);
157  }
158 
159  // Compute new duration now, if necessary.
161  {
162  // TODO: Check size of task_parameters
163  MatrixXd duration_as_matrix;
164  policy_parameter_function_duration_->predict(task_parameters,duration_as_matrix);
165  set_tau(duration_as_matrix(0,0));
166  }
167 
168 }
virtual void set_attractor_state(const Eigen::VectorXd &y_attr)
Accessor function for the attractor state of the system.
Definition: Dmp.cpp:873
int dim_orig(void) const
Get the dimensionality of the dynamical system, i.e.
virtual void set_tau(double tau)
Accessor function for the time constant.
Definition: Dmp.cpp:853
std::vector< FunctionApproximator * > policy_parameter_function_goal_
FunctionApproximators that relate task parameters the goal of the DMP.
FunctionApproximator * policy_parameter_function_duration_
FunctionApproximator that relates task parameters the duration of the DMP.
virtual void predict(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &outputs)=0
Query the function approximator to make a prediction.
Eigen::MatrixXd task_parameters_
The current task parameters.

Here is the call graph for this function:

void set_policy_parameter_function_goal ( FunctionApproximator function_approximator)

Set a function approximator to predict the goal from the task parameters.

Parameters
[in]function_approximatorThe function approximator.

Definition at line 46 of file DmpContextual.cpp.

47 {
48  // Make clones, one for each of the dimensions of the goal
49  policy_parameter_function_goal_ = vector<FunctionApproximator*>(dim_orig());
50  for (int dd=0; dd<dim_orig(); dd++)
51  {
53  }
54 }
int dim_orig(void) const
Get the dimensionality of the dynamical system, i.e.
std::vector< FunctionApproximator * > policy_parameter_function_goal_
FunctionApproximators that relate task parameters the goal of the DMP.
FunctionApproximator * function_approximator(int i_dim) const
Get a pointer to the function approximator for a certain dimension.
Definition: Dmp.hpp:345
virtual FunctionApproximator * clone(void) const =0
Return a pointer to a deep copy of the FunctionApproximator object.

Here is the call graph for this function:

void set_policy_parameter_function_duration ( FunctionApproximator function_approximator)

Set a function approximator to predict the duration from the task parameters.

Parameters
[in]function_approximatorThe function approximator.

Definition at line 56 of file DmpContextual.cpp.

57 {
58  // Output of this function approximator should always be 1D (duration is time is 1D)
60 
62 }
FunctionApproximator * policy_parameter_function_duration_
FunctionApproximator that relates task parameters the duration of the DMP.
int getExpectedOutputDim(void) const
The expected dimensionality of the output data.
FunctionApproximator * function_approximator(int i_dim) const
Get a pointer to the function approximator for a certain dimension.
Definition: Dmp.hpp:345
virtual FunctionApproximator * clone(void) const =0
Return a pointer to a deep copy of the FunctionApproximator object.

Here is the call graph for this function:

virtual void computeFunctionApproximatorOutput ( const Eigen::Ref< const Eigen::MatrixXd > &  phase_state,
Eigen::MatrixXd &  fa_output 
) const
pure virtual

Compute the outputs of the function approximators.

Parameters
[in]phase_stateThe phase states for which the outputs are computed.
[out]fa_outputThe outputs of the function approximators.

Reimplemented from Dmp.

Implemented in DmpContextualTwoStep, and DmpContextualOneStep.

void trainLocal ( const std::vector< Trajectory > &  trajectories,
const std::vector< Eigen::MatrixXd > &  task_parameters,
std::string  save_directory,
bool  overwrite 
)
protected

Train a contextual DMP.

All other train functions in this class directly or indirectly call this function. This function trains the function approximators for the policy parameter function for the goal and tau parameters. It then calls the train function in the subclasses (e.g. DmpContextualOneStep::train() or DmpContextualTwoStep::train() to train the forcing term.

Parameters
[in]trajectoriesThe set of trajectories
[in]task_parametersThe task parameters for each of the trajectories.
[in]save_directoryDirectory to which to save intermediate results.
[in]overwriteOverwrite existing files in the directory above

Definition at line 82 of file DmpContextual.cpp.

83 {
85  {
86  unsigned int n_demonstrations = trajectories.size();
87  assert(n_demonstrations==task_parameters.size());
88 
89  // Gather task parameters in a matrix
90  int n_task_parameters = task_parameters[0].cols();
91  MatrixXd inputs(n_demonstrations,n_task_parameters);
92  for (unsigned int i_demo=0; i_demo<n_demonstrations; i_demo++)
93  // Take the first row, i.e. at time_i = 0.
94  inputs.row(i_demo) = task_parameters[i_demo].row(0);
95 
97  {
98  // Gather goals (target values for approximation) in one matrix
99  MatrixXd targets(n_demonstrations,dim_orig());
100  for (unsigned int i_demo=0; i_demo<n_demonstrations; i_demo++)
101  targets.row(i_demo) = trajectories[i_demo].final_y();
102 
103  //cout << " inputs=" << inputs << endl;
104  //cout << " targets=" << targets << endl;
105  //cout << " targets.col(0)=" << targets.col(0) << endl;
106 
107  for (int i_dim=0; i_dim<dim_orig(); i_dim++)
108  {
109  string save_directory_cur;
110  if (!save_directory.empty())
111  save_directory_cur = save_directory + "/dim" + to_string(i_dim) + "_goal";
112 
113  policy_parameter_function_goal_[i_dim]->train(inputs,targets.col(i_dim),save_directory_cur,overwrite);
114  }
115  }
116 
118  {
119  // Gather durations (target values for approximation) in one matrix
120  VectorXd targets(n_demonstrations);
121  for (unsigned int i_demo=0; i_demo<n_demonstrations; i_demo++)
122  targets(i_demo) = trajectories[i_demo].duration();
123 
124  //cout << " inputs=" << inputs << endl;
125  //cout << " targets=" << targets << endl;
126 
127  string save_directory_cur;
128  if (!save_directory.empty())
129  save_directory_cur = save_directory + "/_duration";
130 
131  policy_parameter_function_duration_->train(inputs,targets,save_directory_cur,overwrite);
132  }
133 
134  }
135 
136  // Train the rest, i.e. the parameters for the forcing term.
137  train(trajectories, task_parameters, save_directory, overwrite);
138 }
int dim_orig(void) const
Get the dimensionality of the dynamical system, i.e.
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.
std::vector< FunctionApproximator * > policy_parameter_function_goal_
FunctionApproximators that relate task parameters the goal of the DMP.
FunctionApproximator * policy_parameter_function_duration_
FunctionApproximator that relates task parameters the duration of the DMP.
virtual void train(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful ...

Here is the call graph for this function:

virtual void train ( const std::vector< Trajectory > &  trajectories,
const std::vector< Eigen::MatrixXd > &  task_parameters,
std::string  save_directory,
bool  overwrite 
)
pure virtual

Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful for debugging, i.e.

if you want to save intermediate results to a directory

Parameters
[in]trajectoriesThe set of trajectories
[in]task_parametersThe task parameters for each of the trajectories.
[in]save_directoryDirectory to which to save intermediate results.
[in]overwriteOverwrite existing files in the directory above Overloads Dmp::train

Implemented in DmpContextualTwoStep, and DmpContextualOneStep.

void train ( const std::vector< Trajectory > &  trajectories,
const std::vector< Eigen::MatrixXd > &  task_parameters,
std::string  save_directory 
)

Train a contextual DMP with multiple trajectories.

Parameters
[in]trajectoriesA set of demonstrated trajectories
[in]task_parametersThe task_parameters for each trajectory. It is a std::vector, where each task parameter element corresponds to one Trajectory. Each element is a matrix of size n_time_steps x n_task_paramaters
[in]save_directoryDirectory to which to save intermediate results. Does not overwrite existing files.

Definition at line 68 of file DmpContextual.cpp.

69 {
70  bool overwrite = false;
71  train(trajectories, task_parameters, save_directory, overwrite);
72 }
virtual void train(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful ...

Here is the call graph for this function:

void train ( const std::vector< Trajectory > &  trajectories,
const std::vector< Eigen::MatrixXd > &  task_parameters 
)

Train a contextual DMP with multiple trajectories.

Parameters
[in]trajectoriesA set of demonstrated trajectories
[in]task_parametersThe task_parameters for each trajectory. It is a std::vector, where each task parameter element corresponds to one Trajectory. Each element is a matrix of size n_time_steps x n_task_paramaters

Definition at line 74 of file DmpContextual.cpp.

75 {
76  bool overwrite=false;
77  string save_directory("");
78  train(trajectories, task_parameters, save_directory, overwrite);
79 }
virtual void train(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful ...

Here is the call graph for this function:

void train ( const std::vector< Trajectory > &  trajectories,
std::string  save_directory,
bool  overwrite 
)

Train a contextual DMP with multiple trajectories.

Parameters
[in]trajectoriesA set of demonstrated trajectories, the task parameters are stored as miscellaneous variables in the trajectory, see also Trajectory::misc()
[in]save_directoryDirectory to which to save intermediate results
[in]overwriteOverwrite existing files in the directory above

Definition at line 170 of file DmpContextual.cpp.

171 {
172  vector<MatrixXd> task_parameters(trajectories.size());
173  for (unsigned int i_traj=0; i_traj<trajectories.size(); i_traj++)
174  {
175  task_parameters[i_traj] = trajectories[i_traj].misc();
176  assert(task_parameters[i_traj].cols()>0);
177  if (i_traj>0)
178  assert(task_parameters[i_traj].cols() == task_parameters[i_traj].cols());
179  }
180  trainLocal(trajectories, task_parameters, save_directory, overwrite);
181 }
void trainLocal(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)
Train a contextual DMP.

Here is the call graph for this function:

void train ( const std::vector< Trajectory > &  trajectories,
std::string  save_directory 
)

Train a contextual DMP with multiple trajectories.

Parameters
[in]trajectoriesA set of demonstrated trajectories, the task parameters are stored as miscellaneous variables in the trajectory, see also Trajectory::misc()
[in]save_directoryDirectory to which to save intermediate results. Does not overwrite existing files.

Definition at line 183 of file DmpContextual.cpp.

184 {
185  bool overwrite=false;
186  train(trajectories, save_directory, overwrite);
187 }
virtual void train(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful ...

Here is the call graph for this function:

void train ( const std::vector< Trajectory > &  trajectories)

Train a contextual DMP with multiple trajectories.

Parameters
[in]trajectoriesA set of demonstrated trajectories, the task parameters are stored as miscellaneous variables in the trajectory, see also Trajectory::misc()

Definition at line 189 of file DmpContextual.cpp.

190 {
191  bool overwrite=false;
192  string save_directory("");
193  train(trajectories, save_directory, overwrite);
194 }
virtual void train(const std::vector< Trajectory > &trajectories, const std::vector< Eigen::MatrixXd > &task_parameters, std::string save_directory, bool overwrite)=0
Train a contextual Dmp with a set of trajectories (and save results to file) This function is useful ...

Here is the call graph for this function:

void checkTrainTrajectories ( const std::vector< Trajectory > &  trajectories)
protected

Check if several trajectories have the same duration and initial/final states.

Parameters
[in]trajectoriesA set of trajectories

Definition at line 197 of file DmpContextual.cpp.

198 {
199  // Check if inputs are of the right size.
200  unsigned int n_demonstrations = trajectories.size();
201 
202  // Then check if the trajectories have the same duration and initial/final state
203  double first_duration = trajectories[0].duration();
204  VectorXd first_y_init = trajectories[0].initial_y();
205  VectorXd first_y_attr = trajectories[0].final_y();
206  for (unsigned int i_demo=1; i_demo<n_demonstrations; i_demo++)
207  {
208  // Difference in tau
209  if (fabs(first_duration-trajectories[i_demo].duration())>10e-4)
210  {
212  {
213  cerr << __FILE__ << ":" << __LINE__ << ":";
214  cerr << "WARNING: Duration of demonstrations differ (" << first_duration << "!=" << trajectories[i_demo].duration() << ")" << endl;
215  cerr << " See DmpContextual::set_policy_parameter_function_duration(...) on how to fix this. " << endl;
216  }
217  }
218 
219  // Difference between initial states
220  double sum_abs_diff = (first_y_init.array()-trajectories[i_demo].initial_y().array()).abs().sum();
221  if (sum_abs_diff>10e-7)
222  {
223  cerr << __FILE__ << ":" << __LINE__ << ":";
224  cerr << "WARNING: Initial states of demonstrations differ ( [" << first_y_init.transpose() << "] != [ " << trajectories[i_demo].initial_y().transpose() << "] )" << endl;
225  }
226 
227  // Difference between final states
228  sum_abs_diff = (first_y_attr.array()-trajectories[i_demo].final_y().array()).abs().sum();
229  if (sum_abs_diff>10e-7 && policy_parameter_function_goal_.size()==0)
230  {
231  cerr << __FILE__ << ":" << __LINE__ << ":";
232  cerr << "WARNING: Final states of demonstrations differ ( [" << first_y_attr.transpose() << "] != [ " << trajectories[i_demo].final_y().transpose() << "] )" << endl;
233  cerr << " See DmpContextual::set_policy_parameter_function_goal(...) on how to fix this. " << endl;
234  }
235 
236  }
237 }
std::vector< FunctionApproximator * > policy_parameter_function_goal_
FunctionApproximators that relate task parameters the goal of the DMP.
FunctionApproximator * policy_parameter_function_duration_
FunctionApproximator that relates task parameters the duration of the DMP.

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Give boost serialization access to private members.

Definition at line 190 of file DmpContextual.hpp.


The documentation for this class was generated from the following files: