All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
roboptim::GenericFunction< T > Class Template Referenceabstract
Mathematical abstract functions

Define an abstract mathematical function ( ). More...

`#include <roboptim/core/fwd.hh>`

Inheritance diagram for roboptim::GenericFunction< T >:

## Public Types

typedef GenericFunctionTraits < T >::value_type | value_type
| Values type. More...
typedef GenericFunctionTraits < T >::vector_t | vector_t
| Basic vector type. More...
typedef GenericFunctionTraits < T >::matrix_t | matrix_t
| Basic matrix type. More...
typedef GenericFunctionTraits < T >::size_type | size_type
| Size type. More...
typedef GenericFunctionTraits < T >::result_t | result_t
| Type of a function evaluation result. More...
typedef GenericFunctionTraits < T >::argument_t | argument_t
| Type of a function evaluation argument. More...

## Public Member Functions

bool | isValidResult (const result_t &result) const throw ()
| Check the given result size is valid. More...
GenericFunction< T >::size_type | inputSize () const throw ()
| Return the input size (i.e. More...
GenericFunction< T >::size_type | outputSize () const throw ()
| Return the output size (i.e. More...
virtual | ~GenericFunction () throw ()
| Trivial destructor. More...
result_t | operator() (const argument_t &argument) const throw ()
| Evaluate the function at a specified point. More...
void | operator() (result_t &result, const argument_t &argument) const throw ()
| Evaluate the function at a specified point. More...
const std::string & | getName () const throw ()
| Get function name. More...
virtual std::ostream & | print (std::ostream &) const throw ()
| Display the function on the specified output stream. More...

## Static Public Member Functions

static value_type | epsilon () throw ()
| Get the value of the machine epsilon, useful for floating types comparison. More...
static value_type | infinity () throw ()
| Get the value that symbolizes positive infinity. More...

## Protected Member Functions

| GenericFunction (size_type inputSize, size_type outputSize=1, std::string name=std::string()) throw ()
| Concrete class constructor should call this constructor. More...
virtual void | impl_compute (result_t &result, const argument_t &argument) const =0 throw ()
| Function evaluation. More...

## Static Protected Attributes

static log4cxx::LoggerPtr | logger
| Pointer to function logger (see log4cxx documentation). More...

## Interval

typedef std::pair< value_type, value_type > | interval_t
| Interval type (lower, upper). More...
typedef std::vector< interval_t > | intervals_t
| Vector of intervals. More...
static interval_t | makeInterval (value_type l, value_type u) throw ()
| Construct an interval from a lower and upper bound. More...
static interval_t | makeInfiniteInterval () throw ()
| Construct an infinite interval. More...
static interval_t | makeLowerInterval (value_type l) throw ()
| Construct an interval from a lower bound. More...
static interval_t | makeUpperInterval (value_type u) throw ()
| Construct an interval from an upper bound. More...
static double | getLowerBound (const interval_t &interval) throw ()
| Get the lower bound of an interval. More...
static double | getUpperBound (const interval_t &interval) throw ()
| Get the upper bound of an interval. More...

## Discrete interval

typedef boost::tuple < value_type, value_type, value_type > | discreteInterval_t
| Types representing a discrete interval. More...
static discreteInterval_t | makeDiscreteInterval (value_type min, value_type max, value_type step)
| Construct a discrete interval. More...
static discreteInterval_t | makeDiscreteInterval (interval_t interval, value_type step)
| Construct a discrete interval. More...
static double | getLowerBound (const discreteInterval_t &interval) throw ()
| Get the lower bound of a discrete interval. More...
static double | getUpperBound (const discreteInterval_t &interval) throw ()
| Get the upper bound of a discrete interval. More...
static double | getStep (const discreteInterval_t &interval) throw ()
| Get the upper step of a discrete interval. More...
template<typename F >
static void | foreach (const discreteInterval_t interval, F functor)
| Iterate on an interval. More...
template<typename F >
static void | foreach (const interval_t interval, const size_type n, F functor)
| Iterate on an interval. More...

## Detailed Description

### template<typename T>
class roboptim::GenericFunction< T >

Define an abstract mathematical function ( ).

A function is an object that can be evaluated for a given point.

, where is the input size and is the output size.

Functions are pure immutable objects: evaluating a function twice at a given point must give the same result.

This function is parametrized by the matrix type used in this function. Currently, dense (which size may be dynamic or static and sparse Eigen matrices can be used) are supported.

Template Parameters

  T | Matrix type

Examples:
  visualization-gnuplot-function.cc.

## Member Typedef Documentation

template<typename T>

typedef GenericFunctionTraits<T>::argument_t roboptim::GenericFunction< T >::argument_t

Type of a function evaluation argument.

template<typename T>

typedef boost::tuple<value_type, value_type, value_type> roboptim::GenericFunction< T >::discreteInterval_t

Types representing a discrete interval.

A discrete interval is a triplet of values:

- lower bound,
- upper bound,
- step.

template<typename T>

typedef std::pair<value_type, value_type> roboptim::GenericFunction< T >::interval_t

Interval type (lower, upper).

Use negative or positive infinity to respectively disable the lower or upper bound.

template<typename T>

typedef std::vector<interval_t> roboptim::GenericFunction< T >::intervals_t

Vector of intervals.

template<typename T>

typedef GenericFunctionTraits<T>::matrix_t roboptim::GenericFunction< T >::matrix_t

Basic matrix type.

This basic matrix type is used each time a two dimensional matrix of values is needed.

Attention
  It is good practice in RobOptim to rely on this type when a matrix of values is needed instead of relying on a particular implementation.

Examples:
  numeric-quadratic-function.cc.

template<typename T>

typedef GenericFunctionTraits<T>::result_t roboptim::GenericFunction< T >::result_t

Type of a function evaluation result.

template<typename T>

typedef GenericFunctionTraits<T>::size_type roboptim::GenericFunction< T >::size_type

Size type.

This type is used to represent sizes, indexes, etc.

template<typename T>

typedef GenericFunctionTraits<T>::value_type roboptim::GenericFunction< T >::value_type

Values type.

Represents the numerical type (i.e. float, double, int...) used for computations.

template<typename T>

typedef GenericFunctionTraits<T>::vector_t roboptim::GenericFunction< T >::vector_t

Basic vector type.

This basic vector type is used each time a vector of values is required.

Attention
  It is good practice in RobOptim to rely on this type when a vector of values is needed instead of relying on a particular implementation.

Examples:
  numeric-quadratic-function.cc.

## Member Function Documentation

template<typename T>

static value_type roboptim::GenericFunction< T >::epsilon | ( |  | ) |
throw | ( |
| ) |  |

inline static

Get the value of the machine epsilon, useful for floating types comparison.

Returns
  machine epsilon value.

Referenced by roboptim::detail::ltvector::operator()().

template<typename T>
template<typename F >

static void roboptim::GenericFunction< T >::foreach | ( | const discreteInterval_t | interval,
|  | F | functor
| ) |  |

inline static

Iterate on an interval.

Call the functor to each discretization point of the discrete interval.

Parameters

  interval | interval on which the method iterates
  functor | unary function that will be applied

Template Parameters

  F | functor type (has to satisfy the STL unary function concept)

References roboptim::GenericFunction< T >::getLowerBound(), roboptim::GenericFunction< T >::getStep(), and roboptim::GenericFunction< T >::getUpperBound().

template<typename T>
template<typename F >

static void roboptim::GenericFunction< T >::foreach | ( | const interval_t | interval,
|  | const size_type | n,
|  | F | functor
| ) |  |

inline static

Iterate on an interval.

Call the functor regularly n times on an interval.

Parameters

  interval | interval on which the method iterates
  n | number of discretization points
  functor | unary function that will be applied

Template Parameters

  F | functor type (has to satisfy the STL unary function concept)

References roboptim::GenericFunction< T >::getLowerBound(), and roboptim::GenericFunction< T >::getUpperBound().

template<typename T>

static double roboptim::GenericFunction< T >::getLowerBound | ( | const interval_t & | interval | ) |
throw | ( |
| ) |  |

inline static

Get the lower bound of an interval.

Parameters

  interval | accessed interval

Returns
  lower bound of the interval

Referenced by roboptim::GenericFunction< T >::foreach(), and roboptim::GenericFunction< T >::makeDiscreteInterval().

template<typename T>

static double roboptim::GenericFunction< T >::getLowerBound | ( | const discreteInterval_t & | interval | ) |
throw | ( |
| ) |  |

inline static

Get the lower bound of a discrete interval.

Parameters

  interval | accessed discrete interval

Returns
  lower bound of the discrete interval

template<typename T>

const std::string& roboptim::GenericFunction< T >::getName | ( |  | ) | const
throw | ( |
| ) |  |

inline

Get function name.

Returns
  Function name.

Referenced by roboptim::visualization::gnuplot::plot(), roboptim::visualization::gnuplot::plot_jac(), roboptim::visualization::gnuplot::plot_xy(), and roboptim::GenericFunction< T >::print().

template<typename T>

static double roboptim::GenericFunction< T >::getStep | ( | const discreteInterval_t & | interval | ) |
throw | ( |
| ) |  |

inline static

Get the upper step of a discrete interval.

Parameters

  interval | accessed discrete interval

Returns
  upper step of the discrete interval

Referenced by roboptim::GenericFunction< T >::foreach().

template<typename T>

static double roboptim::GenericFunction< T >::getUpperBound | ( | const interval_t & | interval | ) |
throw | ( |
| ) |  |

inline static

Get the upper bound of an interval.

Parameters

  interval | accessed interval

Returns
  upper bound of the interval

Referenced by roboptim::GenericFunction< T >::foreach(), and roboptim::GenericFunction< T >::makeDiscreteInterval().

template<typename T>

static double roboptim::GenericFunction< T >::getUpperBound | ( | const discreteInterval_t & | interval | ) |
throw | ( |
| ) |  |

inline static

Get the upper bound of a discrete interval.

Parameters

  interval | accessed discrete interval

Returns
  upper bound of the discrete interval

template<typename T>

virtual void roboptim::GenericFunction< T >::impl_compute | ( | result_t & | result,
|  | const argument_t & | argument
| ) |  | const
throw | ( |
| ) |  |

protected pure virtual

Function evaluation.

Evaluate the function, has to be implemented in concrete classes.

Warning
  Do not call this function directly, call #operator()(result_t&, const argument_t&) const throw () instead.

Parameters

  result | result will be stored in this vector
  argument | point at which the function will be evaluated

Implemented in roboptim::GenericFiniteDifferenceGradient< T, FdgPolicy >, roboptim::NTimesDerivableFunction< 2 >, roboptim::SumOfC1Squares, roboptim::GenericNumericLinearFunction< T >, roboptim::NumericQuadraticFunction, roboptim::IdentityFunction, and roboptim::ConstantFunction.

template<typename T>

static value_type roboptim::GenericFunction< T >::infinity | ( |  | ) |
throw | ( |
| ) |  |

inline static

Get the value that symbolizes positive infinity.

Returns
  representation of positive infinity in the value type

Referenced by roboptim::GenericFunction< T >::makeInfiniteInterval(), roboptim::GenericFunction< T >::makeLowerInterval(), roboptim::GenericFunction< T >::makeUpperInterval(), roboptim::Problem< F, boost::mpl::vector<> >::print(), and roboptim::Problem< F, C >::print().

template<typename T>

GenericFunction<T>::size_type roboptim::GenericFunction< T >::inputSize | ( |  | ) | const
throw | ( |
| ) |  |

inline

Return the input size (i.e.

argument's vector size).

Returns
  input size

Referenced by roboptim::finiteDifferenceGradientPolicies::Simple< T >::computeGradient(), roboptim::GenericDifferentiableFunction< T >::gradient(), roboptim::GenericDifferentiableFunction< T >::gradientSize(), roboptim::GenericTwiceDifferentiableFunction< T >::hessianSize(), roboptim::GenericDifferentiableFunction< T >::jacobian(), roboptim::GenericDifferentiableFunction< T >::jacobianSize(), roboptim::GenericFunction< T >::operator()(), roboptim::visualization::gnuplot::plot(), and roboptim::visualization::gnuplot::plot_xy().

template<typename T>

bool roboptim::GenericFunction< T >::isValidResult | ( | const result_t & | result | ) | const
throw | ( |
| ) |  |

inline

Check the given result size is valid.

Parameters

  result | result that will be checked

Returns
  true if valid, false if not

References roboptim::GenericFunction< T >::outputSize().

Referenced by roboptim::GenericFunction< T >::operator()().

template<typename T>

static discreteInterval_t roboptim::GenericFunction< T >::makeDiscreteInterval | ( | value_type | min,
|  | value_type | max,
|  | value_type | step
| ) |  |

inline static

Construct a discrete interval.

Parameters

  min | miminum value of the interval
  max | maxinum value of the interval
  step | discretization step

template<typename T>

static discreteInterval_t roboptim::GenericFunction< T >::makeDiscreteInterval | ( | interval_t | interval,
|  | value_type | step
| ) |  |

inline static

Construct a discrete interval.

Parameters

  interval | continuous interval
  step | discretization step

References roboptim::GenericFunction< T >::getLowerBound(), and roboptim::GenericFunction< T >::getUpperBound().

template<typename T>

static interval_t roboptim::GenericFunction< T >::makeInfiniteInterval | ( |  | ) |
throw | ( |
| ) |  |

inline static

Construct an infinite interval.

Returns
  interval representing

References roboptim::GenericFunction< T >::infinity().

Referenced by roboptim::Problem< F, boost::mpl::vector<> >::Problem(), and roboptim::Problem< F, C >::Problem().

template<typename T>

static interval_t roboptim::GenericFunction< T >::makeInterval | ( | value_type | l,
|  | value_type | u
| ) |  |
throw | ( |
| ) |  |

inline static

Construct an interval from a lower and upper bound.

Parameters

  l | lower bound
  u | upper bound

Returns
  interval representing

Referenced by roboptim::GenericFunction< T >::makeLowerInterval(), and roboptim::GenericFunction< T >::makeUpperInterval().

template<typename T>

static interval_t roboptim::GenericFunction< T >::makeLowerInterval | ( | value_type | l | ) |
throw | ( |
| ) |  |

inline static

Construct an interval from a lower bound.

Parameters

  l | lower bound

Returns
  interval representing

References roboptim::GenericFunction< T >::infinity(), and roboptim::GenericFunction< T >::makeInterval().

template<typename T>

static interval_t roboptim::GenericFunction< T >::makeUpperInterval | ( | value_type | u | ) |
throw | ( |
| ) |  |

inline static

Construct an interval from an upper bound.

Parameters

  u | upper bound

Returns
  interval representing

References roboptim::GenericFunction< T >::infinity(), and roboptim::GenericFunction< T >::makeInterval().

template<typename T>

result_t roboptim::GenericFunction< T >::operator() | ( | const argument_t & | argument | ) | const
throw | ( |
| ) |  |

inline

Evaluate the function at a specified point.

The program will abort if the argument does not have the expected size.

Parameters

  argument | point at which the function will be evaluated

Returns
  computed result

References roboptim::GenericFunction< T >::outputSize().

template<typename T>

void roboptim::GenericFunction< T >::operator() | ( | result_t & | result,
|  | const argument_t & | argument
| ) |  | const
throw | ( |
| ) |  |

inline

Evaluate the function at a specified point.

The program will abort if the argument does not have the expected size.

Parameters

  result | result will be stored in this vector
  argument | point at which the function will be evaluated

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::GenericFunction< T >::inputSize(), roboptim::GenericFunction< T >::isValidResult(), and roboptim::GenericFunction< T >::logger.

template<typename T>

GenericFunction<T>::size_type roboptim::GenericFunction< T >::outputSize | ( |  | ) | const
throw | ( |
| ) |  |

inline

Return the output size (i.e.

result's vector size).

Returns
  input size

Referenced by roboptim::finiteDifferenceGradientPolicies::Simple< T >::computeGradient(), roboptim::finiteDifferenceGradientPolicies::FivePointsRule< T >::computeGradient(), roboptim::GenericFunction< T >::isValidResult(), roboptim::GenericDifferentiableFunction< T >::jacobianSize(), roboptim::GenericFunction< T >::operator()(), roboptim::visualization::gnuplot::plot(), and roboptim::visualization::gnuplot::plot_xy().