bpp-core3  3.0.0
bpp::NumTools Class Reference

Some utilitary function for numerical calculus. More...

#include <Bpp/Numeric/NumTools.h>

Static Public Member Functions

template<class T >
static T abs (T a)
 Get the magnitude of a value. More...
 
template<class T >
static T sign (T a)
 Get the sign of a value. More...
 
template<class T >
static T max (T a, T b)
 Get the max between 2 values. More...
 
template<class T >
static T min (T a, T b)
 Get the min between 2 values. More...
 
template<class T >
static T sign (T a, T b)
 Get the magnitude of a times the sign of b. More...
 
template<class T >
static T sqr (T a)
 Get the square of a number. More...
 
template<class T >
static T logsum (T lnx, T lny)
 Compute the logarithm of a sum from the sum of logarithms. More...
 
template<class T >
static void swap (T &a, T &b)
 
template<class T >
static void shift (T &a, T &b, T c)
 
template<class T >
static void shift (T &a, T &b, T &c, T d)
 
template<class T >
static T fact (T n)
 
template<class T >
static T logFact (T n)
 
static double uniRoot (FunctionInterface &f, const std::string &param, double a, double b, double tolerance)
 Find one root of the given function. More...
 
static std::unique_ptr< RowMatrix< double > > computeHessianMatrix (SecondOrderDerivable &function, const ParameterList &parameters)
 Compute the Hessian matrix for a function at a given point. More...
 

Detailed Description

Some utilitary function for numerical calculus.

Definition at line 19 of file NumTools.h.

Member Function Documentation

◆ abs()

template<class T >
static T bpp::NumTools::abs ( a)
inlinestatic

Get the magnitude of a value.

This template function may work with any type for which the operators < and - are defined.

Parameters
aThe value for which the magnitude must be returned.
Returns
The magnitude of the value a.

Definition at line 31 of file NumTools.h.

Referenced by bpp::OneDimensionOptimizationTools::bracketMinimum(), bpp::GoldenSectionSearch::doInit(), bpp::BrentOneDimension::doStep(), bpp::GoldenSectionSearch::GSSStopCondition::getCurrentTolerance(), bpp::PowellMultiDimensions::PMDStopCondition::getCurrentTolerance(), bpp::BrentOneDimension::BODStopCondition::getCurrentTolerance(), and bpp::DownhillSimplexMethod::DSMStopCondition::getCurrentTolerance().

◆ computeHessianMatrix()

unique_ptr< RowMatrix< double > > NumTools::computeHessianMatrix ( SecondOrderDerivable function,
const ParameterList parameters 
)
static

Compute the Hessian matrix for a function at a given point.

\[ H(f(\theta)) = \begin{pmatrix} \frac{\partial^2 f(\theta)}{\partial \theta_1^2} & \frac{\partial^2 f(\theta)}{\partial \theta_1 \partial \theta_2} & \cdots & \frac{\partial^2 f(\theta)}{\partial \theta_1 \partial \theta_n}\\ \frac{\partial^2 f(\theta)}{\partial \theta_2 \partial \theta_1} & \frac{\partial^2 f(\theta)}{\partial \theta_2^2} & \cdots & \frac{\partial^2 f(\theta)}{\partial \theta_2 \partial \theta_n}\\ \vdots & \vdots & \ddots & \vdots \\ \frac{\partial^2 f(\theta)}{\partial \theta_n \partial \theta_1} & \frac{\partial^2 f(\theta)}{\partial \theta_n \partial \theta_2} & \cdots & \frac{\partial^2 f(\theta)}{\partial \theta_n^2} \end{pmatrix} \]

Parameters
functionA function with second order derivatives.
parametersThe set of parameters for which to compute the hessian matrix.
Returns
A matrix with size equal to the number of parameters.

Definition at line 46 of file NumTools.cpp.

References bpp::ParameterList::getParameterNames(), and bpp::ParameterList::size().

Referenced by logFact().

◆ fact()

template<class T >
static T bpp::NumTools::fact ( n)
inlinestatic

Definition at line 124 of file NumTools.h.

References fact().

Referenced by fact().

◆ logFact()

template<class T >
static T bpp::NumTools::logFact ( n)
inlinestatic

Definition at line 128 of file NumTools.h.

References computeHessianMatrix(), logFact(), and uniRoot().

Referenced by logFact().

◆ logsum()

template<class T >
static T bpp::NumTools::logsum ( lnx,
lny 
)
inlinestatic

Compute the logarithm of a sum from the sum of logarithms.

The following formula is used:

\[ \ln(x) + \ln\left(1+ \exp\left(\ln(y) - \ln(x)\right)\right) = \ln(x + y) \]

see http://bozeman.genome.washington.edu/compbio/mbt599_2006/hmm_scaling_revised.pdf

Parameters
lnxThe value.
lnyThe power
Returns
$ ln(x+y) $.

Definition at line 96 of file NumTools.h.

Referenced by bpp::LogsumHmmLikelihood::computeBackward_(), and bpp::LogsumHmmLikelihood::computeForward_().

◆ max()

template<class T >
static T bpp::NumTools::max ( a,
b 
)
inlinestatic

Get the max between 2 values.

This template function may work with any type for which the operator

is defined.

Parameters
a,bThe two values to compare.
Returns
a if a > b, b else.

Definition at line 53 of file NumTools.h.

Referenced by bpp::OneDimensionOptimizationTools::bracketMinimum().

◆ min()

template<class T >
static T bpp::NumTools::min ( a,
b 
)
inlinestatic

Get the min between 2 values.

This template function may work with any type for which the operator < is defined.

Parameters
a,bThe two values to compare.
Returns
a if a < b, b else.

Definition at line 64 of file NumTools.h.

◆ shift() [1/2]

template<class T >
static void bpp::NumTools::shift ( T &  a,
T &  b,
c 
)
inlinestatic

Definition at line 112 of file NumTools.h.

Referenced by bpp::BrentOneDimension::doStep().

◆ shift() [2/2]

template<class T >
static void bpp::NumTools::shift ( T &  a,
T &  b,
T &  c,
d 
)
inlinestatic

Definition at line 117 of file NumTools.h.

◆ sign() [1/2]

template<class T >
static T bpp::NumTools::sign ( a)
inlinestatic

Get the sign of a value.

This template function may work with any type for which the operators < and == are defined.

Parameters
aThe value for which the sign must be returned.
Returns
-1 if a < 0, 0 if a = 0, 1 else.

Definition at line 42 of file NumTools.h.

Referenced by bpp::OneDimensionOptimizationTools::bracketMinimum(), and bpp::BrentOneDimension::doStep().

◆ sign() [2/2]

template<class T >
static T bpp::NumTools::sign ( a,
b 
)
inlinestatic

Get the magnitude of a times the sign of b.

Parameters
aThe value whose magnitude must be used.
bThe value whose sign must be used.
Returns
abs<T>(a) * sign<T>(b).

Definition at line 73 of file NumTools.h.

◆ sqr()

template<class T >
static T bpp::NumTools::sqr ( a)
inlinestatic

Get the square of a number.

Parameters
aThe value.
Returns
$ a^2 $.

Definition at line 81 of file NumTools.h.

Referenced by bpp::PowellMultiDimensions::doStep().

◆ swap()

template<class T >
static void bpp::NumTools::swap ( T &  a,
T &  b 
)
inlinestatic

Definition at line 105 of file NumTools.h.

◆ uniRoot()

double NumTools::uniRoot ( FunctionInterface f,
const std::string &  param,
double  a,
double  b,
double  tolerance 
)
static

Find one root of the given function.

Parameters
fThe function to analyse.
paramThe name of the parameter to solve.
aLower bound of initial interval.
bUpper bound of initial interval.
toleranceThe final precision requested.
Returns
The value of the parameter for which the function is zero.
Exceptions
ExceptionIf something bad happened or if the initial interval do not contains a root.

Definition at line 13 of file NumTools.cpp.

References bpp::ParameterList::addParameter(), and bpp::FunctionInterface::f().

Referenced by logFact().


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