DMP_BBO library
Public Member Functions | Protected Member Functions | Friends | List of all members

Model parameters for the Locally Weighted Regression (LWR) function approximator. More...

#include <ModelParametersLWR.hpp>

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

Public Member Functions

 ModelParametersLWR (const Eigen::MatrixXd &centers, const Eigen::MatrixXd &widths, const Eigen::MatrixXd &slopes, const Eigen::MatrixXd &offsets, bool asymmetric_kernels=false, bool lines_pivot_at_max_activation=false)
 Constructor for the model parameters of the LWPR function approximator. More...
 
std::string toString (void) const
 Returns a string representation of the object. More...
 
ModelParametersclone (void) const
 Return a pointer to a deep copy of the ModelParameters object. More...
 
int getExpectedInputDim (void) const
 The expected dimensionality of the input data. More...
 
void unnormalizedKernelActivations (const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &kernel_activations) const
 Get the unnormalized kernel activations for given inputs. More...
 
void kernelActivations (const Eigen::Ref< const Eigen::MatrixXd > &inputs, Eigen::MatrixXd &kernel_activations) const
 Get the normalized kernel activations for given inputs. More...
 
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. More...
 
void setParameterVectorModifierPrivate (std::string modifier, bool new_value)
 Turn certain modifiers on or off, see Parameterizable::setParameterVectorModifier(). More...
 
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 basis function, rather than the intersection with the y-axis. More...
 
void set_slopes_as_angles (bool slopes_as_angles)
 Whether to return slopes as angles or slopes in ModelParametersLWR::getParameterVectorAll() More...
 
void getSelectableParameters (std::set< std::string > &selected_values_labels) const
 Return all the names of the parameter types that can be selected. More...
 
void getParameterVectorMask (const std::set< std::string > selected_values_labels, Eigen::VectorXi &selected_mask) const
 Get a mask for selecting parameters. More...
 
void getParameterVectorAll (Eigen::VectorXd &all_values) const
 Return a vector that returns all available parameter values. More...
 
int getParameterVectorAllSize (void) const
 Get the size of the parameter values vector when it contains all available parameter values. More...
 
unsigned int getNumberOfBasisFunctions () const
 Get the number of basis functions in this model. More...
 
UnifiedModeltoUnifiedModel (void) const
 Convert these model parameters to unified model parameters. More...
 
void set_caching (bool caching)
 Turn caching for the function normalizedKernelActivations() on or off. More...
 
- Public Member Functions inherited from ModelParameters
virtual int getExpectedOutputDim (void) const
 The expected dimensionality of the output data. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize class data members to boost archive. 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...
 
virtual 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...
 
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 setParameterVectorAll (const Eigen::VectorXd &values)
 Set all available parameter values with one vector. More...
 

Friends

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

Detailed Description

Model parameters for the Locally Weighted Regression (LWR) function approximator.

Definition at line 40 of file ModelParametersLWR.hpp.

Constructor & Destructor Documentation

ModelParametersLWR ( const Eigen::MatrixXd &  centers,
const Eigen::MatrixXd &  widths,
const Eigen::MatrixXd &  slopes,
const Eigen::MatrixXd &  offsets,
bool  asymmetric_kernels = false,
bool  lines_pivot_at_max_activation = false 
)

Constructor for the model parameters of the LWPR function approximator.

Parameters
[in]centersCenters of the basis functions
[in]widthsWidths of the basis functions.
[in]slopesSlopes of the line segments.
[in]offsetsOffsets of the line segments, i.e. the value of the line segment at its intersection with the y-axis.
[in]asymmetric_kernelsWhether to use asymmetric kernels or not, cf MetaParametersLWR::asymmetric_kernels()
[in]lines_pivot_at_max_activationWhether line models should pivot at x=0 (false), or at the center of the kernel (x=x_c)

Definition at line 54 of file ModelParametersLWR.cpp.

55 :
56  centers_(centers),
57  widths_(widths),
58  slopes_(slopes),
59  offsets_(offsets),
60  asymmetric_kernels_(asymmetric_kernels),
61  lines_pivot_at_max_activation_(lines_pivot_at_max_activation),
62  slopes_as_angles_(false),
63  caching_(false)
64 {
65 #ifndef NDEBUG // Variables below are only required for asserts; check for NDEBUG to avoid warnings.
66  int n_basis_functions = centers.rows();
67  int n_dims = centers.cols();
68 #endif
69  assert(n_basis_functions==widths_.rows());
70  assert(n_dims ==widths_.cols());
71  assert(n_basis_functions==slopes_.rows());
72  assert(n_dims ==slopes_.cols());
73  assert(n_basis_functions==offsets_.rows());
74  assert(1 ==offsets_.cols());
75 
76  all_values_vector_size_ = 0;
77  all_values_vector_size_ += centers_.rows()*centers_.cols();
78  all_values_vector_size_ += widths_.rows() *widths_.cols();
79  all_values_vector_size_ += offsets_.rows()*offsets_.cols();
80  all_values_vector_size_ += slopes_.rows() *slopes_.cols();
81 
82 };

Member Function Documentation

string toString ( void  ) const
virtual

Returns a string representation of the object.

Returns
A string representation of the object.

Implements ModelParameters.

Definition at line 308 of file ModelParametersLWR.cpp.

309 {
310  RETURN_STRING_FROM_BOOST_SERIALIZATION_XML("ModelParametersLWR");
311 }
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.
ModelParameters * clone ( void  ) const
virtual

Return a pointer to a deep copy of the ModelParameters object.

Returns
Pointer to a deep copy

Implements ModelParameters.

Definition at line 84 of file ModelParametersLWR.cpp.

84  {
85  return new ModelParametersLWR(centers_,widths_,slopes_,offsets_,asymmetric_kernels_,lines_pivot_at_max_activation_);
86 }
ModelParametersLWR(const Eigen::MatrixXd &centers, const Eigen::MatrixXd &widths, const Eigen::MatrixXd &slopes, const Eigen::MatrixXd &offsets, bool asymmetric_kernels=false, bool lines_pivot_at_max_activation=false)
Constructor for the model parameters of the LWPR function approximator.
int getExpectedInputDim ( void  ) const
inlinevirtual

The expected dimensionality of the input data.

Returns
Expected dimensionality of the input data

Implements ModelParameters.

Definition at line 59 of file ModelParametersLWR.hpp.

59  {
60  return centers_.cols();
61  };

Here is the call graph for this function:

void unnormalizedKernelActivations ( const Eigen::Ref< const Eigen::MatrixXd > &  inputs,
Eigen::MatrixXd &  kernel_activations 
) const

Get the unnormalized kernel activations for given inputs.

Parameters
[in]inputsThe input data (size: n_samples X n_dims)
[out]kernel_activationsThe kernel activations, computed for each of the samples in the input data (size: n_samples X n_basis_functions)

Definition at line 88 of file ModelParametersLWR.cpp.

89 {
90  ENTERING_REAL_TIME_CRITICAL_CODE
91  bool normalized_basis_functions=false;
92  BasisFunction::Gaussian::activations(centers_,widths_,inputs,kernel_activations,
93  normalized_basis_functions,asymmetric_kernels_);
94  EXITING_REAL_TIME_CRITICAL_CODE
95 }
void kernelActivations ( const Eigen::Ref< const Eigen::MatrixXd > &  inputs,
Eigen::MatrixXd &  kernel_activations 
) const

Get the normalized kernel activations for given inputs.

Parameters
[in]inputsThe input data (size: n_samples X n_dims)
[out]kernel_activationsThe normalized kernel activations, computed for each of the sampels in the input data (size: n_samples X n_basis_functions)

Definition at line 97 of file ModelParametersLWR.cpp.

98 {
99  if (caching_)
100  {
101  // If the cached inputs matrix has the same size as the one now requested
102  // (this also takes care of the case when inputs_cached is empty and need to be initialized)
103  if ( inputs.rows()==inputs_cached_.rows() && inputs.cols()==inputs_cached_.cols() )
104  {
105  // And they have the same values
106  if ( (inputs.array()==inputs_cached_.array()).all() )
107  {
108  // Then you can return the cached values
109  kernel_activations = kernel_activations_cached_;
110  return;
111  }
112  }
113  }
114 
115  ENTERING_REAL_TIME_CRITICAL_CODE
116 
117  // Cache could not be used, actually do the work
118  bool normalize_activations = true;
119  BasisFunction::Gaussian::activations(centers_,widths_,inputs,kernel_activations,normalize_activations,asymmetric_kernels_);
120 
121  EXITING_REAL_TIME_CRITICAL_CODE
122 
123  if (caching_)
124  {
125  // Cache the current results now.
126  inputs_cached_ = inputs;
127  kernel_activations_cached_ = kernel_activations;
128  }
129 
130 }
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.

Parameters
[in]inputsThe inputs for which to compute the output of the lines models (size: n_samples X n_input_dims)
[out]linesThe output of the linear models (size: n_samples X n_basis_functions)

If "lines" is passed as a Matrix of correct size (n_samples X n_basis_functions), this function will not allocate any memory, and is real-time.

Definition at line 216 of file ModelParametersLWR.cpp.

217 {
218  ENTERING_REAL_TIME_CRITICAL_CODE
219 
220  //cout << endl << "========================" << endl;
221  //cout << "lines = " << lines.rows() << "X" << lines.cols() << endl;
222  //cout << "centers_ = " << centers_.rows() << "X" << centers_.cols() << endl;
223  //cout << "slopes_ = " << slopes_.rows() << "X" << slopes_.cols() << endl;
224  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
225  //cout << "inputs = " << inputs.rows() << "X" << inputs.cols() << endl;
226 
227  int n_time_steps = inputs.rows();
228  int n_lines = centers_.rows();
229  lines.resize(n_time_steps,n_lines);
230  //cout << "lines = " << lines.rows() << "X" << lines.cols() << endl;
231 
232 
233  // Compute values along lines for each time step
234  // Line representation is "y = ax + b"
235  for (int i_line=0; i_line<n_lines; i_line++)
236  {
237  lines.col(i_line).noalias() = inputs*slopes_.row(i_line).transpose();
238  lines.col(i_line).array() += offsets_(i_line);
239 
240  if (lines_pivot_at_max_activation_)
241  {
242  // Line representation is "y = a(x-c) + b", which is "y = ax - ac + b"
243  // Therefore, we still have to subtract "ac"
244  double ac = slopes_.row(i_line).dot(centers_.row(i_line));
245  lines.col(i_line).array() -= ac;
246  }
247  }
248 
249  EXITING_REAL_TIME_CRITICAL_CODE
250 }
void setParameterVectorModifierPrivate ( std::string  modifier,
bool  new_value 
)
virtual

Turn certain modifiers on or off, see Parameterizable::setParameterVectorModifier().

Parameterizable::setParameterVectorModifierPrivate(), This function may (but must not be) overridden by subclasses of Parameterizable, depending on whether the subclass has modifiers (or not)

Parameters
[in]modifierThe name of the modifier
[in]new_valueWhether to turn the modifier on (true) or off (false)

Reimplemented from Parameterizable.

Definition at line 445 of file ModelParametersLWR.cpp.

446 {
447  if (modifier.compare("lines_pivot_at_max_activation")==0)
449 
450  if (modifier.compare("slopes_as_angles")==0)
451  set_slopes_as_angles(new_value);
452 
453 }
void set_slopes_as_angles(bool slopes_as_angles)
Whether to return slopes as angles or slopes in ModelParametersLWR::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...

Here is the call graph for this function:

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 basis function, rather than the intersection with the y-axis.

Parameters
[in]lines_pivot_at_max_activationWhether to pivot around the mode or not.

Definition at line 132 of file ModelParametersLWR.cpp.

133 {
134  // If no change, just return
135  if (lines_pivot_at_max_activation_ == lines_pivot_at_max_activation)
136  return;
137 
138  //cout << "________________" << endl;
139  //cout << centers_.transpose() << endl;
140  //cout << slopes_.transpose() << endl;
141  //cout << offsets_.transpose() << endl;
142  //cout << "centers_ = " << centers_.rows() << "X" << centers_.cols() << endl;
143  //cout << "slopes_ = " << slopes_.rows() << "X" << slopes_.cols() << endl;
144  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
145 
146  // If you pivot lines around the point when the basis function has maximum activation (i.e.
147  // at the center of the Gaussian), you must compute the new offset corresponding to this
148  // slope, and vice versa
149  int n_lines = centers_.rows();
150  VectorXd ac(n_lines); // slopes*centers
151  for (int i_line=0; i_line<n_lines; i_line++)
152  {
153  ac[i_line] = slopes_.row(i_line) * centers_.row(i_line).transpose();
154  }
155 
156  if (lines_pivot_at_max_activation)
157  {
158  // Representation was "y = ax + b", now it will be "y = a(x-c) + b^new"
159  // Since "y = ax + b" can be rewritten as "y = a(x-c) + (b+ac)", we know that "b^new = (ac+b)"
160  offsets_ = offsets_ + ac;
161  }
162  else
163  {
164  // Representation was "y = a(x-c) + b", now it will be "y = ax + b^new"
165  // Since "y = a(x-c) + b" can be rewritten as "y = ax + (b-ac)", we know that "b^new = (b-ac)"
166  offsets_ = offsets_ - ac;
167  }
168  // Remark, the above could have been done as a one-liner, but I prefer the more legible version.
169 
170  //cout << offsets_.transpose() << endl;
171  //cout << "offsets_ = " << offsets_.rows() << "X" << offsets_.cols() << endl;
172 
173  lines_pivot_at_max_activation_ = lines_pivot_at_max_activation;
174 }
void set_slopes_as_angles ( bool  slopes_as_angles)

Whether to return slopes as angles or slopes in ModelParametersLWR::getParameterVectorAll()

Parameters
[in]slopes_as_anglesWhether to return as slopes (true) or angles (false)
Todo:
Implement and document

Definition at line 176 of file ModelParametersLWR.cpp.

177 {
178  slopes_as_angles_ = slopes_as_angles;
179  cerr << __FILE__ << ":" << __LINE__ << ":";
180  cerr << "Not implemented yet!!!" << endl;
181  slopes_as_angles_ = false;
182 }
void getSelectableParameters ( std::set< std::string > &  selected_values_labels) const
virtual

Return all the names of the parameter types that can be selected.

Parameters
[out]selected_values_labelsNames of the parameter types that can be selected

Implements Parameterizable.

Definition at line 313 of file ModelParametersLWR.cpp.

314 {
315  selected_values_labels = set<string>();
316  selected_values_labels.insert("centers");
317  selected_values_labels.insert("widths");
318  selected_values_labels.insert("offsets");
319  selected_values_labels.insert("slopes");
320 }
void getParameterVectorMask ( const std::set< std::string >  selected_values_labels,
Eigen::VectorXi &  selected_mask 
) const
virtual

Get a mask for selecting parameters.

Parameters
[in]selected_values_labelsLabels of the selected parameter values
[out]selected_maskA mask indicating indices of selected parameters. 0 indicates not selected, >0 indicates selected.

For instance, if the parameters consists of centers, widths and slopes the parameter values vector will be something like

    centers     widths    slopes
[ 100 110 120 10 10 10 0.4 0.7 0.4 ]

In this case, if selected_values_labels contains "centers" and "slopes", the mask will be:

    centers     widths    slopes
[   1   1   1  0  0  0   3   3   3 ]

The '0' indicates that these parameters are not selected. The other ones have different numbers so that they may be discerned from one another (as required in Parameterizable::getParameterVectorSelectedMinMax for instance.

Implements Parameterizable.

Definition at line 323 of file ModelParametersLWR.cpp.

324 {
325 
326  selected_mask.resize(getParameterVectorAllSize());
327  selected_mask.fill(0);
328 
329  int offset = 0;
330  int size;
331 
332  // Centers
333  size = centers_.rows()*centers_.cols();
334  if (selected_values_labels.find("centers")!=selected_values_labels.end())
335  selected_mask.segment(offset,size).fill(1);
336  offset += size;
337 
338  // Widths
339  size = widths_.rows()*widths_.cols();
340  if (selected_values_labels.find("widths")!=selected_values_labels.end())
341  selected_mask.segment(offset,size).fill(2);
342  offset += size;
343 
344  // Offsets
345  size = offsets_.rows()*offsets_.cols();
346  if (selected_values_labels.find("offsets")!=selected_values_labels.end())
347  selected_mask.segment(offset,size).fill(3);
348  offset += size;
349 
350  // Slopes
351  size = slopes_.rows()*slopes_.cols();
352  if (selected_values_labels.find("slopes")!=selected_values_labels.end())
353  selected_mask.segment(offset,size).fill(4);
354  offset += size;
355 
356  assert(offset == getParameterVectorAllSize());
357 }
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...

Here is the call graph for this function:

void getParameterVectorAll ( Eigen::VectorXd &  values) const
virtual

Return a vector that returns all available parameter values.

Parameters
[out]valuesAll available parameter values in one vector.
Remarks
Contrast this with Parameterizable::getParameterVectorSelected, which return only the SELECTED parameter values. Selecting parameters is done with Parameterizable::setSelectedParameters

Implements Parameterizable.

Definition at line 359 of file ModelParametersLWR.cpp.

360 {
361  values.resize(getParameterVectorAllSize());
362  int offset = 0;
363 
364  for (int i_dim=0; i_dim<centers_.cols(); i_dim++)
365  {
366  values.segment(offset,centers_.rows()) = centers_.col(i_dim);
367  offset += centers_.rows();
368  }
369 
370  for (int i_dim=0; i_dim<widths_.cols(); i_dim++)
371  {
372  values.segment(offset,widths_.rows()) = widths_.col(i_dim);
373  offset += widths_.rows();
374  }
375 
376  values.segment(offset,offsets_.rows()) = offsets_;
377  offset += offsets_.rows();
378 
379  VectorXd cur_slopes;
380  for (int i_dim=0; i_dim<slopes_.cols(); i_dim++)
381  {
382  cur_slopes = slopes_.col(i_dim);
383  if (slopes_as_angles_)
384  {
385  // cur_slopes is a slope, but the values vector expects the angle with the x-axis. Do the
386  // conversion here.
387  for (int ii=0; ii<cur_slopes.size(); ii++)
388  cur_slopes[ii] = atan2(cur_slopes[ii],1.0);
389  }
390 
391  values.segment(offset,slopes_.rows()) = cur_slopes;
392  offset += slopes_.rows();
393  }
394 
395  assert(offset == getParameterVectorAllSize());
396 };
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...

Here is the call graph for this function:

int getParameterVectorAllSize ( void  ) const
inlinevirtual

Get the size of the parameter values vector when it contains all available parameter values.

Returns
The size of the parameter vector

For instance, if the parameters consists of centers, widths and slopes the parameter values vector will be something like

    centers     widths    slopes
[ 100 110 120 10 10 10 0.4 0.7 0.4 ]

then getParameterVectorAllSize() will return 9

Implements Parameterizable.

Definition at line 102 of file ModelParametersLWR.hpp.

103  {
104  return all_values_vector_size_;
105  }
unsigned int getNumberOfBasisFunctions ( ) const
inline

Get the number of basis functions in this model.

Returns
The number of basis functions.

Definition at line 110 of file ModelParametersLWR.hpp.

111  {
112  return centers_.rows();
113  }

Here is the call graph for this function:

UnifiedModel * toUnifiedModel ( void  ) const
virtual

Convert these model parameters to unified model parameters.

Returns
Unified model parameter representation (NULL if not implemented for a particular subclass)

Implements ModelParameters.

Definition at line 455 of file ModelParametersLWR.cpp.

456 {
457 
458  // LWR uses normalized basis functions
459  bool normalized_basis_functions = true;
460  return new UnifiedModel(centers_, widths_, slopes_, offsets_, normalized_basis_functions);
461 
462 }
void setParameterVectorAll ( const Eigen::VectorXd &  values)
protectedvirtual

Set all available parameter values with one vector.

Parameters
[in]valuesAll available parameter values in one vector.
Remarks
Contrast this with Parameterizable::setParameterVectorSelected, which sets only the SELECTED parameter values. Selecting parameters is done with Parameterizable::setSelectedParameters

Implements Parameterizable.

Definition at line 398 of file ModelParametersLWR.cpp.

398  {
399 
400  if (all_values_vector_size_ != values.size())
401  {
402  cerr << __FILE__ << ":" << __LINE__ << ": values is of wrong size." << endl;
403  return;
404  }
405 
406  int offset = 0;
407  int size = centers_.rows();
408  int n_dims = centers_.cols();
409  for (int i_dim=0; i_dim<n_dims; i_dim++)
410  {
411  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
412  // because this function will return different values for different centers
413  if ( !(centers_.col(i_dim).array() == values.segment(offset,size).array()).all() )
414  clearCache();
415 
416  centers_.col(i_dim) = values.segment(offset,size);
417  offset += size;
418  }
419  for (int i_dim=0; i_dim<n_dims; i_dim++)
420  {
421  // If the centers change, the cache for normalizedKernelActivations() must be cleared,
422  // because this function will return different values for different centers
423  if ( !(widths_.col(i_dim).array() == values.segment(offset,size).array()).all() )
424  clearCache();
425 
426  widths_.col(i_dim) = values.segment(offset,size);
427  offset += size;
428  }
429 
430  offsets_ = values.segment(offset,size);
431  offset += size;
432  // Cache must not be cleared, because normalizedKernelActivations() returns the same values.
433 
434  MatrixXd old_slopes = slopes_;
435  for (int i_dim=0; i_dim<n_dims; i_dim++)
436  {
437  slopes_.col(i_dim) = values.segment(offset,size);
438  offset += size;
439  // Cache must not be cleared, because normalizedKernelActivations() returns the same values.
440  }
441 
442  assert(offset == getParameterVectorAllSize());
443 };
int getParameterVectorAllSize(void) const
Get the size of the parameter values vector when it contains all available parameter values...

Here is the call graph for this function:

void set_caching ( bool  caching)
inline

Turn caching for the function normalizedKernelActivations() on or off.

Turning this on should lead to substantial improvements in execution time if the centers and widths of the kernels do not change often AND you call normalizedKernelActivations with the same inputs over and over again.

Parameters
[in]cachingWhether to turn caching on or off
Remarks
In the constructor, caching is set to true, so by default it is on.

Definition at line 139 of file ModelParametersLWR.hpp.

140  {
141  caching_ = caching;
142  if (!caching_) clearCache();
143  }

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Give boost serialization access to private members.

Definition at line 162 of file ModelParametersLWR.hpp.


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