bpp-core  2.1.0
bpp::NumTools Class Reference

Some utilitary function for numerical calculus. More...

#include <Bpp/Numeric/NumTools.h>

List of all members.

Static Public Member Functions

template<class T >
static T abs (T a)
 Get the magnitude of a value.
template<class T >
static T sign (T a)
 Get the sign of a value.
template<class T >
static T max (T a, T b)
 Get the max between 2 values.
template<class T >
static T min (T a, T b)
 Get the min between 2 values.
template<class T >
static T sign (T a, T b)
 Get the magnitude of a times the sign of b.
template<class T >
static T sqr (T a)
 Get the square of a number.
template<class T >
static T logsum (T lnx, T lny)
 Compute the logarithm of a sum from the sum of logarithms.
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) throw (Exception)
 Find one root of the given function.
static RowMatrix< double > * computeHessianMatrix (DerivableSecondOrder &function, const ParameterList &parameters)
 Compute the Hessian matrix for a function at a given point.

Detailed Description

Some utilitary function for numerical calculus.

Definition at line 53 of file NumTools.h.


Member Function Documentation

template<class T >
static T bpp::NumTools::abs ( a) [inline, static]

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 66 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(), bpp::DownhillSimplexMethod::DSMStopCondition::getCurrentTolerance(), and bpp::Uniform01K::setSeed().

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 80 of file NumTools.cpp.

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

template<class T >
static T bpp::NumTools::fact ( n) [inline, static]

Definition at line 157 of file NumTools.h.

References fact().

Referenced by fact().

template<class T >
static T bpp::NumTools::logFact ( n) [inline, static]

Definition at line 161 of file NumTools.h.

References logFact().

Referenced by logFact().

template<class T >
static T bpp::NumTools::logsum ( lnx,
lny 
) [inline, static]

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 131 of file NumTools.h.

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

template<class T >
static T bpp::NumTools::max ( a,
b 
) [inline, static]

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 88 of file NumTools.h.

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

template<class T >
static T bpp::NumTools::min ( a,
b 
) [inline, static]

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 99 of file NumTools.h.

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

Definition at line 145 of file NumTools.h.

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

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

Definition at line 150 of file NumTools.h.

template<class T >
static T bpp::NumTools::sign ( a) [inline, static]

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 77 of file NumTools.h.

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

template<class T >
static T bpp::NumTools::sign ( a,
b 
) [inline, static]

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 108 of file NumTools.h.

template<class T >
static T bpp::NumTools::sqr ( a) [inline, static]

Get the square of a number.

Parameters:
aThe value.
Returns:
$ a^2 $.

Definition at line 116 of file NumTools.h.

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

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

Definition at line 138 of file NumTools.h.

double NumTools::uniRoot ( Function f,
const std::string &  param,
double  a,
double  b,
double  tolerance 
) throw (Exception) [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 48 of file NumTools.cpp.

References bpp::ParameterList::addParameter().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends