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 (Function &f, const std::string &param, double a, double b, double tolerance)
 Find one root of the given function. More...
 
static RowMatrix< double > * computeHessianMatrix (DerivableSecondOrder &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 55 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 67 of file NumTools.h.

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

◆ computeHessianMatrix()

RowMatrix< double > * NumTools::computeHessianMatrix ( DerivableSecondOrder 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 83 of file NumTools.cpp.

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

◆ fact()

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

Definition at line 160 of file NumTools.h.

References fact().

Referenced by fact().

◆ logFact()

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

Definition at line 164 of file NumTools.h.

References logFact().

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 132 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 89 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 100 of file NumTools.h.

◆ shift() [1/2]

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

Definition at line 153 of file NumTools.h.

◆ shift() [2/2]

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

Definition at line 148 of file NumTools.h.

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

◆ 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 78 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 109 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 117 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 141 of file NumTools.h.

◆ uniRoot()

double NumTools::uniRoot ( Function 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 50 of file NumTools.cpp.

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


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