math Namespace Reference

Math routines. More...

Functions

COMPILER_FUNCTIONAL double BinomialCoefficient (int n, int k)
 Computes the binomial coefficient, n choose k for nonnegative integers n and k.
double ClampNonNegative (double d)
 Forces a number to be non-negative, turning negative numbers into zero.
double ClampNonPositive (double d)
 Forces a number to be non-positive, turning positive numbers into zero.
double ClampRange (double value, double range_min, double range_max)
 Clips a number between a particular range.
COMPILER_FUNCTIONAL double Factorial (int d)
 Computes the factorial of an integer.
unsigned IntLog2 (unsigned i)
 Finds the log base 2 of an integer.
template<typename TAnyIntegerType >
bool IsPowerTwo (TAnyIntegerType i)
void MakeIdentityPermutation (index_t size, ArrayList< index_t > *result)
 Creates an identity permutation where the element i equals i.
void MakeIdentityPermutation (index_t size, index_t *array)
 Creates an identity permutation where the element i equals i.
void MakeInversePermutation (const ArrayList< index_t > &original, ArrayList< index_t > *reverse)
 Inverts or transposes an existing permutation.
void MakeInversePermutation (index_t size, const index_t *original, index_t *reverse)
 Inverts or transposes an existing permutation.
void MakeRandomPermutation (index_t size, ArrayList< index_t > *result)
 Creates a random permutation over integers 0 throush size - 1.
void MakeRandomPermutation (index_t size, index_t *array)
 Creates a random permutation and stores it in an existing C array (power user version).
double Mean (Vector V)
 Computes the mean value of a vector.
template<int t_numerator, int t_denominator>
double Pow (double d)
 Calculates a relatively small power using template metaprogramming.
template<int t_numerator, int t_denominator>
double PowAbs (double d)
 Calculates a small power of the absolute value of a number using template metaprogramming.
int RandInt (int lo, int hi_exclusive)
 Generates a uniform random integer.
int RandInt (int hi_exclusive)
 Generates a uniform random integer.
double Random (double lo, double hi)
 Generates a uniform random number in the specified range.
double Random ()
 Generates a uniform random number between 0 and 1.
int64 RoundInt (double d)
 Rounds a double-precision to an integer, casting it too.
double Sigmoid (double x)
 Computes the sigmoid function of a real number x Sigmoid(x) = 1/[1+exp(-x)].
double SphereVolume (double r, int d)
 Computes the hyper-volume of a hyper-sphere of dimension d.
template<typename T >
Sqr (T v)
 Squares a number.
double Std (Vector V)
 Computes the standard deviation of a vector.
double Var (Vector V)
 Computes the variance of a vector using "corrected two-pass algorithm".

Variables

const double E = 2.7182818284590452354
 Base of the natural logarithm.
const double LN_10 = 2.30258509299404568402
 Natural log of 10.
const double LN_2 = 0.69314718055994530942
 Natural log of 2.
const double LOG10_E = 0.43429448190325182765
 Log base 10 of E.
const double LOG2_E = 1.4426950408889634074
 Log base 2 of E.
const double PI = 3.141592653589793238462643383279
 The ratio of the circumference of a circle to its diameter.
const double PI_2 = 1.57079632679489661923
 The ratio of the circumference of a circle to its radius.
const double SQRT2 = 1.41421356237309504880
 The square root of 2.

Detailed Description

Math routines.

The hope is that this should contain most of the useful math routines you can think of. Currently, this is very sparse.


Function Documentation

COMPILER_FUNCTIONAL double math::BinomialCoefficient ( int  n,
int  k 
)

Computes the binomial coefficient, n choose k for nonnegative integers n and k.

Parameters:
n the first nonnegative integer argument
k the second nonnegative integer argument
Returns:
the binomial coefficient n choose k

Definition at line 43 of file discrete.cc.

Referenced by SeriesExpansionAux::Init(), and MultSeriesExpansionAux::Init().

double math::ClampNonNegative ( double  d  )  [inline]

Forces a number to be non-negative, turning negative numbers into zero.

Avoids branching costs (yes, we've discovered measurable improvements).

Definition at line 87 of file math_lib.h.

Referenced by DBallBound< TMetric, TPoint >::MinDistance(), DBallBound< TMetric, TPoint >::MinimaxDistance(), DBallBound< TMetric, TPoint >::MinToMid(), and DBallBound< TMetric, TPoint >::RangeDistance().

double math::ClampNonPositive ( double  d  )  [inline]

Forces a number to be non-positive, turning positive numbers into zero.

Avoids branching costs (yes, we've discovered measurable improvements).

Definition at line 96 of file math_lib.h.

double math::ClampRange ( double  value,
double  range_min,
double  range_max 
) [inline]

Clips a number between a particular range.

Parameters:
value the number to clip
range_min the first of the range
range_max the last of the range
Returns:
max(range_min, min(range_max, d))

Definition at line 108 of file math_lib.h.

COMPILER_FUNCTIONAL double math::Factorial ( int  d  ) 

Computes the factorial of an integer.

Definition at line 64 of file discrete.cc.

unsigned math::IntLog2 ( unsigned  i  )  [inline]

Finds the log base 2 of an integer.

This integer must absolutely be a power of 2.

Definition at line 139 of file discrete.h.

void math::MakeIdentityPermutation ( index_t  size,
ArrayList< index_t > *  result 
) [inline]

Creates an identity permutation where the element i equals i.

For instance, result[0] == 0, result[1] == 1, result[2] == 2, etc.

Parameters:
size the size to initialize the result to
result will be initialized to the identity permutation

Definition at line 85 of file discrete.h.

References ArrayList< TElem >::begin(), ArrayList< TElem >::Init(), and MakeIdentityPermutation().

void math::MakeIdentityPermutation ( index_t  size,
index_t *  array 
)

Creates an identity permutation where the element i equals i.

Low-level pointer version -- preferably use the ArrayList version instead.

For instance, result[0] == 0, result[1] == 1, result[2] == 2, etc.

Parameters:
size the number of elements in the permutation
array a place to store the permutation

Definition at line 76 of file discrete.cc.

Referenced by MakeIdentityPermutation(), GeneralCrossValidator< TLearner >::Run(), and SimpleCrossValidator< TClassifier >::Run().

void math::MakeInversePermutation ( const ArrayList< index_t > &  original,
ArrayList< index_t > *  reverse 
) [inline]

Inverts or transposes an existing permutation.

Definition at line 123 of file discrete.h.

References ArrayList< TElem >::begin(), ArrayList< TElem >::Init(), MakeInversePermutation(), and ArrayList< TElem >::size().

void math::MakeInversePermutation ( index_t  size,
const index_t *  original,
index_t *  reverse 
)

Inverts or transposes an existing permutation.

Definition at line 100 of file discrete.cc.

Referenced by MakeInversePermutation().

void math::MakeRandomPermutation ( index_t  size,
ArrayList< index_t > *  result 
) [inline]

Creates a random permutation over integers 0 throush size - 1.

Parameters:
size the number of elements
result will be initialized to a permutation array

Definition at line 108 of file discrete.h.

References ArrayList< TElem >::begin(), ArrayList< TElem >::Init(), and MakeRandomPermutation().

void math::MakeRandomPermutation ( index_t  size,
index_t *  array 
)

Creates a random permutation and stores it in an existing C array (power user version).

The random permutation is over the integers 0 through size - 1.

Parameters:
size the number of elements
array the array to store a permutation in

Definition at line 82 of file discrete.cc.

Referenced by MakeRandomPermutation(), GeneralCrossValidator< TLearner >::Run(), and SimpleCrossValidator< TClassifier >::Run().

double math::Mean ( Vector  V  ) 

Computes the mean value of a vector.

Don't forget initializing V before using this function

Parameters:
V the input vector
Returns:
the mean value
template<int t_numerator, int t_denominator>
double math::Pow ( double  d  )  [inline]

Calculates a relatively small power using template metaprogramming.

This allows a numerator and denominator. In the case where the numerator and denominator are equal, this will not do anything, or in the case where the denominator is one.

Definition at line 158 of file math_lib.h.

template<int t_numerator, int t_denominator>
double math::PowAbs ( double  d  )  [inline]

Calculates a small power of the absolute value of a number using template metaprogramming.

This allows a numerator and denominator. In the case where the numerator and denominator are equal, this will not do anything, or in the case where the denominator is one. For even powers, this will avoid calling the absolute value function.

Definition at line 172 of file math_lib.h.

int math::RandInt ( int  lo,
int  hi_exclusive 
) [inline]

Generates a uniform random integer.

Definition at line 141 of file math_lib.h.

int math::RandInt ( int  hi_exclusive  )  [inline]

Generates a uniform random integer.

Definition at line 135 of file math_lib.h.

double math::Random ( double  lo,
double  hi 
) [inline]

Generates a uniform random number in the specified range.

Definition at line 128 of file math_lib.h.

References Random().

double math::Random (  )  [inline]

Generates a uniform random number between 0 and 1.

Definition at line 121 of file math_lib.h.

Referenced by Random().

int64 math::RoundInt ( double  d  )  [inline]

Rounds a double-precision to an integer, casting it too.

Definition at line 78 of file math_lib.h.

double math::Sigmoid ( double  x  ) 

Computes the sigmoid function of a real number x Sigmoid(x) = 1/[1+exp(-x)].

Parameters:
x the input real number
Returns:
the sigmoid function value
COMPILER_FUNCTIONAL double math::SphereVolume ( double  r,
int  d 
)

Computes the hyper-volume of a hyper-sphere of dimension d.

Parameters:
r the radius of the hyper-sphere
d the number of dimensions

Referenced by EpanKernel::CalcNormConstant().

template<typename T >
T math::Sqr ( v  )  [inline]

Squares a number.

Definition at line 71 of file math_lib.h.

Referenced by DHrectBound< t_pow >::CalculateMaxDistanceSq(), and DatasetScaler::StandardizeData().

double math::Std ( Vector  V  ) 

Computes the standard deviation of a vector.

Don't forget initializing V before using this function.

Parameters:
V the input vector
Returns:
the standard deviation
double math::Var ( Vector  V  ) 

Computes the variance of a vector using "corrected two-pass algorithm".

See "Numerical Recipes in C" for reference. Don't forget initializing V before using this function.

Parameters:
V the input vector
Returns:
the variance

Variable Documentation

const double math::E = 2.7182818284590452354

Base of the natural logarithm.

Definition at line 55 of file math_lib.h.

const double math::LN_10 = 2.30258509299404568402

Natural log of 10.

Definition at line 63 of file math_lib.h.

const double math::LN_2 = 0.69314718055994530942

Natural log of 2.

Definition at line 61 of file math_lib.h.

Referenced by GaussianStarKernel::Init().

const double math::LOG10_E = 0.43429448190325182765

Log base 10 of E.

Definition at line 59 of file math_lib.h.

const double math::LOG2_E = 1.4426950408889634074

Log base 2 of E.

Definition at line 57 of file math_lib.h.

const double math::PI = 3.141592653589793238462643383279

The ratio of the circumference of a circle to its diameter.

Definition at line 65 of file math_lib.h.

Referenced by GaussianKernel::CalcNormConstant().

const double math::PI_2 = 1.57079632679489661923

The ratio of the circumference of a circle to its radius.

Definition at line 67 of file math_lib.h.

Referenced by GaussianStarKernel::CalcNormConstant().

const double math::SQRT2 = 1.41421356237309504880

The square root of 2.

Definition at line 53 of file math_lib.h.

Generated on Mon Jan 24 12:04:41 2011 for FASTlib by  doxygen 1.6.3