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

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

#include <MetaParametersLWR.hpp>

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

Public Member Functions

 MetaParametersLWR (int expected_input_dim, const std::vector< Eigen::VectorXd > &centers_per_dim, double intersection_height=0.5, double regularization=0.0, bool asymmetric_kernels=false)
 Constructor for the algorithmic meta-parameters of the LWR function approximator. More...
 
 MetaParametersLWR (int expected_input_dim, const Eigen::VectorXi &n_basis_functions_per_dim, double intersection_height=0.5, double regularization=0.0, bool asymmetric_kernels=false)
 Constructor for the algorithmic meta-parameters of the LWR function approximator. More...
 
 MetaParametersLWR (int expected_input_dim, int n_basis_functions=10, double intersection_height=0.5, double regularization=0.0, bool asymmetric_kernels=false)
 Constructor for the algorithmic meta-parameters of the LWR function approximator. More...
 
void getCentersAndWidths (const Eigen::VectorXd &min, const Eigen::VectorXd &max, Eigen::MatrixXd &centers, Eigen::MatrixXd &widths) const
 Get the centers and widths of the basis functions. More...
 
double regularization (void) const
 Accessor function for regularization. More...
 
bool asymmetric_kernels (void) const
 Accessor function for asymmetric_kernels. More...
 
MetaParametersLWRclone (void) const
 Return a pointer to a deep copy of the MetaParameters object. More...
 
std::string toString (void) const
 Returns a string representation of the object. More...
 
- Public Member Functions inherited from MetaParameters
 MetaParameters (int expected_input_dim)
 Constructor. More...
 
virtual ~MetaParameters (void)
 Virtual destructor, because this is a base class.
 
int getExpectedInputDim (void) const
 The expected dimensionality of the input data. More...
 
virtual int getExpectedOutputDim (void) const
 The expected dimensionality of the output data. More...
 

Friends

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

Additional Inherited Members

- Protected Member Functions inherited from MetaParameters
 MetaParameters (void)
 Default constructor. More...
 

Detailed Description

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

Definition at line 39 of file MetaParametersLWR.hpp.

Constructor & Destructor Documentation

MetaParametersLWR ( int  expected_input_dim,
const std::vector< Eigen::VectorXd > &  centers_per_dim,
double  intersection_height = 0.5,
double  regularization = 0.0,
bool  asymmetric_kernels = false 
)

Constructor for the algorithmic meta-parameters of the LWR function approximator.

Parameters
[in]expected_input_dimThe dimensionality of the data this function approximator expects. Although this information is already contained in the 'centers_per_dim' argument, we ask the user to pass it explicitly so that various checks on the arguments may be conducted.
[in]centers_per_dimCenters of the basis functions, one VectorXd for each dimension.
[in]intersection_heightThe value at which two neighbouring basis functions will intersect.
[in]regularizationRegularization parameter
[in]asymmetric_kernelsWhether to use asymmetric kernels or not (to be documented, default is false)

Definition at line 52 of file MetaParametersLWR.cpp.

53 :
54  MetaParameters(expected_input_dim),
55  n_bfs_per_dim_(VectorXi::Zero(0)),
56  centers_per_dim_(centers_per_dim),
57  intersection_height_(intersection_height),
58  regularization_(regularization),
59  asymmetric_kernels_(asymmetric_kernels)
60 {
61  assert(expected_input_dim==(int)centers_per_dim_.size());
62  for (unsigned int dd=0; dd<centers_per_dim_.size(); dd++)
63  assert(centers_per_dim_[dd].size()>0);
64  assert(intersection_height_>0 && intersection_height_<1);
65  assert(regularization>=0.0);
66 }
double regularization(void) const
Accessor function for regularization.
MetaParameters(void)
Default constructor.
bool asymmetric_kernels(void) const
Accessor function for asymmetric_kernels.
MetaParametersLWR ( int  expected_input_dim,
const Eigen::VectorXi &  n_basis_functions_per_dim,
double  intersection_height = 0.5,
double  regularization = 0.0,
bool  asymmetric_kernels = false 
)

Constructor for the algorithmic meta-parameters of the LWR function approximator.

Parameters
[in]expected_input_dimThe dimensionality of the data this function approximator expects. Although this information is already contained in the 'centers' argument, we ask the user to pass it explicitly so that various checks on the arguments may be conducted.
[in]n_basis_functions_per_dimNumber of basis functions
[in]intersection_heightThe value at which two neighbouring basis functions will intersect.
[in]regularizationRegularization parameter
[in]asymmetric_kernelsWhether to use asymmetric kernels or not (to be documented, default is false)

The centers and widths of the basis functions are determined from these parameters once the range of the input data is known, see also setInputMinMax()

Definition at line 68 of file MetaParametersLWR.cpp.

69 :
70  MetaParameters(expected_input_dim),
71  n_bfs_per_dim_(n_bfs_per_dim),
72  centers_per_dim_(std::vector<Eigen::VectorXd>(0)),
73  intersection_height_(intersection_height),
74  regularization_(regularization),
75  asymmetric_kernels_(asymmetric_kernels)
76 {
77  assert(expected_input_dim==n_bfs_per_dim_.size());
78  for (int dd=0; dd<n_bfs_per_dim_.size(); dd++)
79  assert(n_bfs_per_dim_[dd]>0);
80  assert(intersection_height_>0 && intersection_height_<1);
81  assert(regularization>=0.0);
82 };
double regularization(void) const
Accessor function for regularization.
MetaParameters(void)
Default constructor.
bool asymmetric_kernels(void) const
Accessor function for asymmetric_kernels.
MetaParametersLWR ( int  expected_input_dim,
int  n_basis_functions = 10,
double  intersection_height = 0.5,
double  regularization = 0.0,
bool  asymmetric_kernels = false 
)

Constructor for the algorithmic meta-parameters of the LWR function approximator.

This is for the special case when the dimensionality of the input data is 1.

Parameters
[in]expected_input_dimThe dimensionality of the data this function approximator expects. Since this constructor is for 1-D input data only, we simply check if this argument is equal to 1.
[in]n_basis_functionsNumber of basis functions for the one dimension
[in]intersection_heightThe value at which two neighbouring basis functions will intersect.
[in]regularizationRegularization parameter
[in]asymmetric_kernelsWhether to use asymmetric kernels or not (to be documented, default is false)

The centers and widths of the basis functions are determined from these parameters once the range of the input data is known, see also setInputMinMax()

Definition at line 84 of file MetaParametersLWR.cpp.

85 :
86  MetaParameters(expected_input_dim),
87  n_bfs_per_dim_(VectorXi::Constant(1,n_bfs)),
88  centers_per_dim_(std::vector<Eigen::VectorXd>(0)),
89  intersection_height_(intersection_height),
90  regularization_(regularization),
91  asymmetric_kernels_(asymmetric_kernels)
92 {
93  assert(expected_input_dim==n_bfs_per_dim_.size());
94  for (int dd=0; dd<n_bfs_per_dim_.size(); dd++)
95  assert(n_bfs_per_dim_[dd]>0);
96  assert(intersection_height_>0 && intersection_height_<1);
97  assert(regularization>=0.0);
98 };
double regularization(void) const
Accessor function for regularization.
MetaParameters(void)
Default constructor.
bool asymmetric_kernels(void) const
Accessor function for asymmetric_kernels.

Member Function Documentation

void getCentersAndWidths ( const Eigen::VectorXd &  min,
const Eigen::VectorXd &  max,
Eigen::MatrixXd &  centers,
Eigen::MatrixXd &  widths 
) const

Get the centers and widths of the basis functions.

Parameters
[in]minMinimum values of input data (one value for each dimension).
[in]maxMaximum values of input data (one value for each dimension).
[out]centersCenters of the basis functions (matrix of size n_basis_functions X n_input_dims
[out]widthsWidths of the basis functions (matrix of size n_basis_functions X n_input_dims

The reason why there are not two functions getCenters and getWidths is that it is much easier to compute both at the same time, and usually you will need both at the same time anyway.

Todo:
Document this rather complex function

Definition at line 112 of file MetaParametersLWR.cpp.

113 {
114  int n_dims = getExpectedInputDim();
115  assert(min.size()==n_dims);
116  assert(max.size()==n_dims);
117 
118  vector<VectorXd> centers_per_dim_local(n_dims);
119  if (!centers_per_dim_.empty())
120  {
121  centers_per_dim_local = centers_per_dim_;
122  }
123  else
124  {
125  // Centers are not know yet, compute them based on min and max
126  for (int i_dim=0; i_dim<n_dims; i_dim++)
127  centers_per_dim_local[i_dim] = VectorXd::LinSpaced(n_bfs_per_dim_[i_dim],min[i_dim],max[i_dim]);
128  }
129 
130  // Determine the widths from the centers (separately for each dimension)
131  vector<VectorXd> widths_per_dim_local(n_dims);
132  for (int i_dim=0; i_dim<n_dims; i_dim++)
133  {
134  VectorXd cur_centers = centers_per_dim_local[i_dim]; // Abbreviation for convenience
135  int n_centers = cur_centers.size();
136  VectorXd cur_widths(n_centers);
137 
138  if (n_centers==1)
139  {
140  cur_widths[0] = 1.0;
141  }
142  else
143  {
144  // Consider two neighbouring basis functions, exp(-0.5(x-c0)^2/w^2) and exp(-0.5(x-c1)^2/w^2)
145  // Assuming the widths are the same for both, they are certain to intersect at x = 0.5(c0+c1)
146  // And we want the activation at x to be 'intersection'. So
147  // y = exp(-0.5(x-c0)^2/w^2)
148  // intersection = exp(-0.5((0.5(c0+c1))-c0)^2/w^2)
149  // intersection = exp(-0.5((0.5*c1-0.5*c0)^2/w^2))
150  // intersection = exp(-0.5((0.5*(c1-c0))^2/w^2))
151  // intersection = exp(-0.5(0.25*(c1-c0)^2/w^2))
152  // intersection = exp(-0.125((c1-c0)^2/w^2))
153  // w = sqrt((c1-c0)^2/-8*ln(intersection))
154  for (int cc=0; cc<n_centers-1; cc++)
155  {
156  double w = sqrt(pow(cur_centers[cc+1]-cur_centers[cc],2)/(-8*log(intersection_height_)));
157  cur_widths[cc] = w;
158  }
159  cur_widths[n_centers-1] = cur_widths[n_centers-2];
160  }
161  widths_per_dim_local[i_dim] = cur_widths;
162  }
163 
164  VectorXd digit_max(n_dims);
165  int n_centers = 1;
166  for (int i_dim=0; i_dim<n_dims; i_dim++)
167  {
168  n_centers = n_centers*centers_per_dim_local[i_dim].size();
169  digit_max[i_dim] = centers_per_dim_local[i_dim].size();
170  }
171  VectorXi digit = VectorXi::Zero(n_dims);
172 
173  centers.resize(n_centers,n_dims);
174  widths.resize(n_centers,n_dims);
175  int i_center=0;
176 
177  while (digit[0]<digit_max(0))
178  {
179  for (int i_dim=0; i_dim<n_dims; i_dim++)
180  {
181  centers(i_center,i_dim) = centers_per_dim_local[i_dim][digit[i_dim]];
182  widths(i_center,i_dim) = widths_per_dim_local[i_dim][digit[i_dim]];
183  }
184  i_center++;
185 
186  // Increment last digit by one
187  digit[n_dims-1]++;
188  for (int i_dim=n_dims-1; i_dim>0; i_dim--)
189  {
190  if (digit[i_dim]>=digit_max[i_dim])
191  {
192  digit[i_dim] = 0;
193  digit[i_dim-1]++;
194  }
195  }
196  }
197 
198 }
int getExpectedInputDim(void) const
The expected dimensionality of the input data.

Here is the call graph for this function:

double regularization ( void  ) const
inline

Accessor function for regularization.

Returns
Regularization parameter.

Definition at line 93 of file MetaParametersLWR.hpp.

94  {
95  return regularization_;
96  }
bool asymmetric_kernels ( void  ) const
inline

Accessor function for asymmetric_kernels.

Returns
true if asymmetric kernels are used, false if symmetric kernels are used.
Todo:
Document this. In the literature, only symmetric kernels are used.

Definition at line 102 of file MetaParametersLWR.hpp.

103  {
104  return asymmetric_kernels_;
105  }

Here is the call graph for this function:

MetaParametersLWR * clone ( void  ) const
virtual

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

Returns
Pointer to a deep copy

Implements MetaParameters.

Definition at line 100 of file MetaParametersLWR.cpp.

101 {
102  MetaParametersLWR* cloned;
103  if (centers_per_dim_.size()>0)
104  cloned = new MetaParametersLWR(getExpectedInputDim(),centers_per_dim_,intersection_height_,regularization_,asymmetric_kernels_);
105  else
106  cloned = new MetaParametersLWR(getExpectedInputDim(),n_bfs_per_dim_,intersection_height_,regularization_,asymmetric_kernels_);
107 
108  return cloned;
109 }
int getExpectedInputDim(void) const
The expected dimensionality of the input data.
MetaParametersLWR(int expected_input_dim, const std::vector< Eigen::VectorXd > &centers_per_dim, double intersection_height=0.5, double regularization=0.0, bool asymmetric_kernels=false)
Constructor for the algorithmic meta-parameters of the LWR function approximator. ...

Here is the call graph for this function:

string toString ( void  ) const
virtual

Returns a string representation of the object.

Returns
A string representation of the object.

Implements MetaParameters.

Definition at line 213 of file MetaParametersLWR.cpp.

214 {
215  RETURN_STRING_FROM_BOOST_SERIALIZATION_XML("MetaParametersLWR");
216 }
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Give boost serialization access to private members.

Definition at line 124 of file MetaParametersLWR.hpp.


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