roboptim::GenericFunction< T > Class Template Reference

Define an abstract mathematical function ( \(C^0\)). More...

#include <roboptim/core/function.hh>

Inheritance diagram for roboptim::GenericFunction< T >:
roboptim::GenericDifferentiableFunction< T > roboptim::GenericFiniteDifferenceGradient< T, FdgPolicy > roboptim::GenericSumOfC1Squares< T > roboptim::GenericTwiceDifferentiableFunction< T > roboptim::Cos< T > roboptim::GenericQuadraticFunction< T > roboptim::NTimesDerivableFunction< 2 > roboptim::Polynomial< T > roboptim::Sin< T > roboptim::GenericLinearFunction< T > roboptim::GenericNumericQuadraticFunction< T > roboptim::GenericConstantFunction< T > roboptim::GenericIdentityFunction< T > roboptim::GenericNumericLinearFunction< T >

List of all members.

Public Types

typedef T traits_t
 Traits type.
typedef GenericFunctionTraits
< T >::value_type 
value_type
 Values type.
typedef GenericFunctionTraits
< T >::size_type 
size_type
 Size type.
typedef std::string name_t
 Type of a function argument name.
typedef std::vector< name_tnames_t
 Type of a vector of function argument names.

Public Member Functions

 ROBOPTIM_DEFINE_FLAG_TYPE ()
 ROBOPTIM_GENERATE_TRAITS_REFS_ (vector)
 Basic (column) vector type.
 ROBOPTIM_GENERATE_TRAITS_REFS_ (rowVector)
 Row vector type.
 ROBOPTIM_GENERATE_TRAITS_REFS_ (matrix)
 Basic matrix type.
 ROBOPTIM_GENERATE_TRAITS_REFS_ (result)
 Type of a function evaluation result.
 ROBOPTIM_GENERATE_TRAITS_REFS_ (argument)
 Type of a function evaluation argument.
bool isValidResult (const_result_ref result) const
 Check the given result size is valid.
GenericFunction< T >::size_type inputSize () const
 Return the input size (i.e.
GenericFunction< T >::size_type outputSize () const
 Return the output size (i.e.
virtual ~GenericFunction ()
 Trivial destructor.
result_t operator() (const_argument_ref argument) const
 Evaluate the function at a specified point.
void operator() (result_ref result, const_argument_ref argument) const
 Evaluate the function at a specified point.
const std::string & getName () const
 Get function name.
virtual std::ostream & print (std::ostream &) const
 Display the function on the specified output stream.
virtual flag_t getFlags () const
 Get the type-checking flag.

Static Public Member Functions

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

Static Public Attributes

static const flag_t flags = ROBOPTIM_IS_FUNCTION
 Flag representing the Roboptim Function type.

Protected Member Functions

 GenericFunction (size_type inputSize, size_type outputSize=1, std::string name=std::string())
 Concrete class constructor should call this constructor.
virtual void impl_compute (result_ref result, const_argument_ref argument) const =0
 Function evaluation.

Static Protected Attributes

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

Interval

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

Discrete interval

typedef boost::tuple
< value_type, value_type,
value_type
discreteInterval_t
 Types representing a discrete interval.
template<class ExpectedType >
ExpectedType * castInto (bool check=false)
 Cast function to ExpectedType.
template<class ExpectedType >
const ExpectedType * castInto (bool check=false) const
 Cast function to ExpectedType (const).
template<class ExpectedType >
bool asType () const
 Fonction type checking.
static discreteInterval_t makeDiscreteInterval (value_type min, value_type max, value_type step)
 Construct a discrete interval.
static discreteInterval_t makeDiscreteInterval (interval_t interval, value_type step)
 Construct a discrete interval.
static value_type getLowerBound (const discreteInterval_t &interval)
 Get the lower bound of a discrete interval.
static value_type getUpperBound (const discreteInterval_t &interval)
 Get the upper bound of a discrete interval.
static value_type getStep (const discreteInterval_t &interval)
 Get the upper step of a discrete interval.
template<typename F >
static void foreach (const discreteInterval_t interval, F functor)
 Iterate on an interval.
template<typename F >
static void foreach (const interval_t interval, const size_type n, F functor)
 Iterate on an interval.

Detailed Description

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

Define an abstract mathematical function ( \(C^0\)).

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

\[ f : x \rightarrow f(x) \]

\(x \in \mathbb{R}^n\), \(f(x) \in \mathbb{R}^m\) where \(n\) is the input size and \(m\) 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:
TMatrix type
Examples:
result.cc, visualization-gnuplot-function.cc, and visualization-matplotlib-function.cc.

Member Typedef Documentation

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 std::string roboptim::GenericFunction< T >::name_t

Type of a function argument name.

template<typename T>
typedef std::vector<name_t> roboptim::GenericFunction< T >::names_t

Type of a vector of function argument names.

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

Size type.

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

Reimplemented in roboptim::GenericQuadraticFunction< T >.

template<typename T>
typedef T roboptim::GenericFunction< T >::traits_t

Traits type.

Represents the matrix type used to store the underlying data. This can be EigenMatrixDense or EigenMatrixSparse.

Reimplemented in roboptim::NTimesDerivableFunction< 2 >.

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.


Constructor & Destructor Documentation

template<typename T >
roboptim::GenericFunction< T >::~GenericFunction ( ) [virtual]

Trivial destructor.

template<typename T >
roboptim::GenericFunction< T >::GenericFunction ( size_type  inputSize,
size_type  outputSize = 1,
std::string  name = std::string () 
) [protected]

Concrete class constructor should call this constructor.

Parameters:
inputSizefunction arity
outputSizeresult size
namefunction's name
Exceptions:
std::runtime_error

Member Function Documentation

template<typename T >
template<class ExpectedType >
bool roboptim::GenericFunction< T >::asType ( ) const

Fonction type checking.

Template Parameters:
ExpectedTypetype the function could be compatible with
template<typename T >
template<class ExpectedType >
ExpectedType * roboptim::GenericFunction< T >::castInto ( bool  check = false)

Cast function to ExpectedType.

Template Parameters:
ExpectedTypetype we want to cast the function into.
Parameters:
checkcheck that the cast is valid, and throws if it is not.
template<typename T >
template<class ExpectedType >
const ExpectedType * roboptim::GenericFunction< T >::castInto ( bool  check = false) const

Cast function to ExpectedType (const).

Template Parameters:
ExpectedTypetype we want to cast the function into.
Parameters:
checkcheck that the cast is valid, and throws if it is not.
template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::epsilon ( ) [static]

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

Returns:
machine epsilon value.
template<typename T >
template<typename F >
void roboptim::GenericFunction< T >::foreach ( const discreteInterval_t  interval,
functor 
) [static]

Iterate on an interval.

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

Parameters:
intervalinterval on which the method iterates
functorunary function that will be applied
Template Parameters:
Ffunctor type (has to satisfy the STL unary function concept)
template<typename T >
template<typename F >
void roboptim::GenericFunction< T >::foreach ( const interval_t  interval,
const size_type  n,
functor 
) [static]

Iterate on an interval.

Call the functor regularly n times on an interval.

Parameters:
intervalinterval on which the method iterates
nnumber of discretization points
functorunary function that will be applied
Template Parameters:
Ffunctor type (has to satisfy the STL unary function concept)
template<typename T >
GenericFunction< T >::flag_t roboptim::GenericFunction< T >::getFlags ( ) const [virtual]

Get the type-checking flag.

template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::getLowerBound ( const interval_t interval) [static]

Get the lower bound of an interval.

Parameters:
intervalaccessed interval
Returns:
lower bound of the interval
template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::getLowerBound ( const discreteInterval_t interval) [static]

Get the lower bound of a discrete interval.

Parameters:
intervalaccessed discrete interval
Returns:
lower bound of the discrete interval
template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::getStep ( const discreteInterval_t interval) [static]

Get the upper step of a discrete interval.

Parameters:
intervalaccessed discrete interval
Returns:
upper step of the discrete interval
template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::getUpperBound ( const interval_t interval) [static]

Get the upper bound of an interval.

Parameters:
intervalaccessed interval
Returns:
upper bound of the interval
template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::getUpperBound ( const discreteInterval_t interval) [static]

Get the upper bound of a discrete interval.

Parameters:
intervalaccessed discrete interval
Returns:
upper bound of the discrete interval
template<typename T>
virtual void roboptim::GenericFunction< T >::impl_compute ( result_ref  result,
const_argument_ref  argument 
) const [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_ref, const_argument_ref) const instead.
Parameters:
resultresult will be stored in this vector
argumentpoint at which the function will be evaluated

Implemented in roboptim::GenericFiniteDifferenceGradient< T, FdgPolicy >, roboptim::NTimesDerivableFunction< 2 >, roboptim::GenericNumericQuadraticFunction< T >, roboptim::GenericNumericLinearFunction< T >, roboptim::GenericConstantFunction< T >, roboptim::GenericSumOfC1Squares< T >, roboptim::GenericIdentityFunction< T >, roboptim::Polynomial< T >, roboptim::Cos< T >, and roboptim::Sin< T >.

template<typename T >
GenericFunction< T >::value_type roboptim::GenericFunction< T >::infinity ( ) [static]

Get the value that symbolizes positive infinity.

Returns:
representation of positive infinity in the value type
template<typename T >
bool roboptim::GenericFunction< T >::isValidResult ( const_result_ref  result) const

Check the given result size is valid.

Parameters:
resultresult that will be checked
Returns:
true if valid, false if not
template<typename T >
GenericFunction< T >::discreteInterval_t roboptim::GenericFunction< T >::makeDiscreteInterval ( value_type  min,
value_type  max,
value_type  step 
) [static]

Construct a discrete interval.

Parameters:
minmiminum value of the interval
maxmaxinum value of the interval
stepdiscretization step
template<typename T >
GenericFunction< T >::discreteInterval_t roboptim::GenericFunction< T >::makeDiscreteInterval ( interval_t  interval,
value_type  step 
) [static]

Construct a discrete interval.

Parameters:
intervalcontinuous interval
stepdiscretization step
template<typename T >
GenericFunction< T >::interval_t roboptim::GenericFunction< T >::makeInfiniteInterval ( ) [static]

Construct an infinite interval.

Returns:
interval representing \([-\infty, +\infty]\)
Examples:
problem-cc.cc.
template<typename T >
GenericFunction< T >::interval_t roboptim::GenericFunction< T >::makeInterval ( value_type  l,
value_type  u 
) [static]

Construct an interval from a lower and upper bound.

Parameters:
llower bound
uupper bound
Returns:
interval representing \([l, u]\)
template<typename T >
GenericFunction< T >::interval_t roboptim::GenericFunction< T >::makeLowerInterval ( value_type  l) [static]

Construct an interval from a lower bound.

Parameters:
llower bound
Returns:
interval representing \([l, +\infty]\)
template<typename T >
GenericFunction< T >::interval_t roboptim::GenericFunction< T >::makeUpperInterval ( value_type  u) [static]

Construct an interval from an upper bound.

Parameters:
uupper bound
Returns:
interval representing \([-\infty, u]\)
template<typename T >
GenericFunction< T >::result_t roboptim::GenericFunction< T >::operator() ( const_argument_ref  argument) const

Evaluate the function at a specified point.

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

Parameters:
argumentpoint at which the function will be evaluated
Returns:
computed result
template<typename T >
void roboptim::GenericFunction< T >::operator() ( result_ref  result,
const_argument_ref  argument 
) const

Evaluate the function at a specified point.

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

Parameters:
resultresult will be stored in this vector
argumentpoint at which the function will be evaluated

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().

template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_DEFINE_FLAG_TYPE ( )
template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ ( vector  )

Basic (column) 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.
template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ ( rowVector  )

Row vector type.

This basic vector type is used each time a row vector of values is required (e.g. gradients).

template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ ( matrix  )

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.
template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ ( result  )

Type of a function evaluation result.

template<typename T>
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ ( argument  )

Type of a function evaluation argument.


Member Data Documentation

template<typename T>
const flag_t roboptim::GenericFunction< T >::flags = ROBOPTIM_IS_FUNCTION [static]

Flag representing the Roboptim Function type.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines