CAPD DynSys Library  5.2.0
capd::map::Function< VectorType > Class Template Reference

Class Function represents a function $ R^n\to R$. More...

#include <capd/map/Function.h>

Public Types

typedef VectorType::ScalarType ScalarType
 
typedef BasicFunction< ScalarTypeBaseFunction
 
typedef BaseFunction::size_type size_type
 
typedef capd::autodiff::DagIndexer< ScalarTypeDAG
 
typedef capd::autodiff::Node NodeType
 

Public Member Functions

 Function ()
 creates an univariate constant function f(x)=0 More...
 
 Function (const std::string &s)
 parses expression from given string. Allocates memory for ODE solver of order 'order' More...
 
 Function (const char *s)
 parses expression from given string. Allocates memory for ODE solver of order 'order' More...
 
 Function (const Function &f)
 copying constructor More...
 
template<typename Functional >
 Function (Functional f, int dimIn, int noParam, size_type degree=1)
 parses expression from given routine. More...
 
Functionoperator= (const std::string &)
 substitution from string. Parse expression and compute new DAG. More...
 
Functionoperator= (const char *)
 substitution from string. Parse expression and compute new DAG. More...
 
Functionoperator= (const Function &f)
 assignment from an object More...
 
ScalarType operator() (const ScalarType &v) const
 evaluates function (for univariate case) More...
 
ScalarType operator() (const VectorType &v) const
 evaluates function at a given vector More...
 
VectorType gradient (VectorType u) const
 returns gradient of the function computed at vector u More...
 
void setParameters (const VectorType &values)
 simultaneously sets values of many parameters. It is assumed that given vector contains values of subsequent parameters. More...
 
void setOrder (size_type)
 allocates necessary memory for ODE solver of order 'order' More...
 
void setParameter (size_type d, const VectorType::ScalarType &value)
 sets new value of a parameter of index d. More...
 
void setParameter (const std::string &name, const ScalarType &value)
 sets new value of a parameter. If parameter not found there is no effect. More...
 
void setParameters (const VectorType::ScalarType *values, size_type d)
 simultaneously sets values of many parameters. It is assumed that given vector contains values of subsequent parameters. More...
 
ScalarType getParameter (size_type d) const
 
ScalarType getParameter (const std::string &name) const
 
void setCurrentTime (const ScalarType &a_time) const
 sets actual value of variable that represents time in an ODE. More...
 
const ScalarTypegetCurrentTime () const
 returns actual value of variable that represents time in an ODE More...
 
void differentiateTime () const
 sets first derivative of time with respect to time equal to 1 More...
 
void setMask (Iterator b, Iterator e)
 The iterator range [b,e) should contain a range of Multiinideces the user requires to compute. More...
 
void addMultiindexToMask (const capd::vectalg::Multiindex &mi)
 Adds new multiindex (along with dependencies) to the existing mask. More...
 
void resetMask ()
 Resets the mask of derivatives. More...
 
const boolgetMask () const
 
bool getMask (size_type i) const
 
bool getMask (size_type i, size_type j) const
 

Protected Member Functions

void check (const std::string &s)
 
void reset (Function f, int dimIn, int dimOut, int noParam)
 parses expression from given routine. More...
 
void createDefault ()
 used to create a default object without expression. Creates a univariate constant function f(x)=0 More...
 
void createFromText (std::string s)
 parses expression from given string. Allocates memory for ODE solver of order 'order' More...
 
void copyObject (const BasicFunction &f)
 an auxiliary function used in copying constructor and assignment operator More...
 
void clean ()
 resets all allocated data More...
 
void realloc (size_type degree)
 reallocates memory for computation of derivatives up to order 'degree' More...
 
void setArgument (const V &v) const
 
void applyC1Mask () const
 
void evalHomogenousPolynomial () const
 
void evalHomogenousPolynomial (size_type degree, size_type coeffNo=0) const
 
void eval (size_type coeffNo) const
 
void eval (size_type degree, size_type coeffNo) const
 
void deleteNodes ()
 

Protected Attributes

std::vector< capd::autodiff::AbstractNode< ScalarType > * > m_nodes
 
std::vector< capd::autodiff::Nodem_fullGraph
 graph representing the expression More...
 
std::vector< capd::autodiff::MyNodem_evalPath
 reduced graph - only nodes with nontrivial evaluations are left More...
 
std::vector< intm_pos
 indices of roots of expressions for each component More...
 
std::vector< std::string > m_var
 variables, time and parameters More...
 
DAG m_dag
 data structure that stores all the coefficients. Provides suitable indexing and evaluation of expression. More...
 
size_type m_indexOfFirstParam
 if equal to m_var.size() then no parameters specified More...
 

Detailed Description

template<typename VectorType>
class capd::map::Function< VectorType >

Class Function represents a function $ R^n\to R$.

It provides methods for computation of value, gradient and normalized derivatives (Taylor coefficients) of this function at a given point.

The function is internally represented as an optimized array that encodes Direct Acyclic Graph associated to the expression defining function. The expression defining function can be specified as a human readable string or a routine.

The template parameter is a Vector that satisfies capd::vectalg::Vector interface. This includes:

  • vectors of variable length. They give flexibility but they are slower due to memory allocations and deallocations. Recommended for short programs.
  • vectors of fixed length - they are allocated on stack instead of storage (dynamic allocation) and thus tey are fast. Recommended for programs running long time.
  • arbitrary precision vectors - with static and dynamic allocation

Member Typedef Documentation

◆ BaseFunction

template<typename VectorType >
typedef BasicFunction<ScalarType> capd::map::Function< VectorType >::BaseFunction

◆ DAG

typedef capd::autodiff::DagIndexer<ScalarType> capd::map::BasicFunction< VectorType::ScalarType >::DAG
inherited

◆ NodeType

typedef capd::autodiff::Node capd::map::BasicFunction< VectorType::ScalarType >::NodeType
inherited

◆ ScalarType

template<typename VectorType >
typedef VectorType::ScalarType capd::map::Function< VectorType >::ScalarType

◆ size_type

template<typename VectorType >
typedef BaseFunction::size_type capd::map::Function< VectorType >::size_type

Constructor & Destructor Documentation

◆ Function() [1/5]

template<typename VectorType >
capd::map::Function< VectorType >::Function

creates an univariate constant function f(x)=0

◆ Function() [2/5]

template<typename VectorType >
capd::map::Function< VectorType >::Function ( const std::string &  s)

parses expression from given string. Allocates memory for ODE solver of order 'order'

◆ Function() [3/5]

template<typename VectorType >
capd::map::Function< VectorType >::Function ( const char *  s)

parses expression from given string. Allocates memory for ODE solver of order 'order'

◆ Function() [4/5]

template<typename VectorType >
capd::map::Function< VectorType >::Function ( const Function< VectorType > &  f)

copying constructor

◆ Function() [5/5]

template<typename VectorType >
template<typename Functional >
capd::map::Function< VectorType >::Function ( Functional  f,
int  dimIn,
int  noParam,
size_type  degree = 1 
)
inline

parses expression from given routine.

Allocates memory for jet propagation of degree 'degree'

Parameters
f- routine that defines function, its signature is: void (NodeType time, NodeType in[], int dimIn, NodeType out[], int dimOut, NodeType param[], int noParam)
dimIn- number of input variables (dimension of domain)
dimOut- number of output variables (dimension of codomain)
noParam- number of parameters

Member Function Documentation

◆ addMultiindexToMask()

void capd::map::BasicFunction< VectorType::ScalarType >::addMultiindexToMask ( const capd::vectalg::Multiindex mi)
inlineinherited

Adds new multiindex (along with dependencies) to the existing mask.

Parameters
mimultiindex to be added to the mask
Warning
causes undefined behavior if the mask has not been set before call to this method.

◆ applyC1Mask()

void capd::map::BasicFunction< VectorType::ScalarType >::applyC1Mask
protectedinherited

◆ check()

template<typename VectorType >
void capd::map::Function< VectorType >::check ( const std::string &  s)
protected

◆ clean()

void capd::map::BasicFunction< VectorType::ScalarType >::clean
protectedinherited

resets all allocated data

◆ copyObject()

void capd::map::BasicFunction< VectorType::ScalarType >::copyObject ( const BasicFunction< VectorType::ScalarType > &  f)
protectedinherited

an auxiliary function used in copying constructor and assignment operator

◆ createDefault()

void capd::map::BasicFunction< VectorType::ScalarType >::createDefault
protectedinherited

used to create a default object without expression. Creates a univariate constant function f(x)=0

◆ createFromText()

void capd::map::BasicFunction< VectorType::ScalarType >::createFromText ( std::string  s)
protectedinherited

parses expression from given string. Allocates memory for ODE solver of order 'order'

◆ deleteNodes()

void capd::map::BasicFunction< VectorType::ScalarType >::deleteNodes
protectedinherited

◆ differentiateTime()

void capd::map::BasicFunction< VectorType::ScalarType >::differentiateTime
inherited

sets first derivative of time with respect to time equal to 1

◆ eval() [1/2]

void capd::map::BasicFunction< VectorType::ScalarType >::eval ( size_type  coeffNo) const
inlineprotectedinherited

◆ eval() [2/2]

void capd::map::BasicFunction< VectorType::ScalarType >::eval ( size_type  degree,
size_type  coeffNo 
) const
inlineprotectedinherited

◆ evalHomogenousPolynomial() [1/2]

void capd::map::BasicFunction< VectorType::ScalarType >::evalHomogenousPolynomial
inlineprotectedinherited

◆ evalHomogenousPolynomial() [2/2]

void capd::map::BasicFunction< VectorType::ScalarType >::evalHomogenousPolynomial ( size_type  degree,
size_type  coeffNo = 0 
) const
inlineprotectedinherited

◆ getCurrentTime()

const VectorType::ScalarType & capd::map::BasicFunction< VectorType::ScalarType >::getCurrentTime
inherited

returns actual value of variable that represents time in an ODE

◆ getMask() [1/3]

const bool* capd::map::BasicFunction< VectorType::ScalarType >::getMask
inlineinherited

◆ getMask() [2/3]

bool capd::map::BasicFunction< VectorType::ScalarType >::getMask ( size_type  i) const
inlineinherited

◆ getMask() [3/3]

bool capd::map::BasicFunction< VectorType::ScalarType >::getMask ( size_type  i,
size_type  j 
) const
inlineinherited

◆ getParameter() [1/2]

BasicFunction< VectorType::ScalarType >::ScalarType capd::map::BasicFunction< VectorType::ScalarType >::getParameter ( const std::string &  name) const
inherited

◆ getParameter() [2/2]

BasicFunction< VectorType::ScalarType >::ScalarType capd::map::BasicFunction< VectorType::ScalarType >::getParameter ( size_type  d) const
inherited

◆ gradient()

template<typename VectorType >
VectorType capd::map::Function< VectorType >::gradient ( VectorType  u) const

returns gradient of the function computed at vector u

◆ operator()() [1/2]

template<typename VectorType >
Function< VectorType >::ScalarType capd::map::Function< VectorType >::operator() ( const ScalarType v) const

evaluates function (for univariate case)

◆ operator()() [2/2]

template<typename VectorType >
Function< VectorType >::ScalarType capd::map::Function< VectorType >::operator() ( const VectorType &  v) const

evaluates function at a given vector

◆ operator=() [1/3]

template<typename VectorType >
Function< VectorType > & capd::map::Function< VectorType >::operator= ( const char *  s)

substitution from string. Parse expression and compute new DAG.

◆ operator=() [2/3]

template<typename VectorType >
Function< VectorType > & capd::map::Function< VectorType >::operator= ( const Function< VectorType > &  f)

assignment from an object

◆ operator=() [3/3]

template<typename VectorType >
Function< VectorType > & capd::map::Function< VectorType >::operator= ( const std::string &  s)

substitution from string. Parse expression and compute new DAG.

◆ realloc()

void capd::map::BasicFunction< VectorType::ScalarType >::realloc ( size_type  degree)
protectedinherited

reallocates memory for computation of derivatives up to order 'degree'

◆ reset()

void capd::map::BasicFunction< VectorType::ScalarType >::reset ( Function  f,
int  dimIn,
int  dimOut,
int  noParam 
)
protectedinherited

parses expression from given routine.

Assignment of new function parsed from a routine.

Allocates memory for jet propagation of degree 'degree'

Parameters
f- routine that defines function, its signature is: void (NodeType time, NodeType in[], int dimIn, NodeType out[], int dimOut, NodeType param[], int noParam)
dimIn- number of input variables (dimension of domain)
dimOut- number of output variables (dimension of codomain)
noParam- number of parameters

◆ resetMask()

void capd::map::BasicFunction< VectorType::ScalarType >::resetMask
inlineinherited

Resets the mask of derivatives.

In consequence, full jet of derivatives will be computed after call to any method that computes derivative, hessian or jet.

◆ setArgument()

void capd::map::BasicFunction< VectorType::ScalarType >::setArgument ( const V &  v) const
protectedinherited

◆ setCurrentTime()

void capd::map::BasicFunction< VectorType::ScalarType >::setCurrentTime ( const ScalarType a_time) const
inherited

sets actual value of variable that represents time in an ODE.

◆ setMask()

void capd::map::BasicFunction< VectorType::ScalarType >::setMask ( Iterator  b,
Iterator  e 
)
inlineinherited

The iterator range [b,e) should contain a range of Multiinideces the user requires to compute.

The method automatically adds all the depending partial derivatives to this collection and defines a mask for computation of partial derivtives.

Parameters
[b,e)iterator range which contains collection of multiindices
Warning
The method causes undefined behavior if a multiindex in the collection exceeds limits of the map (like dimension, maximal allowed degree).

◆ setOrder()

void capd::map::BasicFunction< VectorType::ScalarType >::setOrder ( size_type  order)
inherited

allocates necessary memory for ODE solver of order 'order'

◆ setParameter() [1/2]

void capd::map::BasicFunction< VectorType::ScalarType >::setParameter ( const std::string &  name,
const ScalarType value 
)
inherited

sets new value of a parameter. If parameter not found there is no effect.

◆ setParameter() [2/2]

void capd::map::BasicFunction< VectorType::ScalarType >::setParameter ( size_type  d,
const VectorType::ScalarType &  value 
)
inherited

sets new value of a parameter of index d.

◆ setParameters() [1/2]

template<typename VectorType >
void capd::map::Function< VectorType >::setParameters ( const VectorType &  values)

simultaneously sets values of many parameters. It is assumed that given vector contains values of subsequent parameters.

◆ setParameters() [2/2]

void capd::map::BasicFunction< VectorType::ScalarType >::setParameters ( const VectorType::ScalarType *  values,
size_type  d 
)
inherited

simultaneously sets values of many parameters. It is assumed that given vector contains values of subsequent parameters.

Member Data Documentation

◆ m_dag

DAG capd::map::BasicFunction< VectorType::ScalarType >::m_dag
mutableprotectedinherited

data structure that stores all the coefficients. Provides suitable indexing and evaluation of expression.

◆ m_evalPath

std::vector<capd::autodiff::MyNode> capd::map::BasicFunction< VectorType::ScalarType >::m_evalPath
protectedinherited

reduced graph - only nodes with nontrivial evaluations are left

◆ m_fullGraph

std::vector<capd::autodiff::Node> capd::map::BasicFunction< VectorType::ScalarType >::m_fullGraph
protectedinherited

graph representing the expression

◆ m_indexOfFirstParam

size_type capd::map::BasicFunction< VectorType::ScalarType >::m_indexOfFirstParam
protectedinherited

if equal to m_var.size() then no parameters specified

◆ m_nodes

std::vector<capd::autodiff::AbstractNode<ScalarType>*> capd::map::BasicFunction< VectorType::ScalarType >::m_nodes
protectedinherited

◆ m_pos

std::vector<int> capd::map::BasicFunction< VectorType::ScalarType >::m_pos
protectedinherited

indices of roots of expressions for each component

◆ m_var

std::vector<std::string> capd::map::BasicFunction< VectorType::ScalarType >::m_var
protectedinherited

variables, time and parameters