DART  6.10.1
dart::optimizer::ModularFunction Class Reference

ModularFunction uses C++11 std::function to allow you to easily swap out the cost function, gradient function, and Hessian function during runtime for an optimizer::Function instance. More...

#include <Function.hpp>

Inheritance diagram for dart::optimizer::ModularFunction:
dart::optimizer::Function

Public Member Functions

 ModularFunction (const std::string &_name="modular_function")
 Constructor. More...
 
 ~ModularFunction () override
 Destructor. More...
 
double eval (const Eigen::VectorXd &_x) override
 eval() will now call whatever CostFunction you set using setCostFunction() More...
 
void evalGradient (const Eigen::VectorXd &_x, Eigen::Map< Eigen::VectorXd > _grad) override
 evalGradient() will now call whatever GradientFunction you set using setGradientFunction() More...
 
void evalHessian (const Eigen::VectorXd &_x, Eigen::Map< Eigen::VectorXd, Eigen::RowMajor > _Hess) override
 evalHessian() will now call whatever HessianFunction you set using setHessianFunction() More...
 
void setCostFunction (CostFunction _cost)
 Set the function that gets called by eval() More...
 
void clearCostFunction (bool _printWarning=true)
 Replace the cost function with a constant-zero function. More...
 
void setGradientFunction (GradientFunction _gradient)
 Set the function that gets called by evalGradient() More...
 
void clearGradientFunction ()
 Replace the gradient function with the default evalGradient() of the base Function class. More...
 
void setHessianFunction (HessianFunction _hessian)
 Set the function that gets called by evalHessian() More...
 
void clearHessianFunction ()
 Replace the Hessian function with the default evalHessian() of the base Function class. More...
 
virtual void setName (const std::string &newName)
 Sets the name of this Function. More...
 
const std::string & getName () const
 Returns the name of this Function. More...
 
void evalGradient (const Eigen::VectorXd &_x, Eigen::VectorXd &_grad)
 Evaluates and return the objective function at the point x. More...
 

Protected Attributes

CostFunction mCostFunction
 Storage for the cost function. More...
 
GradientFunction mGradientFunction
 Storage for the gradient function. More...
 
HessianFunction mHessianFunction
 Storage for the Hessian function. More...
 
std::string mName
 Name of this function. More...
 

Detailed Description

ModularFunction uses C++11 std::function to allow you to easily swap out the cost function, gradient function, and Hessian function during runtime for an optimizer::Function instance.

Constructor & Destructor Documentation

◆ ModularFunction()

dart::optimizer::ModularFunction::ModularFunction ( const std::string &  _name = "modular_function")
explicit

Constructor.

◆ ~ModularFunction()

dart::optimizer::ModularFunction::~ModularFunction ( )
override

Destructor.

Member Function Documentation

◆ clearCostFunction()

void dart::optimizer::ModularFunction::clearCostFunction ( bool  _printWarning = true)

Replace the cost function with a constant-zero function.

Passing in true will cause a warning to be printed out whenever eval() is called.

◆ clearGradientFunction()

void dart::optimizer::ModularFunction::clearGradientFunction ( )

Replace the gradient function with the default evalGradient() of the base Function class.

A warning will be printed whenever evalGradient() gets called.

◆ clearHessianFunction()

void dart::optimizer::ModularFunction::clearHessianFunction ( )

Replace the Hessian function with the default evalHessian() of the base Function class.

A warning will be printed whenever evalHessian() gets called.

◆ eval()

double dart::optimizer::ModularFunction::eval ( const Eigen::VectorXd &  _x)
overridevirtual

eval() will now call whatever CostFunction you set using setCostFunction()

Implements dart::optimizer::Function.

◆ evalGradient() [1/2]

void dart::optimizer::ModularFunction::evalGradient ( const Eigen::VectorXd &  _x,
Eigen::Map< Eigen::VectorXd >  _grad 
)
overridevirtual

evalGradient() will now call whatever GradientFunction you set using setGradientFunction()

Reimplemented from dart::optimizer::Function.

◆ evalGradient() [2/2]

void dart::optimizer::Function::evalGradient ( const Eigen::VectorXd &  _x,
Eigen::VectorXd &  _grad 
)
inherited

Evaluates and return the objective function at the point x.

If you have a raw array that the gradient will be passed in, then use evalGradient(const Eigen::VectorXd&, Eigen::Map<Eigen::VectorXd>) for better performance.

◆ evalHessian()

void dart::optimizer::ModularFunction::evalHessian ( const Eigen::VectorXd &  _x,
Eigen::Map< Eigen::VectorXd, Eigen::RowMajor >  _Hess 
)
overridevirtual

evalHessian() will now call whatever HessianFunction you set using setHessianFunction()

Reimplemented from dart::optimizer::Function.

◆ getName()

const std::string & dart::optimizer::Function::getName ( ) const
inherited

Returns the name of this Function.

◆ setCostFunction()

void dart::optimizer::ModularFunction::setCostFunction ( CostFunction  _cost)

Set the function that gets called by eval()

◆ setGradientFunction()

void dart::optimizer::ModularFunction::setGradientFunction ( GradientFunction  _gradient)

Set the function that gets called by evalGradient()

◆ setHessianFunction()

void dart::optimizer::ModularFunction::setHessianFunction ( HessianFunction  _hessian)

Set the function that gets called by evalHessian()

◆ setName()

void dart::optimizer::Function::setName ( const std::string &  newName)
virtualinherited

Sets the name of this Function.

Member Data Documentation

◆ mCostFunction

CostFunction dart::optimizer::ModularFunction::mCostFunction
protected

Storage for the cost function.

◆ mGradientFunction

GradientFunction dart::optimizer::ModularFunction::mGradientFunction
protected

Storage for the gradient function.

◆ mHessianFunction

HessianFunction dart::optimizer::ModularFunction::mHessianFunction
protected

Storage for the Hessian function.

◆ mName

std::string dart::optimizer::Function::mName
protectedinherited

Name of this function.