Define an abstract mathematical function ( \(C^0\)). More...
#include <roboptim/core/fwd.hh>
Public Types | |
typedef T | traits_t |
Traits type. More... | |
typedef GenericFunctionTraits < T >::value_type | value_type |
Values type. More... | |
typedef GenericFunctionTraits < T >::size_type | size_type |
Size type. More... | |
typedef std::string | name_t |
Type of a function argument name. More... | |
typedef std::vector< name_t > | names_t |
Type of a vector of function argument names. More... | |
Public Member Functions | |
ROBOPTIM_DEFINE_FLAG_TYPE () | |
ROBOPTIM_GENERATE_TRAITS_REFS_ (vector) | |
Basic (column) vector type. More... | |
ROBOPTIM_GENERATE_TRAITS_REFS_ (rowVector) | |
Row vector type. More... | |
ROBOPTIM_GENERATE_TRAITS_REFS_ (matrix) | |
Basic matrix type. More... | |
ROBOPTIM_GENERATE_TRAITS_REFS_ (result) | |
Type of a function evaluation result. More... | |
ROBOPTIM_GENERATE_TRAITS_REFS_ (argument) | |
Type of a function evaluation argument. More... | |
bool | isValidResult (const_result_ref result) const |
Check the given result size is valid. More... | |
GenericFunction< T >::size_type | inputSize () const |
Return the input size (i.e. More... | |
GenericFunction< T >::size_type | outputSize () const |
Return the output size (i.e. More... | |
virtual | ~GenericFunction () |
Trivial destructor. More... | |
result_t | operator() (const_argument_ref argument) const |
Evaluate the function at a specified point. More... | |
void | operator() (result_ref result, const_argument_ref argument) const |
Evaluate the function at a specified point. More... | |
const std::string & | getName () const |
Get function name. More... | |
virtual std::ostream & | print (std::ostream &) const |
Display the function on the specified output stream. More... | |
virtual flag_t | getFlags () const |
Get the type-checking flag. More... | |
template<typename F > | |
void | foreach (const discreteInterval_t interval, F functor) |
template<typename F > | |
void | foreach (const interval_t interval, const size_type n, F functor) |
Static Public Member Functions | |
static value_type | epsilon () |
Get the value of the machine epsilon, useful for floating types comparison. More... | |
static value_type | infinity () |
Get the value that symbolizes positive infinity. More... | |
Static Public Attributes | |
static const flag_t | flags = ROBOPTIM_IS_FUNCTION |
Flag representing the Roboptim Function type. More... | |
Protected Member Functions | |
GenericFunction (size_type inputSize, size_type outputSize=1, std::string name=std::string()) | |
Concrete class constructor should call this constructor. More... | |
virtual void | impl_compute (result_ref result, const_argument_ref argument) const =0 |
Function evaluation. 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) |
Construct an interval from a lower and upper bound. More... | |
static interval_t | makeInfiniteInterval () |
Construct an infinite interval. More... | |
static interval_t | makeLowerInterval (value_type l) |
Construct an interval from a lower bound. More... | |
static interval_t | makeUpperInterval (value_type u) |
Construct an interval from an upper bound. More... | |
static value_type | getLowerBound (const interval_t &interval) |
Get the lower bound of an interval. More... | |
static value_type | getUpperBound (const interval_t &interval) |
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... | |
template<class ExpectedType > | |
ExpectedType * | castInto (bool check=false) |
Cast function to ExpectedType. More... | |
template<class ExpectedType > | |
const ExpectedType * | castInto (bool check=false) const |
Cast function to ExpectedType (const). More... | |
template<class ExpectedType > | |
bool | asType () const |
Fonction type checking. 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 value_type | getLowerBound (const discreteInterval_t &interval) |
Get the lower bound of a discrete interval. More... | |
static value_type | getUpperBound (const discreteInterval_t &interval) |
Get the upper bound of a discrete interval. More... | |
static value_type | getStep (const discreteInterval_t &interval) |
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... | |
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.
T | Matrix type |
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:
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.
typedef std::vector<interval_t> roboptim::GenericFunction< T >::intervals_t |
Vector of intervals.
typedef std::string roboptim::GenericFunction< T >::name_t |
Type of a function argument name.
typedef std::vector<name_t> roboptim::GenericFunction< T >::names_t |
Type of a vector of function argument names.
typedef GenericFunctionTraits<T>::size_type roboptim::GenericFunction< T >::size_type |
Size type.
This type is used to represent sizes, indexes, etc.
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.
typedef GenericFunctionTraits<T>::value_type roboptim::GenericFunction< T >::value_type |
Values type.
Represents the numerical type (i.e. float, double, int...) used for computations.
|
virtual |
Trivial destructor.
|
protected |
Concrete class constructor should call this constructor.
inputSize | function arity |
outputSize | result size |
name | function's name |
std::runtime_error |
bool roboptim::GenericFunction< T >::asType | ( | ) | const |
Fonction type checking.
ExpectedType | type the function could be compatible with |
ExpectedType * roboptim::GenericFunction< T >::castInto | ( | bool | check = false | ) |
Cast function to ExpectedType.
ExpectedType | type we want to cast the function into. |
check | check that the cast is valid, and throws if it is not. |
const ExpectedType * roboptim::GenericFunction< T >::castInto | ( | bool | check = false | ) | const |
Cast function to ExpectedType (const).
ExpectedType | type we want to cast the function into. |
check | check that the cast is valid, and throws if it is not. |
|
static |
Get the value of the machine epsilon, useful for floating types comparison.
void roboptim::GenericFunction< T >::foreach | ( | const discreteInterval_t | interval, |
F | functor | ||
) |
void roboptim::GenericFunction< T >::foreach | ( | const interval_t | interval, |
const size_type | n, | ||
F | functor | ||
) |
|
static |
Iterate on an interval.
Call the functor to each discretization point of the discrete interval.
interval | interval on which the method iterates |
functor | unary function that will be applied |
F | functor type (has to satisfy the STL unary function concept) |
|
static |
Iterate on an interval.
Call the functor regularly n times on an interval.
interval | interval on which the method iterates |
n | number of discretization points |
functor | unary function that will be applied |
F | functor type (has to satisfy the STL unary function concept) |
|
virtual |
Get the type-checking flag.
|
static |
Get the lower bound of an interval.
interval | accessed interval |
|
static |
Get the lower bound of a discrete interval.
interval | accessed discrete interval |
const std::string & roboptim::GenericFunction< T >::getName | ( | ) | const |
Get function name.
Referenced by roboptim::GenericFiniteDifferenceGradient< T, FdgPolicy >::generateName(), roboptim::visualization::gnuplot::plot(), roboptim::visualization::matplotlib::plot(), roboptim::visualization::gnuplot::plot_jac(), and roboptim::visualization::gnuplot::plot_xy().
|
static |
Get the upper step of a discrete interval.
interval | accessed discrete interval |
|
static |
Get the upper bound of an interval.
interval | accessed interval |
|
static |
Get the upper bound of a discrete interval.
interval | accessed discrete interval |
|
protectedpure virtual |
Function evaluation.
Evaluate the function, has to be implemented in concrete classes.
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::GenericNumericQuadraticFunction< T >, roboptim::GenericNumericLinearFunction< T >, roboptim::GenericConstantFunction< T >, roboptim::GenericSumOfC1Squares< T >, roboptim::GenericIdentityFunction< T >, roboptim::Polynomial< T >, roboptim::Cos< T >, and roboptim::Sin< T >.
|
static |
Get the value that symbolizes positive infinity.
Referenced by roboptim::Problem< T >::constraintsViolationVector(), and roboptim::Result::print().
GenericFunction< T >::size_type roboptim::GenericFunction< T >::inputSize | ( | ) | const |
Return the input size (i.e.
argument's vector size).
Referenced by roboptim::finiteDifferenceGradientPolicies::Simple< T >::computeGradient(), roboptim::finiteDifferenceGradientPolicies::Policy< T >::computeJacobian(), roboptim::GenericTwiceDifferentiableFunction< T >::hessianSize(), roboptim::Problem< T >::jacobian(), roboptim::visualization::gnuplot::plot(), roboptim::visualization::matplotlib::plot(), and roboptim::visualization::gnuplot::plot_xy().
bool roboptim::GenericFunction< T >::isValidResult | ( | const_result_ref | result | ) | const |
Check the given result size is valid.
result | result that will be checked |
|
static |
Construct a discrete interval.
min | miminum value of the interval |
max | maxinum value of the interval |
step | discretization step |
|
static |
Construct a discrete interval.
interval | continuous interval |
step | discretization step |
|
static |
Construct an infinite interval.
|
static |
Construct an interval from a lower and upper bound.
l | lower bound |
u | upper bound |
|
static |
Construct an interval from a lower bound.
l | lower bound |
|
static |
Construct an interval from an upper bound.
u | upper bound |
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.
argument | point at which the function will be evaluated |
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.
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::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().
GenericFunction< T >::size_type roboptim::GenericFunction< T >::outputSize | ( | ) | const |
Return the output size (i.e.
result's vector size).
Referenced by roboptim::visualization::gnuplot::plot(), roboptim::visualization::matplotlib::plot(), and roboptim::visualization::gnuplot::plot_xy().
|
virtual |
Display the function on the specified output stream.
o | output stream used for display |
Reimplemented in roboptim::GenericFiniteDifferenceGradient< T, FdgPolicy >, roboptim::GenericDifferentiableFunction< T >, roboptim::NTimesDerivableFunction< 2 >, roboptim::GenericTwiceDifferentiableFunction< T >, roboptim::GenericNumericQuadraticFunction< T >, roboptim::GenericConstantFunction< T >, roboptim::GenericNumericLinearFunction< T >, roboptim::Polynomial< T >, roboptim::GenericIdentityFunction< T >, roboptim::GenericLinearFunction< T >, roboptim::GenericQuadraticFunction< T >, roboptim::Cos< T >, and roboptim::Sin< T >.
References roboptim::indent().
roboptim::GenericFunction< T >::ROBOPTIM_DEFINE_FLAG_TYPE | ( | ) |
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.
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).
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.
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ | ( | result | ) |
Type of a function evaluation result.
roboptim::GenericFunction< T >::ROBOPTIM_GENERATE_TRAITS_REFS_ | ( | argument | ) |
Type of a function evaluation argument.
|
static |
Flag representing the Roboptim Function type.