DMP_BBO library
UnifiedModel.cpp
Go to the documentation of this file.
1 
24 #include <boost/serialization/export.hpp>
25 #include <boost/serialization/vector.hpp>
26 #include <boost/archive/text_iarchive.hpp>
27 #include <boost/archive/text_oarchive.hpp>
28 #include <boost/archive/xml_iarchive.hpp>
29 #include <boost/archive/xml_oarchive.hpp>
31 
34 
37 
41 
42 #include <iostream>
43 #include <fstream>
44 
45 #include <eigen3/Eigen/Core>
46 #include <eigen3/Eigen/SVD>
47 #include <eigen3/Eigen/LU>
48 
49 
50 using namespace std;
51 using namespace Eigen;
52 
53 namespace DmpBbo {
54 
55 UnifiedModel::UnifiedModel(const Eigen::MatrixXd& centers, const Eigen::MatrixXd& widths, const Eigen::VectorXd& weights, bool normalized_basis_functions, bool lines_pivot_at_max_activation)
56 {
57  int n_basis_functions = centers.rows();
58  int n_dims = centers.cols();
59 
60  assert(n_basis_functions==widths.rows());
61  assert(n_dims ==widths.cols());
62  assert(n_basis_functions==weights.size());
63 
64  centers_.resize(n_basis_functions);
65  covars_.resize(n_basis_functions);
66  slopes_.resize(n_basis_functions);
67  offsets_.resize(n_basis_functions);
68  priors_.resize(n_basis_functions);
69 
70  for (int i=0; i<n_basis_functions; i++)
71  {
72  centers_[i] = centers.row(i);
73  covars_[i] = widths.row(i).asDiagonal();
74  covars_[i] = covars_[i].array().square();
75  offsets_[i] = weights[i];
76 
77  slopes_[i] = VectorXd::Zero(n_dims);
78  priors_[i] = 1.0;
79  }
80 
81  normalized_basis_functions_ = normalized_basis_functions;
82  lines_pivot_at_max_activation_ = lines_pivot_at_max_activation;
83  slopes_as_angles_ = false;
84 
85  cosine_basis_functions_ = false;
86 
87  initializeAllValuesVectorSize();
88 };
89 
90 UnifiedModel::UnifiedModel(const Eigen::MatrixXd& centers, const Eigen::MatrixXd& widths, const Eigen::MatrixXd& slopes, const Eigen::VectorXd& offsets, bool normalized_basis_functions, bool lines_pivot_at_max_activation)
91 {
92  int n_basis_functions = centers.rows();
93 #ifndef NDEBUG // Variables below are only required for asserts; check for NDEBUG to avoid warnings.
94  int n_dims = centers.cols();
95 #endif
96 
97  assert(n_basis_functions==widths.rows());
98  assert(n_dims ==widths.cols());
99  assert(n_basis_functions==slopes.rows());
100  assert(n_dims ==slopes.cols());
101  assert(n_basis_functions==offsets.size());
102 
103  centers_.resize(n_basis_functions);
104  covars_.resize(n_basis_functions);
105  slopes_.resize(n_basis_functions);
106  offsets_.resize(n_basis_functions);
107  priors_.resize(n_basis_functions);
108 
109  for (int i=0; i<n_basis_functions; i++)
110  {
111  centers_[i] = centers.row(i);
112  covars_[i] = widths.row(i).asDiagonal();
113  covars_[i] = covars_[i].array().square();
114  slopes_[i] = slopes.row(i);
115  offsets_[i] = offsets[i];
116 
117  priors_[i] = 1.0;
118  }
119 
120  normalized_basis_functions_ = normalized_basis_functions;
121  lines_pivot_at_max_activation_ = lines_pivot_at_max_activation;
122  slopes_as_angles_ = false;
123 
124  cosine_basis_functions_ = false;
125 
126  initializeAllValuesVectorSize();
127 }
128 
129 
130 UnifiedModel::UnifiedModel(const Eigen::MatrixXd& angular_frequencies, const Eigen::VectorXd& phases, const Eigen::VectorXd& weights)
131 {
132  int n_basis_functions = angular_frequencies.rows();
133  int n_dims = angular_frequencies.cols();
134 
135  assert(n_basis_functions==phases.size());
136  assert(n_basis_functions==weights.size());
137 
138  centers_.resize(n_basis_functions); // phase
139  covars_.resize(n_basis_functions); // angular_frequencies
140  slopes_.resize(n_basis_functions);
141  offsets_.resize(n_basis_functions); // weights
142  priors_.resize(n_basis_functions);
143 
144  for (int i=0; i<n_basis_functions; i++)
145  {
146  centers_[i] = VectorXd(1);
147  centers_[i][0] = phases[i];
148 
149  covars_[i] = MatrixXd(1,n_dims);
150  covars_[i] = angular_frequencies.row(i);
151 
152  offsets_[i] = weights[i];
153 
154  slopes_[i] = VectorXd::Zero(n_dims);
155  priors_[i] = 1.0;
156  }
157 
158  // These aren't relevant for cosing basis functions
159  normalized_basis_functions_ = false;
160  lines_pivot_at_max_activation_ = false;
161  slopes_as_angles_ = false;
162 
163  cosine_basis_functions_ = true;
164 
165  initializeAllValuesVectorSize();
166 }
167 
168 UnifiedModel::UnifiedModel(
169  const std::vector<Eigen::VectorXd>& centers, // n_centers X n_dims
170  const std::vector<Eigen::MatrixXd>& covars, // n_centers X n_dims X n_dims
171  const std::vector<Eigen::VectorXd>& slopes, // n_centers X n_dims
172  const std::vector<double>& offsets, // n_centers X 1
173  const std::vector<double>& priors, // n_centers X 1
174  bool normalized_basis_functions,
175  bool lines_pivot_at_max_activation)
176 :
177  centers_(centers),
178  covars_(covars),
179  slopes_(slopes),
180  offsets_(offsets),
181  priors_(priors),
182  normalized_basis_functions_(normalized_basis_functions),
183  lines_pivot_at_max_activation_(lines_pivot_at_max_activation),
184  slopes_as_angles_(false)
185 {
186  cosine_basis_functions_ = false;
187 
188  initializeAllValuesVectorSize();
189 }
190 
191 void UnifiedModel::initializeAllValuesVectorSize(void)
192 {
193 
194  all_values_vector_size_ = 0;
195  int n_basis_functions = centers_.size();
196  if (n_basis_functions>0)
197  {
198  all_values_vector_size_ += centers_.size()*centers_[0].size();
199  all_values_vector_size_ += covars_.size() *covars_[0].cols();
200  all_values_vector_size_ += offsets_.size();
201  all_values_vector_size_ += slopes_.size() *slopes_[0].size();
202  all_values_vector_size_ += priors_.size();
203  }
204 }
205 
206 
207 
209  return new UnifiedModel(centers_,covars_,slopes_,offsets_,priors_,normalized_basis_functions_,lines_pivot_at_max_activation_);
210 }
211 
212 
213 void UnifiedModel::set_lines_pivot_at_max_activation(bool lines_pivot_at_max_activation)
214 {
215  // If no change, just return
216  if (lines_pivot_at_max_activation_ == lines_pivot_at_max_activation)
217  return;
218 
219  //cout << "________________" << endl;
220  //cout << centers_.transpose() << endl;
221  //cout << slopes_.transpose() << endl;
222  //cout << offsets_.transpose() << endl;
223  //cout << "centers_ = " << centers_.rows() << "X" << centers_.cols() << endl;
224  //cout << "slopes_ = " << slopes_.rows() << "X" << slopes_.cols() << endl;
225  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
226 
227  // If you pivot lines around the point when the basis function has maximum activation (i.e.
228  // at the center of the Gaussian), you must compute the new offset corresponding to this
229  // slope, and vice versa
230  int n_lines = centers_.size();
231  VectorXd ac(n_lines); // slopes*centers
232  for (int i_line=0; i_line<n_lines; i_line++)
233  {
234  ac[i_line] = slopes_[i_line].dot(centers_[i_line]);
235 
236  if (lines_pivot_at_max_activation)
237  {
238  // Representation was "y = ax + b", now it will be "y = a(x-c) + b^new"
239  // Since "y = ax + b" can be rewritten as "y = a(x-c) + (b+ac)", we know that "b^new = (ac+b)"
240  offsets_[i_line] = offsets_[i_line] + ac[i_line];
241  }
242  else
243  {
244  // Representation was "y = a(x-c) + b", now it will be "y = ax + b^new"
245  // Since "y = a(x-c) + b" can be rewritten as "y = ax + (b-ac)", we know that "b^new = (b-ac)"
246  offsets_[i_line] = offsets_[i_line] - ac[i_line];
247  }
248  }
249 
250  //cout << offsets_.transpose() << endl;
251  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
252 
253  lines_pivot_at_max_activation_ = lines_pivot_at_max_activation;
254 }
255 
256 void UnifiedModel::set_slopes_as_angles(bool slopes_as_angles)
257 {
258  slopes_as_angles_ = slopes_as_angles;
259  cerr << __FILE__ << ":" << __LINE__ << ":";
260  cerr << "Not implemented yet!!!" << endl;
261  slopes_as_angles_ = false;
262 }
263 
264 
265 
266 
267 void UnifiedModel::getLines(const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& lines) const
268 {
269  int n_time_steps = inputs.rows();
270 
271  //cout << "centers_ = " << centers_.rows() << "X" << centers_.cols() << endl;
272  //cout << "slopes_ = " << slopes_.rows() << "X" << slopes_.cols() << endl;
273  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
274  //cout << "inputs = " << inputs.rows() << "X" << inputs.cols() << endl;
275 
276  // Compute values along lines for each time step
277  // Line representation is "y = ax + b"
278  int n_lines = centers_.size();
279  lines.resize(n_time_steps,n_lines);
280  for (int i_line=0; i_line<n_lines; i_line++)
281  {
282  lines.col(i_line) = inputs*slopes_[i_line];
283  lines.col(i_line).array() += offsets_[i_line];
284 
285  if (lines_pivot_at_max_activation_)
286  {
287  // Line representation is "y = a(x-c) + b", which is "y = ax - ac + b"
288  // Therefore, we still have to subtract "ac"
289  double ac = slopes_[i_line].dot(centers_[i_line]);
290  lines.col(i_line).array() -= ac;
291  }
292  }
293  //cout << "lines = " << lines.rows() << "X" << lines.cols() << endl;
294 }
295 
296 void UnifiedModel::evaluate(const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& output) const
297 {
298 
299  MatrixXd lines;
300  getLines(inputs, lines);
301 
302  // Weight the values for each line with the normalized basis function activations
303  MatrixXd activations;
304  kernelActivations(inputs,activations);
305 
306  output = (lines.array()*activations.array()).rowwise().sum();
307 }
308 
309 /*
310 void UnifiedModel::kernelActivationsSymmetric(const MatrixXd& centers, const MatrixXd& widths, const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& kernel_activations)
311 {
312  cout << __FILE__ << ":" << __LINE__ << ":Here" << endl;
313  // Check and set sizes
314  // centers = n_basis_functions x n_dim
315  // widths = n_basis_functions x n_dim
316  // inputs = n_samples x n_dim
317  // activations = n_samples x n_basis_functions
318  int n_basis_functions = centers.rows();
319  int n_samples = inputs.rows();
320  int n_dims = centers.cols();
321  assert( (n_basis_functions==widths.rows()) & (n_dims==widths.cols()) );
322  assert( (n_samples==inputs.rows() ) & (n_dims==inputs.cols()) );
323  kernel_activations.resize(n_samples,n_basis_functions);
324 
325 
326  VectorXd center, width;
327  for (int bb=0; bb<n_basis_functions; bb++)
328  {
329  center = centers.row(bb);
330  width = widths.row(bb);
331 
332  // Here, we compute the values of a (unnormalized) multi-variate Gaussian:
333  // activation = exp(-0.5*(x-mu)*Sigma^-1*(x-mu))
334  // Because Sigma is diagonal in our case, this simplifies to
335  // activation = exp(\sum_d=1^D [-0.5*(x_d-mu_d)^2/Sigma_(d,d)])
336  // = \prod_d=1^D exp(-0.5*(x_d-mu_d)^2/Sigma_(d,d))
337  // This last product is what we compute below incrementally
338 
339  kernel_activations.col(bb).fill(1.0);
340  for (int i_dim=0; i_dim<n_dims; i_dim++)
341  {
342  kernel_activations.col(bb).array() *= exp(-0.5*pow(inputs.col(i_dim).array()-center[i_dim],2)/(width[i_dim]*width[i_dim])).array();
343  }
344  }
345 }
346 */
347 
348 void UnifiedModel::kernelActivations(const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& kernel_activations) const
349 {
350  if (caching_)
351  {
352  // If the cached inputs matrix has the same size as the one now requested
353  // (this also takes care of the case when inputs_cached is empty and need to be initialized)
354  if ( inputs.rows()==inputs_cached_.rows() && inputs.cols()==inputs_cached_.cols() )
355  {
356  // And they have the same values
357  if ( (inputs.array()==inputs_cached_.array()).all() )
358  {
359  // Then you can return the cached values
360  kernel_activations = kernel_activations_cached_;
361  return;
362  }
363  }
364  }
365 
366  // Cache could not be used, actually do the work
367  if (cosine_basis_functions_)
368  {
369  // centers_.resize(n_basis_functions); // phase
370  // covars_.resize(n_basis_functions); // angular_frequencies
371  // slopes_.resize(n_basis_functions);
372  // offsets_.resize(n_basis_functions); // weights
373  // priors_.resize(n_basis_functions);
374  BasisFunction::Cosine::activations(covars_,centers_,inputs,kernel_activations);
375  }
376  else
377  {
378  BasisFunction::Gaussian::activations(centers_,covars_,priors_,inputs,kernel_activations,normalized_basis_functions_);
379  }
380 
381  if (caching_)
382  {
383  // Cache the current results now.
384  inputs_cached_ = inputs;
385  kernel_activations_cached_ = kernel_activations;
386  }
387 
388 }
389 
390 template<class Archive>
391 void UnifiedModel::serialize(Archive & ar, const unsigned int version)
392 {
393  // serialize base class information
394  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Parameterizable);
395 
396  ar & BOOST_SERIALIZATION_NVP(centers_);
397  ar & BOOST_SERIALIZATION_NVP(covars_);
398  ar & BOOST_SERIALIZATION_NVP(slopes_);
399  ar & BOOST_SERIALIZATION_NVP(offsets_);
400  ar & BOOST_SERIALIZATION_NVP(priors_);
401  ar & BOOST_SERIALIZATION_NVP(normalized_basis_functions_);
402  ar & BOOST_SERIALIZATION_NVP(lines_pivot_at_max_activation_);
403  ar & BOOST_SERIALIZATION_NVP(slopes_as_angles_);
404  ar & BOOST_SERIALIZATION_NVP(all_values_vector_size_);
405  ar & BOOST_SERIALIZATION_NVP(caching_);
406 }
407 
408 string UnifiedModel::toString(void) const
409 {
411 }
412 
413 void UnifiedModel::getSelectableParameters(set<string>& selected_values_labels) const
414 {
415  selected_values_labels = set<string>();
416  selected_values_labels.insert("centers");
417  selected_values_labels.insert("widths");
418  selected_values_labels.insert("offsets");
419  selected_values_labels.insert("slopes");
420  selected_values_labels.insert("priors");
421 }
422 
423 
424 void UnifiedModel::getParameterVectorMask(const std::set<std::string> selected_values_labels, VectorXi& selected_mask) const
425 {
426 
427  selected_mask.resize(getParameterVectorAllSize());
428  selected_mask.fill(0);
429 
430  int offset = 0;
431  int size;
432 
433  // Centers
434  size = centers_.size()*centers_[0].size();
435  if (selected_values_labels.find("centers")!=selected_values_labels.end())
436  selected_mask.segment(offset,size).fill(1);
437  offset += size;
438 
439  // Widths
440  size = covars_.size()*covars_[0].cols();
441  if (selected_values_labels.find("widths")!=selected_values_labels.end())
442  selected_mask.segment(offset,size).fill(2);
443  offset += size;
444 
445  // Offsets
446  size = offsets_.size();
447  if (selected_values_labels.find("offsets")!=selected_values_labels.end())
448  selected_mask.segment(offset,size).fill(3);
449  offset += size;
450 
451  // Slopes
452  size = slopes_.size()*slopes_[0].size();
453  if (selected_values_labels.find("slopes")!=selected_values_labels.end())
454  selected_mask.segment(offset,size).fill(4);
455  offset += size;
456 
457  assert(offset == getParameterVectorAllSize());
458 }
459 
460 void UnifiedModel::getParameterVectorAll(VectorXd& values) const
461 {
462  values.resize(getParameterVectorAllSize());
463  int offset = 0;
464  int n_basis_functions = centers_.size();
465  int n_dims = getExpectedInputDim();
466 
467  for (int i_bfs=0; i_bfs<n_basis_functions; i_bfs++)
468  {
469  values.segment(offset,n_dims) = centers_[i_bfs]; offset += n_dims;
470  values.segment(offset,n_dims) = covars_[i_bfs].diagonal(); offset += n_dims;
471  values.segment(offset,n_dims) = slopes_[i_bfs]; offset += n_dims;
472  values[offset] = offsets_[i_bfs]; offset += 1;
473  values[offset] = priors_[i_bfs]; offset += 1;
474  }
475 
476  /*
477  Dead code. But kept in for reference in case slopes_as_angles_ will be implemented
478  VectorXd cur_slopes;
479  for (int i_dim=0; i_dim<slopes_.cols(); i_dim++)
480  {
481  cur_slopes = slopes_.col(i_dim);
482  if (slopes_as_angles_)
483  {
484  // cur_slopes is a slope, but the values vector expects the angle with the x-axis. Do the
485  // conversion here.
486  for (int ii=0; ii<cur_slopes.size(); ii++)
487  cur_slopes[ii] = atan2(cur_slopes[ii],1.0);
488  }
489 
490  values.segment(offset,slopes_.rows()) = cur_slopes;
491  offset += slopes_.rows();
492  }
493  */
494 
495  assert(offset == getParameterVectorAllSize());
496 };
497 
498 void UnifiedModel::setParameterVectorAll(const VectorXd& values) {
499 
500  if (all_values_vector_size_ != values.size())
501  {
502  cerr << __FILE__ << ":" << __LINE__ << ": values is of wrong size." << endl;
503  return;
504  }
505 
506  int offset = 0;
507  int n_basis_functions = centers_.size();
508  int n_dims = getExpectedInputDim();
509 
510  for (int i_bfs=0; i_bfs<n_basis_functions; i_bfs++)
511  {
512  VectorXd cur_center = values.segment(offset,n_dims);
513  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
514  // because this function will return different values for different centers
515  if ( !(centers_[i_bfs].array() == cur_center.array()).all() )
516  clearCache();
517 
518  centers_[i_bfs] = values.segment(offset,n_dims) ; offset += n_dims;
519 
520  VectorXd cur_width = values.segment(offset,n_dims);
521  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
522  // because this function will return different values for different centers
523  if ( !(covars_[i_bfs].diagonal().array() == cur_width.array()).all() )
524  clearCache();
525 
526  covars_[i_bfs].diagonal() = values.segment(offset,n_dims) ; offset += n_dims;
527 
528 
529  // Cache must not be cleared, because normalizedKernelActivations() returns the same values.
530  slopes_[i_bfs] = values.segment(offset,n_dims) ; offset += n_dims;
531  offsets_[i_bfs] = values[offset] ; offset += 1;
532  priors_[i_bfs] = values[offset] ; offset += 1;
533  }
534 
535  /*
536  int offset = 0;
537  int size = centers_.rows();
538  int n_dims = centers_.cols();
539  for (int i_dim=0; i_dim<n_dims; i_dim++)
540  {
541  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
542  // because this function will return different values for different centers
543  if ( !(centers_.col(i_dim).array() == values.segment(offset,size).array()).all() )
544  clearCache();
545 
546  centers_.col(i_dim) = values.segment(offset,size);
547  offset += size;
548  }
549  for (int i_dim=0; i_dim<n_dims; i_dim++)
550  {
551  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
552  // because this function will return different values for different centers
553  if ( !(covars_.col(i_dim).array() == values.segment(offset,size).array()).all() )
554  clearCache();
555 
556  covars_.col(i_dim) = values.segment(offset,size);
557  offset += size;
558  }
559 
560  offsets_ = values.segment(offset,size);
561  offset += size;
562  // Cache must not be cleared, because normalizedKernelActivations() returns the same values.
563 
564  MatrixXd old_slopes = slopes_;
565  for (int i_dim=0; i_dim<n_dims; i_dim++)
566  {
567  slopes_.col(i_dim) = values.segment(offset,size);
568  offset += size;
569  // Cache must not be cleared, because normalizedKernelActivations() returns the same values.
570  }
571 */
572  assert(offset == getParameterVectorAllSize());
573 };
574 
575 bool UnifiedModel::saveGridData(const VectorXd& min, const VectorXd& max, const VectorXi& n_samples_per_dim, string save_directory, bool overwrite) const
576 {
577  if (save_directory.empty())
578  return true;
579 
580 #ifndef NDEBUG // Variables below are only required for asserts; check for NDEBUG to avoid warnings.
581  int n_dims = min.size();
582  assert(n_dims==max.size());
583  assert(n_dims==n_samples_per_dim.size());
584 #endif
585 
586  MatrixXd inputs;
587  FunctionApproximator::generateInputsGrid(min, max, n_samples_per_dim, inputs);
588 
589  MatrixXd lines;
590  getLines(inputs, lines);
591 
592  MatrixXd activations;
593  if (cosine_basis_functions_)
594  {
595  BasisFunction::Cosine::activations(covars_,centers_,inputs,activations);
596  }
597  else
598  {
599  BasisFunction::Gaussian::activations(centers_,covars_,priors_,inputs,activations,normalized_basis_functions_);
600  if (normalized_basis_functions_)
601  {
602  MatrixXd unnormalized_activations;
603  BasisFunction::Gaussian::activations(centers_,covars_,priors_,inputs,unnormalized_activations,false);
604  saveMatrix(save_directory,"activations_unnormalized_grid.txt",unnormalized_activations,overwrite);
605  }
606  }
607 
608  MatrixXd predictions;
609  evaluate(inputs,predictions);
610 
611  saveMatrix(save_directory,"n_samples_per_dim.txt",n_samples_per_dim,overwrite);
612  saveMatrix(save_directory,"inputs_grid.txt",inputs,overwrite);
613  saveMatrix(save_directory,"lines_grid.txt",lines,overwrite);
614  saveMatrix(save_directory,"activations_grid.txt",activations,overwrite);
615  saveMatrix(save_directory,"predictions_grid.txt",predictions,overwrite);
616 
617  return true;
618 
619 }
620 
621 void UnifiedModel::setParameterVectorModifierPrivate(std::string modifier, bool new_value)
622 {
623  if (modifier.compare("lines_pivot_at_max_activation")==0)
625 
626  if (modifier.compare("slopes_as_angles")==0)
627  set_slopes_as_angles(new_value);
628 
629 }
630 
631 }
UnifiedModel class header file.
Header file for input/output of Eigen matrices to ASCII files.
void getParameterVectorMask(const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
Get a mask for selecting parameters.
FunctionApproximator class header file.
void setParameterVectorModifierPrivate(std::string modifier, bool new_value)
Turn certain modifiers on or off, see Parameterizable::setParameterVectorModifier().
std::string toString(void) const
Returns a string representation of the object.
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...
void getLines(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &lines) const
Get the output of each linear model (unweighted) for the given inputs.
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&#39;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.
void set_slopes_as_angles(bool slopes_as_angles)
Whether to return slopes as angles or slopes in UnifiedModel::getParameterVectorAll() ...
void set_lines_pivot_at_max_activation(bool lines_pivot_at_max_activation)
Set whether the offsets should be adapted so that the line segments pivot around the mode of the basi...
Class for providing access to a model&#39;s parameters as a vector.
bool saveMatrix(std::string filename, Eigen::Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime > matrix, bool overwrite=false)
Save an Eigen matrix to an ASCII file.
BasisFunction header file.
void kernelActivations(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &kernel_activations) const
Get the kernel activations for given inputs.
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.
void getParameterVectorAll(Eigen::VectorXd &all_values) const
Return a vector that returns all available parameter values.
The unified model, which can be used to represent the model of all other function approximators...
BOOST_CLASS_EXPORT_IMPLEMENT(DmpBbo::UnifiedModel)
For boost::serialization.
void getSelectableParameters(std::set< std::string > &selected_values_labels) const
Return all the names of the parameter types that can be selected.
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...
UnifiedModel * clone(void) const
Return a pointer to a deep copy of the object.
void evaluate(const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &output) const
Compute the sum of the locally weighted lines.
Header file to generate strings from boost serialized files.
void setParameterVectorAll(const Eigen::VectorXd &values)
Set all available parameter values with one vector.
int getExpectedInputDim(void) const
The expected dimensionality of the input data.
Header file for serialization of Eigen matrices.