GClasses

GClasses::GMath Class Reference

Provides some useful math functions. More...

#include <GMath.h>

List of all members.

Static Public Member Functions

static double signedRoot (double x)
 Returns sign(x) * sqrt(ABS(x))
static double logistic (double x)
 The logistic sigmoid function.
static double logisticDerivative (double x)
 This evaluates the derivative of the sigmoid function.
static double logisticInverse (double y)
 This is the inverse of the logistic sigmoid function.
static double softStep (double x, double steepness)
 Calculates a function that always passes through (0, 0), (1, 1), and (0.5, 0.5). The slope at (0.5, 0.5) will be "steepness". If steepness is > 1, then the slope at (0, 0) and (1, 1) will be 0. If steepness is < 1, the slope at (0, 0) and (1, 1) will be infinity. If steepness is exactly 1, the slope will be 1 at those points. softStep(1/x, 2) = PI*cauchy(x-1).
static double interpolatingFunc (double x)
 A soft step function with a very high degree of continuity at 0 and 1.
static double bend (double x)
 The bend function has a slope of 1 at very negative values of x, and 2 at very positive values of x, and a smooth transition in between.
static double bendInverse (double y)
 The inverse of the bend function.
static double bendDerivative (double x)
 The derivative of the bend function.
static double gamma (double x)
 The gamma function.
static double logGamma (double x)
 returns log(Gamma(x))
static double logFactorial (int x)
 returns log(x!)
static double gaussian (double x)
 The gaussian function.
static double approximateErf (double x)
 Returns an approximation for the error function of x.
static double approximateInverseErf (double x)
 Returns an approximation for the inverse of the error function.
static double productLog (double x)
 Computes the y where x = y*exp(y). This is also known as the Omega function, or the Lambert W function. x must be > -1/e.
static double limboAdd (double l, double a, double b)
 When l is somewhere between 0 and 1, it will do something in between "add" and "multiply" with a and b. When l is close to 0, this returns a value close to a + b. When l is close to 1, this returns a value close to a * b. When l is exactly 0 or 1, results are undefined, so you special-case those values to just call add or multiply.
static void newtonPolynomial (const double *pTValues, double *pFuncValues, int nPoints)
 This implements Newton's method for determining a polynomial f(t) that goes through all the control points pFuncValues at pTValues. (You could then convert to a Bezier curve to get a Bezier curve that goes through those points.) The polynomial coefficients are put in pFuncValues in the form c0 + c1*t + c2*t*t + c3*t*t*t + ...
static double integrate (MathFunc pFunc, double dStart, double dEnd, int nSteps, void *pThis)
 Integrates the specified function from dStart to dEnd.
static double incompleteBeta (double x, double a, double b, int steps)
 Estimates the Incomplete Beta function by "integrating" with the specified number of steps.
static void pascalsTriangle (size_t *pOutRow, size_t nRow)
 Returns the specified row from Pascal's triangle. pOutRow must be big enough to hold nRow + 1 elements Row 0 1 Row 1 1 1 Row 2 1 2 1 Row 3 1 3 3 1 Row 4 1 4 6 4 1 etc. such that each value is the sum of its two parents.
static double nChooseK (unsigned int n, unsigned int k)
 Returns the value of n choose k.
static double tTestAlphaValue (size_t v, double t)
 Computes the p-value from the degrees of freedom, and the t-value obtained from a T-test.
static double wilcoxonPValue (int n, double t)
 This computes the Wilcoxon P-value assuming n is large enough that the Normal approximation will suffice.
static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure.

Detailed Description

Provides some useful math functions.


Member Function Documentation

static double GClasses::GMath::approximateErf ( double  x) [static]

Returns an approximation for the error function of x.

static double GClasses::GMath::approximateInverseErf ( double  x) [static]

Returns an approximation for the inverse of the error function.

static double GClasses::GMath::bend ( double  x) [inline, static]

The bend function has a slope of 1 at very negative values of x, and 2 at very positive values of x, and a smooth transition in between.

static double GClasses::GMath::bendDerivative ( double  x) [inline, static]

The derivative of the bend function.

static double GClasses::GMath::bendInverse ( double  y) [inline, static]

The inverse of the bend function.

static double GClasses::GMath::gamma ( double  x) [static]

The gamma function.

static double GClasses::GMath::gaussian ( double  x) [inline, static]

The gaussian function.

static double GClasses::GMath::incompleteBeta ( double  x,
double  a,
double  b,
int  steps 
) [static]

Estimates the Incomplete Beta function by "integrating" with the specified number of steps.

static double GClasses::GMath::integrate ( MathFunc  pFunc,
double  dStart,
double  dEnd,
int  nSteps,
void *  pThis 
) [static]

Integrates the specified function from dStart to dEnd.

static double GClasses::GMath::interpolatingFunc ( double  x) [inline, static]

A soft step function with a very high degree of continuity at 0 and 1.

static double GClasses::GMath::limboAdd ( double  l,
double  a,
double  b 
) [inline, static]

When l is somewhere between 0 and 1, it will do something in between "add" and "multiply" with a and b. When l is close to 0, this returns a value close to a + b. When l is close to 1, this returns a value close to a * b. When l is exactly 0 or 1, results are undefined, so you special-case those values to just call add or multiply.

static double GClasses::GMath::logFactorial ( int  x) [static]

returns log(x!)

static double GClasses::GMath::logGamma ( double  x) [static]

returns log(Gamma(x))

static double GClasses::GMath::logistic ( double  x) [inline, static]

The logistic sigmoid function.

static double GClasses::GMath::logisticDerivative ( double  x) [inline, static]

This evaluates the derivative of the sigmoid function.

static double GClasses::GMath::logisticInverse ( double  y) [inline, static]

This is the inverse of the logistic sigmoid function.

static double GClasses::GMath::nChooseK ( unsigned int  n,
unsigned int  k 
) [inline, static]

Returns the value of n choose k.

static void GClasses::GMath::newtonPolynomial ( const double *  pTValues,
double *  pFuncValues,
int  nPoints 
) [static]

This implements Newton's method for determining a polynomial f(t) that goes through all the control points pFuncValues at pTValues. (You could then convert to a Bezier curve to get a Bezier curve that goes through those points.) The polynomial coefficients are put in pFuncValues in the form c0 + c1*t + c2*t*t + c3*t*t*t + ...

static void GClasses::GMath::pascalsTriangle ( size_t *  pOutRow,
size_t  nRow 
) [static]

Returns the specified row from Pascal's triangle. pOutRow must be big enough to hold nRow + 1 elements Row 0 1 Row 1 1 1 Row 2 1 2 1 Row 3 1 3 3 1 Row 4 1 4 6 4 1 etc. such that each value is the sum of its two parents.

static double GClasses::GMath::productLog ( double  x) [static]

Computes the y where x = y*exp(y). This is also known as the Omega function, or the Lambert W function. x must be > -1/e.

static double GClasses::GMath::signedRoot ( double  x) [inline, static]

Returns sign(x) * sqrt(ABS(x))

static double GClasses::GMath::softStep ( double  x,
double  steepness 
) [inline, static]

Calculates a function that always passes through (0, 0), (1, 1), and (0.5, 0.5). The slope at (0.5, 0.5) will be "steepness". If steepness is > 1, then the slope at (0, 0) and (1, 1) will be 0. If steepness is < 1, the slope at (0, 0) and (1, 1) will be infinity. If steepness is exactly 1, the slope will be 1 at those points. softStep(1/x, 2) = PI*cauchy(x-1).

static void GClasses::GMath::test ( ) [static]

Performs unit tests for this class. Throws an exception if there is a failure.

static double GClasses::GMath::tTestAlphaValue ( size_t  v,
double  t 
) [static]

Computes the p-value from the degrees of freedom, and the t-value obtained from a T-test.

static double GClasses::GMath::wilcoxonPValue ( int  n,
double  t 
) [static]

This computes the Wilcoxon P-value assuming n is large enough that the Normal approximation will suffice.