DMP_BBO library
Public Member Functions | List of all members
DemoCostFunctionDistanceToPoint Class Reference

CostFunction in which the distance to a pre-defined point must be minimized. More...

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

Public Member Functions

 DemoCostFunctionDistanceToPoint (const VectorXd &point, double regularization_weight)
 Constructor. More...
 
void evaluate (const VectorXd &sample, VectorXd &cost) const
 The cost function which defines the cost_function. More...
 
unsigned int getNumberOfCostComponents () const
 Get the number of individual cost components that constitute the final total cost. More...
 
string toString (void) const
 Returns a string representation of the object. More...
 
- Public Member Functions inherited from CostFunction
virtual void evaluate (const Eigen::VectorXd &sample, Eigen::VectorXd &cost) const =0
 The cost function which defines the cost_function. More...
 

Detailed Description

CostFunction in which the distance to a pre-defined point must be minimized.

Definition at line 48 of file demoOptimization.cpp.

Constructor & Destructor Documentation

DemoCostFunctionDistanceToPoint ( const VectorXd &  point,
double  regularization_weight 
)
inline

Constructor.

Parameters
[in]pointPoint to which distance must be minimized.
[in]regularization_weightRegularization penalty on the parameter vector.

Definition at line 55 of file demoOptimization.cpp.

56  {
57  point_ = point;
58  regularization_weight_ = regularization_weight;
59  }

Member Function Documentation

void evaluate ( const VectorXd &  sample,
VectorXd &  cost 
) const
inline

The cost function which defines the cost_function.

Parameters
[in]sampleThe sample
[out]costThe scalar cost for each sample.

Definition at line 66 of file demoOptimization.cpp.

67  {
68  assert(sample.size()==point_.size());
69  // Cost is distance to point
70  double dist_to_point = sqrt((sample - point_).array().pow(2).sum());
71  if (regularization_weight_>0.0)
72  {
73  cost.resize(3);
74  cost[1] = dist_to_point;
75  cost[2] = regularization_weight_*sqrt(sample.array().pow(2).sum());
76  cost[0] = cost[1] + cost[2];
77  }
78  else
79  {
80  cost.resize(1);
81  cost[0] = dist_to_point;
82  }
83  }
unsigned int getNumberOfCostComponents ( ) const
inlinevirtual

Get the number of individual cost components that constitute the final total cost.

Returns
The number of cost components.

Implements CostFunction.

Definition at line 85 of file demoOptimization.cpp.

86  {
87  if (regularization_weight_>0.0)
88  return 2;
89  else
90  return 0;
91  }
string toString ( void  ) const
inlinevirtual

Returns a string representation of the object.

Returns
A string representation of the object.

Implements CostFunction.

Definition at line 96 of file demoOptimization.cpp.

97  {
98  string str = "CostFunctionDistanceToPoint";
99  return str;
100  }

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