bpp-core3
3.0.0
|
Numerical derivative function wrapper, partial implementation. More...
#include <Bpp/Numeric/Function/NumericalDerivative.h>
Public Member Functions | |
AbstractNumericalDerivative (std::shared_ptr< FunctionInterface > function) | |
AbstractNumericalDerivative (std::shared_ptr< FirstOrderDerivable > function) | |
AbstractNumericalDerivative (std::shared_ptr< SecondOrderDerivable > function) | |
AbstractNumericalDerivative (const AbstractNumericalDerivative &ad) | |
AbstractNumericalDerivative & | operator= (const AbstractNumericalDerivative &ad) |
virtual | ~AbstractNumericalDerivative () |
AbstractNumericalDerivative * | clone () const override=0 |
Create a copy of this object and send a pointer to it. More... | |
void | setInterval (double h) override |
Set the interval value used in numerical approximation. More... | |
double | getInterval () const override |
void | setParametersToDerivate (const std::vector< std::string > &variables) override |
Set the list of parameters to derivate numerically. More... | |
void | enableSecondOrderCrossDerivatives (bool yn) |
bool | enableSecondOrderCrossDerivatives () const |
virtual double | d2f (const std::string &variable, const ParameterList ¶meters) |
Get the value of the second order derivative of the function according to a given set of parameters. More... | |
virtual double | d2f (const std::string &variable1, const std::string &variable2, const ParameterList ¶meters) |
Get the value of the cross derivative of the function according to a given set of parameters. More... | |
virtual double | df (const std::string &variable, const ParameterList ¶meters) |
Get the value of the first derivative of the function according to a given set of parameters. More... | |
virtual double | getValue () const =0 |
Get the value of the function at the current point. More... | |
virtual bool | hasParameter (const std::string &name) const =0 |
Tell if there is a parameter with specified name. More... | |
virtual const ParameterList & | getParameters () const =0 |
Get all parameters available. More... | |
virtual const Parameter & | parameter (const std::string &name) const =0 |
Get the parameter with specified name. More... | |
virtual double | getParameterValue (const std::string &name) const =0 |
Get the value for parameter of name 'name'. More... | |
virtual void | removeConstraint (const std::string &name)=0 |
Remove the constraint associated with one parameter, if any. More... | |
virtual void | setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint)=0 |
Set/Change the constraint associated with one parameter. More... | |
virtual size_t | getNumberOfParameters () const =0 |
Get the number of parameters. More... | |
virtual void | setNamespace (const std::string &prefix)=0 |
Set the namespace for the parameter names. More... | |
virtual std::string | getNamespace () const =0 |
virtual std::string | getParameterNameWithoutNamespace (const std::string &name) const =0 |
Resolves a parameter name according to the current namespace. More... | |
bool | hasParameter (const std::string &name) const override |
Tell if there is a parameter with specified name. More... | |
const ParameterList & | getParameters () const override |
Get all parameters available. More... | |
const Parameter & | parameter (const std::string &name) const override |
Get the parameter with specified name. More... | |
double | getValue () const override |
Get the value of the function at the current point. More... | |
double | getParameterValue (const std::string &name) const override |
Get the value for parameter of name 'name'. More... | |
void | removeConstraint (const std::string &name) override |
Remove the constraint associated with one parameter, if any. More... | |
void | setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override |
Set/Change the constraint associated with one parameter. More... | |
size_t | getNumberOfParameters () const override |
Get the number of parameters. More... | |
void | setNamespace (const std::string &prefix) override |
Set the namespace for the parameter names. More... | |
std::string | getNamespace () const override |
std::string | getParameterNameWithoutNamespace (const std::string &name) const override |
Resolves a parameter name according to the current namespace. More... | |
The DerivableFirstOrder interface | |
void | enableFirstOrderDerivatives (bool yn) override |
Tell if derivatives must be computed. More... | |
bool | enableFirstOrderDerivatives () const override |
Tell if derivatives must be computed. More... | |
double | getFirstOrderDerivative (const std::string &variable) const override |
Get the derivative of the function at the current point. More... | |
The DerivableSecondOrder interface | |
void | enableSecondOrderDerivatives (bool yn) override |
Tell if derivatives must be computed. More... | |
bool | enableSecondOrderDerivatives () const override |
Tell if derivatives must be computed. More... | |
double | getSecondOrderDerivative (const std::string &variable) const override |
Get the second order derivative of the function at the current point. More... | |
double | getSecondOrderDerivative (const std::string &variable1, const std::string &variable2) const override |
Get the value of the cross derivative of the function according to a given set of parameters. More... | |
The Parametrizable interface. | |
double | f (const ParameterList ¶meters) override |
Get the value of the function according to a given set of parameters. More... | |
void | setParameters (const ParameterList ¶meters) override |
Set the point where the function must be computed. More... | |
void | setAllParametersValues (const ParameterList ¶meters) override |
Set the parameters values to be equals to those of parameters. More... | |
void | setParameterValue (const std::string &name, double value) override |
Set the value of parameter with name name to be equal to value. More... | |
void | setParametersValues (const ParameterList ¶meters) override |
Update the parameters from parameters. More... | |
bool | matchParametersValues (const ParameterList ¶meters) override |
Update the parameters from parameters. More... | |
Protected Member Functions | |
virtual void | updateDerivatives (const ParameterList ¶meters)=0 |
Compute derivatives. More... | |
virtual ParameterList & | getParameters_ ()=0 |
Get all parameters available. More... | |
ParameterList & | getParameters_ () override |
Get all parameters available. More... | |
Protected Attributes | |
std::shared_ptr< FirstOrderDerivable > | function1_ |
std::shared_ptr< SecondOrderDerivable > | function2_ |
double | h_ |
std::vector< std::string > | variables_ |
std::map< std::string, size_t > | index_ |
std::vector< double > | der1_ |
std::vector< double > | der2_ |
RowMatrix< double > | crossDer2_ |
bool | computeD1_ |
bool | computeD2_ |
bool | computeCrossD2_ |
std::shared_ptr< FunctionInterface > | function_ |
Numerical derivative function wrapper, partial implementation.
This class provides a wrapper for Function object, implementing the DerivableSecondOrder interface (Although no cross derivative is implemented for now). Derivations of this class can be used as full DerivableSecondOrder objects, with derivative functions.
Three kinds of constructors are provided: one with a Function object, another with a DerivableFirstOrder object, and one with a DerivableSecondOrder object. In the first case, all derivatives will be computed numerically. In the second case, first order derivative will be computed numerically only if no appropriate analytical derivative is available, second order derivative will always be computed numerically. In the last case, first and second order derivative will be computed numerically only if no appropriate analytical derivative is available.
Definition at line 64 of file NumericalDerivative.h.
|
inline |
Definition at line 80 of file NumericalDerivative.h.
|
inline |
Definition at line 85 of file NumericalDerivative.h.
|
inline |
Definition at line 90 of file NumericalDerivative.h.
|
inline |
Definition at line 95 of file NumericalDerivative.h.
|
inlinevirtual |
Definition at line 117 of file NumericalDerivative.h.
References bpp::SecondOrderDerivable::clone().
|
overridepure virtual |
Create a copy of this object and send a pointer to it.
Implements bpp::SecondOrderDerivable.
Implemented in bpp::ThreePointsNumericalDerivative, bpp::FivePointsNumericalDerivative, and bpp::TwoPointsNumericalDerivative.
|
inlinevirtualinherited |
Get the value of the second order derivative of the function according to a given set of parameters.
variable | The name of the variable in . |
parameters | The parameter set to pass to the function. |
Exception | If an error occured. |
Definition at line 193 of file Functions.h.
References bpp::FunctionInterface::setParameters().
|
inlinevirtualinherited |
Get the value of the cross derivative of the function according to a given set of parameters.
variable1 | The name of the variable in . |
variable2 | The name of the variable in . |
parameters | The parameter set to pass to the function. |
Exception | If an error occured. |
Definition at line 220 of file Functions.h.
References bpp::FunctionInterface::setParameters().
|
inlinevirtualinherited |
Get the value of the first derivative of the function according to a given set of parameters.
variable | The name of the variable in . |
parameters | The parameter set to pass to the function. |
Exception | If an error occured. |
Definition at line 138 of file Functions.h.
References bpp::FunctionInterface::setParameters().
|
inlineoverridevirtual |
Tell if derivatives must be computed.
yn | yes/no |
Implements bpp::FirstOrderDerivable.
Definition at line 144 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Tell if derivatives must be computed.
Implements bpp::FirstOrderDerivable.
Definition at line 145 of file NumericalDerivative.h.
|
inline |
Definition at line 235 of file NumericalDerivative.h.
|
inline |
Definition at line 236 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Tell if derivatives must be computed.
yn | yes/no |
Implements bpp::SecondOrderDerivable.
Definition at line 165 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Tell if derivatives must be computed.
Implements bpp::SecondOrderDerivable.
Definition at line 166 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Get the value of the function according to a given set of parameters.
parameters | The parameter set to pass to the function. |
Exception | If an error occured. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 199 of file NumericalDerivative.h.
References bpp::FunctionInterface::getValue(), and bpp::FunctionInterface::setParameters().
|
inlineoverridevirtual |
Get the derivative of the function at the current point.
variable | The name of the variable in . |
Exception | If no point is specified or if an error occured. |
Implements bpp::FirstOrderDerivable.
Definition at line 147 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Implements bpp::NumericalDerivativeInterface.
Definition at line 124 of file NumericalDerivative.h.
|
pure virtualinherited |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Implements bpp::Parametrizable.
Definition at line 322 of file Functions.h.
|
pure virtualinherited |
Get the number of parameters.
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, bpp::AbstractParametrizable, and bpp::DirectionFunction.
Referenced by bpp::BppODiscreteDistributionFormat::writeDiscreteDistribution(), and bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Get the number of parameters.
Implements bpp::Parametrizable.
Definition at line 312 of file Functions.h.
|
pure virtualinherited |
Resolves a parameter name according to the current namespace.
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), bpp::BppOParametrizableFormat::write(), and bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Resolves a parameter name according to the current namespace.
Implements bpp::Parametrizable.
Definition at line 327 of file Functions.h.
|
pure virtualinherited |
Get all parameters available.
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, bpp::DirectionFunction, and bpp::AbstractParametrizable.
Referenced by bpp::ParameterAliasableAdapter::getIndependentParameters(), bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), bpp::BppOParametrizableFormat::write(), and bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Get all parameters available.
Implements bpp::Parametrizable.
Definition at line 257 of file Functions.h.
|
protectedpure virtualinherited |
Get all parameters available.
Implemented in bpp::FunctionWrapper, bpp::AbstractParametrizable, and bpp::DirectionFunction.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverrideprotectedvirtualinherited |
Get all parameters available.
Implements bpp::Parametrizable.
Definition at line 333 of file Functions.h.
|
pure virtualinherited |
Get the value for parameter of name 'name'.
name | The name of the parameter. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), and bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Get the value for parameter of name 'name'.
name | The name of the parameter. |
Implements bpp::Parametrizable.
Definition at line 277 of file Functions.h.
|
inlineoverridevirtual |
Get the second order derivative of the function at the current point.
variable | The name of the variable in . |
Exception | If no point is specified or if an error occured. |
Implements bpp::SecondOrderDerivable.
Reimplemented in bpp::TwoPointsNumericalDerivative.
Definition at line 168 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Get the value of the cross derivative of the function according to a given set of parameters.
variable1 | The name of the variable in . |
variable2 | The name of the variable in . |
Exception | If an error occured. |
Implements bpp::SecondOrderDerivable.
Reimplemented in bpp::TwoPointsNumericalDerivative.
Definition at line 180 of file NumericalDerivative.h.
|
pure virtualinherited |
Get the value of the function at the current point.
Exception | If no point is specified or if an error occured. |
Implemented in bpp::TestFunction, bpp::InfinityFunctionWrapper, bpp::FunctionWrapper, bpp::LogsumHmmLikelihood, bpp::RescaledHmmLikelihood, bpp::LowMemoryRescaledHmmLikelihood, bpp::ReparametrizationFunctionWrapper, bpp::ThreePointsNumericalDerivative, bpp::FivePointsNumericalDerivative, bpp::TwoPointsNumericalDerivative, and bpp::DirectionFunction.
Referenced by bpp::FunctionInterface::f(), f(), bpp::InfinityFunctionWrapper::f(), and bpp::FunctionInterface::~FunctionInterface().
|
inlineoverridevirtualinherited |
Get the value of the function at the current point.
Exception | If no point is specified or if an error occured. |
Implements bpp::FunctionInterface.
Reimplemented in bpp::InfinityFunctionWrapper, bpp::ThreePointsNumericalDerivative, and bpp::TwoPointsNumericalDerivative.
Definition at line 267 of file Functions.h.
|
pure virtualinherited |
Tell if there is a parameter with specified name.
name | The name of the parameter to look for. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Tell if there is a parameter with specified name.
name | The name of the parameter to look for. |
Implements bpp::Parametrizable.
Definition at line 247 of file Functions.h.
|
inlineoverridevirtual |
Update the parameters from parameters.
Only common parameters with parameters will be updated.
parameters | A list of parameters. |
ConstraintException | If a value in parameters does not match the constraint in the corresponding parameter in the list. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 227 of file NumericalDerivative.h.
|
inline |
Definition at line 100 of file NumericalDerivative.h.
References computeCrossD2_, computeD1_, computeD2_, crossDer2_, der1_, der2_, function1_, function2_, h_, index_, bpp::FunctionWrapper::operator=(), and variables_.
|
pure virtualinherited |
Get the parameter with specified name.
name | The name of the parameter to look for. |
ParameterNotFoundException | if no parameter with this name is found. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::TestFunction::getValue(), and bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Get the parameter with specified name.
name | The name of the parameter to look for. |
ParameterNotFoundException | if no parameter with this name is found. |
Implements bpp::Parametrizable.
Definition at line 262 of file Functions.h.
|
pure virtualinherited |
Remove the constraint associated with one parameter, if any.
name | The name of the parameter to look for. |
ParameterNotFoundException | if no parameter with this name is found. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Remove the constraint associated with one parameter, if any.
name | The name of the parameter to look for. |
ParameterNotFoundException | if no parameter with this name is found. |
Implements bpp::Parametrizable.
Definition at line 302 of file Functions.h.
|
inlineoverridevirtual |
Set the parameters values to be equals to those of parameters.
The list must contain exactly the same parameters (ie same names) than the parameters available.
parameters | A list with all parameters. |
ParameterNotFoundException | If a some parameter in the list is not in params. |
ConstraintException | If a value in parameters does not match the constraint in the corresponding parameter in the list. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 209 of file NumericalDerivative.h.
|
pure virtualinherited |
Set/Change the constraint associated with one parameter.
name | The name of the parameter to look for. |
constraint | A pointer to the constraint (may be null) |
ParameterNotFoundException | if no parameter with this name is found. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, and bpp::AbstractParametrizable.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Set/Change the constraint associated with one parameter.
name | The name of the parameter to look for. |
constraint | A pointer to the constraint (may be null) |
ParameterNotFoundException | if no parameter with this name is found. |
Implements bpp::Parametrizable.
Definition at line 307 of file Functions.h.
|
inlineoverridevirtual |
Set the interval value used in numerical approximation.
Default value is 0.0001.
h | Interval value. |
Implements bpp::NumericalDerivativeInterface.
Definition at line 122 of file NumericalDerivative.h.
|
pure virtualinherited |
Set the namespace for the parameter names.
prefix | The 'namespace', that is a prefix to add to all parameter names. If parameter names are already prefixed, the new prefix will be used instead. |
Implemented in bpp::FunctionWrapper, bpp::ParametrizableAdapter, bpp::LogsumHmmLikelihood, bpp::RescaledHmmLikelihood, bpp::LowMemoryRescaledHmmLikelihood, bpp::AbstractParameterAliasable, bpp::MixtureOfDiscreteDistributions, bpp::AbstractParametrizable, and bpp::InvariantMixedDiscreteDistribution.
Referenced by bpp::Parametrizable::~Parametrizable().
|
inlineoverridevirtualinherited |
Set the namespace for the parameter names.
prefix | The 'namespace', that is a prefix to add to all parameter names. If parameter names are already prefixed, the new prefix will be used instead. |
Implements bpp::Parametrizable.
Definition at line 317 of file Functions.h.
|
inlineoverridevirtual |
Set the point where the function must be computed.
parameters | The parameter set to pass to the function. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 204 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Set the list of parameters to derivate numerically.
variables | A list of all parameter names. |
Implements bpp::NumericalDerivativeInterface.
Definition at line 126 of file NumericalDerivative.h.
References bpp::RowMatrix< Scalar >::resize().
|
inlineoverridevirtual |
Update the parameters from parameters.
parameters must be a subset of all parameters available.
parameters | A list containing all parameters to update. |
ParameterNotFoundException | If a some parameter in params is not in the list. |
ConstraintException | If a value in parameters does not match the constraint in the corresponding parameter in the list. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 221 of file NumericalDerivative.h.
|
inlineoverridevirtual |
Set the value of parameter with name name to be equal to value.
name | the name of the parameter to set. |
value | The value of the parameter. |
ParameterNotFoundException | If no parameter in the list has the name name. |
ConstraintException | If value does not match the constraint associated to parameter name. |
Reimplemented from bpp::FunctionWrapper.
Definition at line 215 of file NumericalDerivative.h.
|
protectedpure virtual |
Compute derivatives.
parameters | The point where to compute derivatives. It is NOT passed as references, as the inner parameters of the function will be changed when computing the numerical derivatives. |
Implemented in bpp::ThreePointsNumericalDerivative, bpp::FivePointsNumericalDerivative, and bpp::TwoPointsNumericalDerivative.
|
protected |
Definition at line 77 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 77 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 77 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 76 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 74 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 75 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 69 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 70 of file NumericalDerivative.h.
Referenced by operator=().
|
protectedinherited |
Definition at line 235 of file Functions.h.
Referenced by bpp::FunctionWrapper::operator=().
|
protected |
Definition at line 71 of file NumericalDerivative.h.
Referenced by operator=().
|
mutableprotected |
Definition at line 73 of file NumericalDerivative.h.
Referenced by operator=().
|
protected |
Definition at line 72 of file NumericalDerivative.h.
Referenced by operator=().