DMP_BBO library
Public Member Functions | Friends | List of all members
ExponentialSystem Class Reference

Dynamical System modelling the evolution of an exponential system: $\dot{x} = -\alpha (x-x^g)$. More...

#include <ExponentialSystem.hpp>

Inheritance diagram for ExponentialSystem:
Inheritance graph
[legend]
Collaboration diagram for ExponentialSystem:
Collaboration graph
[legend]

Public Member Functions

 ExponentialSystem (double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, double alpha, std::string name="ExponentialSystem")
 Initialization constructor. More...
 
 ~ExponentialSystem (void)
 Destructor. More...
 
DynamicalSystemclone (void) const
 Return a pointer to a deep copy of the DynamicalSystem object. More...
 
void differentialEquation (const Eigen::Ref< const Eigen::VectorXd > &x, Eigen::Ref< Eigen::VectorXd > xd) const
 The differential equation which defines the system. More...
 
void analyticalSolution (const Eigen::VectorXd &ts, Eigen::MatrixXd &xs, Eigen::MatrixXd &xds) const
 Return analytical solution of the system at certain times. More...
 
double alpha (void) const
 Accessor function for decay constant. More...
 
std::string toString (void) const
 Returns a string representation of the object. More...
 
- Public Member Functions inherited from DynamicalSystem
 DynamicalSystem (int order, double tau, Eigen::VectorXd initial_state, Eigen::VectorXd attractor_state, std::string name)
 Initialization constructor. More...
 
virtual ~DynamicalSystem (void)
 Destructor.
 
virtual void integrateStart (Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd) const
 Start integrating the system. More...
 
void integrateStart (const Eigen::VectorXd &x_init, Eigen::Ref< Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > xd)
 Start integrating the system with a new initial state. More...
 
virtual void integrateStep (double dt, const Eigen::Ref< const Eigen::VectorXd > x, Eigen::Ref< Eigen::VectorXd > x_updated, Eigen::Ref< Eigen::VectorXd > xd_updated) const
 Integrate the system one time step. More...
 
void set_integration_method (IntegrationMethod integration_method)
 Choose the integration method. More...
 
int dim (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
int dim_orig (void) const
 Get the dimensionality of the dynamical system, i.e. More...
 
double tau (void) const
 Accessor function for the time constant. More...
 
virtual void set_tau (double tau)
 Mutator function for the time constant. More...
 
Eigen::VectorXd initial_state (void) const
 Accessor function for the initial state of the dynamical system. More...
 
void initial_state (Eigen::VectorXd &initial_state) const
 Accessor function for the initial state of the dynamical system. More...
 
virtual void set_initial_state (const Eigen::VectorXd &initial_state)
 Mutator function for the initial state of the dynamical system. More...
 
Eigen::VectorXd attractor_state (void) const
 Accessor function for the attractor state of the dynamical system. More...
 
void attractor_state (Eigen::VectorXd &attractor_state) const
 Accessor function for the attractor state of the dynamical system. More...
 
virtual void set_attractor_state (const Eigen::Ref< const Eigen::VectorXd > &attractor_state)
 Mutator function for the attractor state of the dynamical system. More...
 
std::string name (void) const
 Accessor function for the name of the dynamical system. More...
 
virtual void set_name (std::string name)
 Mutator function for the name of the dynamical system. More...
 

Friends

class boost::serialization::access
 Give boost serialization access to private members. More...
 

Additional Inherited Members

- Public Types inherited from DynamicalSystem
enum  IntegrationMethod { EULER, RUNGE_KUTTA }
 The possible integration methods that can be used. More...
 
- Protected Member Functions inherited from DynamicalSystem
 DynamicalSystem (void)
 Default constructor. More...
 
void set_dim (int dim)
 Set the dimensionality of the dynamical system, i.e. More...
 

Detailed Description

Dynamical System modelling the evolution of an exponential system: $\dot{x} = -\alpha (x-x^g)$.

http://en.wikipedia.org/wiki/Exponential_decay

http://en.wikipedia.org/wiki/Exponential_growth

Definition at line 42 of file ExponentialSystem.hpp.

Constructor & Destructor Documentation

ExponentialSystem ( double  tau,
Eigen::VectorXd  y_init,
Eigen::VectorXd  y_attr,
double  alpha,
std::string  name = "ExponentialSystem" 
)

Initialization constructor.

Parameters
tauTime constant, cf. DynamicalSystem::tau()
y_initInitial state, cf. DynamicalSystem::initial_state()
y_attrAttractor state, cf. DynamicalSystem::attractor_state()
alphaDecay constant, cf. ExponentialSystem::alpha()
nameName for the sytem, cf. DynamicalSystem::name()

Definition at line 50 of file ExponentialSystem.cpp.

51  : DynamicalSystem(1, tau, y_init, y_attr, name),
52  alpha_(alpha)
53 {
54  attractor_state_prealloc_ = VectorXd::Zero(dim_orig());
55 }
double tau(void) const
Accessor function for the time constant.
int dim_orig(void) const
Get the dimensionality of the dynamical system, i.e.
DynamicalSystem(void)
Default constructor.
std::string name(void) const
Accessor function for the name of the dynamical system.
double alpha(void) const
Accessor function for decay constant.

Here is the call graph for this function:

~ExponentialSystem ( void  )

Destructor.

Definition at line 57 of file ExponentialSystem.cpp.

58 {
59 }

Member Function Documentation

DynamicalSystem * clone ( void  ) const
virtual

Return a pointer to a deep copy of the DynamicalSystem object.

Returns
Pointer to a deep copy

Implements DynamicalSystem.

Definition at line 61 of file ExponentialSystem.cpp.

62 {
63  return new ExponentialSystem(tau(),initial_state(),attractor_state(),alpha_,name());
64 }
double tau(void) const
Accessor function for the time constant.
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.
ExponentialSystem(double tau, Eigen::VectorXd y_init, Eigen::VectorXd y_attr, double alpha, std::string name="ExponentialSystem")
Initialization constructor.
std::string name(void) const
Accessor function for the name of the dynamical system.
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.

Here is the call graph for this function:

void differentialEquation ( const Eigen::Ref< const Eigen::VectorXd > &  x,
Eigen::Ref< Eigen::VectorXd >  xd 
) const
virtual

The differential equation which defines the system.

It relates state values to rates of change of those state values

Parameters
[in]xcurrent state (column vector of size dim() X 1)
[out]xdrate of change in state (column vector of size dim() X 1)
Remarks
x and xd should be of size dim() X 1. This forces you to pre-allocate memory, which speeds things up (and also makes Eigen's Ref functionality easier to deal with).

Implements DynamicalSystem.

Definition at line 67 of file ExponentialSystem.cpp.

70 {
71  ENTERING_REAL_TIME_CRITICAL_CODE
72  // xd = alpha_*(attractor_state()-x)/tau(); // Non-realtime version now commented out
73 
74  attractor_state(attractor_state_prealloc_);
75  xd.noalias() = alpha_*(attractor_state_prealloc_-x)/tau();
76 
77  EXITING_REAL_TIME_CRITICAL_CODE
78 }
double tau(void) const
Accessor function for the time constant.
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.

Here is the call graph for this function:

void analyticalSolution ( const Eigen::VectorXd &  ts,
Eigen::MatrixXd &  xs,
Eigen::MatrixXd &  xds 
) const
virtual

Return analytical solution of the system at certain times.

Parameters
[in]tsA vector of times for which to compute the analytical solutions
[out]xsSequence of state vectors. T x D or D x T matrix, where T is the number of times (the length of 'ts'), and D the size of the state (i.e. dim())
[out]xdsSequence of state vectors (rates of change). T x D or D x T matrix, where T is the number of times (the length of 'ts'), and D the size of the state (i.e. dim())
Remarks
The output xs and xds will be of size D x T only if the matrix x you pass as an argument of size D x T. In all other cases (i.e. including passing an empty matrix) the size of x will be T x D. This feature has been added so that you may pass matrices of either size.

Implements DynamicalSystem.

Definition at line 80 of file ExponentialSystem.cpp.

81 {
82  int T = ts.size();
83  assert(T>0);
84 
85  // Usually, we expect xs and xds to be of size T X dim(), so we resize to that. However, if the
86  // input matrices were of size dim() X T, we return the matrices of that size by doing a
87  // transposeInPlace at the end. That way, the user can also request dim() X T sized matrices.
88  bool caller_expects_transposed = (xs.rows()==dim() && xs.cols()==T);
89 
90  // Prepare output arguments to be of right size (Eigen does nothing if already the right size)
91  xs.resize(T,dim());
92  xds.resize(T,dim());
93 
94  VectorXd val_range = initial_state() - attractor_state();
95 
96  VectorXd exp_term = -alpha_*ts/tau();
97  exp_term = exp_term.array().exp().transpose();
98  VectorXd pos_scale = exp_term;
99  VectorXd vel_scale = -(alpha_/tau()) * exp_term;
100 
101  xs = val_range.transpose().replicate(T,1).array() * pos_scale.replicate(1,dim()).array();
102  xs += attractor_state().transpose().replicate(T,1);
103  xds = val_range.transpose().replicate(T,1).array() * vel_scale.replicate(1,dim()).array();
104 
105  if (caller_expects_transposed)
106  {
107  xs.transposeInPlace();
108  xds.transposeInPlace();
109  }
110 }
double tau(void) const
Accessor function for the time constant.
Eigen::VectorXd initial_state(void) const
Accessor function for the initial state of the dynamical system.
int dim(void) const
Get the dimensionality of the dynamical system, i.e.
Eigen::VectorXd attractor_state(void) const
Accessor function for the attractor state of the dynamical system.

Here is the call graph for this function:

double alpha ( void  ) const
inline

Accessor function for decay constant.

Returns
Decay constant

Definition at line 71 of file ExponentialSystem.hpp.

71  {
72  return alpha_;
73  }

Here is the call graph for this function:

string toString ( void  ) const
virtual

Returns a string representation of the object.

Returns
A string representation of the object.

Implements DynamicalSystem.

Definition at line 121 of file ExponentialSystem.cpp.

122 {
123  RETURN_STRING_FROM_BOOST_SERIALIZATION_XML("ExponentialSystem");
124 }
#define RETURN_STRING_FROM_BOOST_SERIALIZATION_XML(name)
Macro to convert the boost XML serialization of an object into a string.

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Give boost serialization access to private members.

Definition at line 94 of file ExponentialSystem.hpp.


The documentation for this class was generated from the following files: