GClasses
GClasses::GMath Class Reference

Detailed Description

Provides some useful math functions.

#include <GMath.h>

Static Public Member Functions

static double approximateErf (double x)
 Returns an approximation for the error function of x. More...
 
static double approximateInverseErf (double x)
 Returns an approximation for the inverse of the error function. More...
 
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. More...
 
static double bendDerivative (double x)
 The derivative of the bend function. More...
 
static double bendInverse (double y)
 The inverse of the bend function. More...
 
static double functionInverse (double(*func)(const double *params, double x), const double *params, double y, double x1, double x2, double epsilon)
 Inverts a function using linear interpolation to iteratively find the target output. Assumes the function is monotonic in the region it will explore func gives the function to invert. params specifies parameters to the function. y is the target output. x1 and x2 are two initial estimates to seed the search. The search is complete when the output is within epsilon of the target. Throws an exception if progress stalls. More...
 
static double fuzzy (double x, double y, double alpha)
 If false = 0.0 and true = 1.0, then not(x) = -x = fuzzy(x, 0.0, 0), and(x, y) = fuzzy(x, y, 1.0), or(x, y) = -fuzzy(x, y, 0.0), xor(x, y) = -fuzzy(x, y, 0.5), nand(x, y) = -fuzzy(x, y, 1.0), nor(x, y) = fuzzy(x, y, 0.0), nxor(x, y) = fuzzy(x, y, 0.5). More...
 
static double gamma (double x)
 The gamma function. More...
 
static double gaussian (double x)
 The gaussian function. More...
 
static double incompleteBeta (double x, double a, double b, int steps)
 Estimates the Incomplete Beta function by "integrating" with the specified number of steps. More...
 
static double integrate (MathFunc pFunc, double dStart, double dEnd, int nSteps, void *pThis)
 Integrates the specified function from dStart to dEnd. More...
 
static double interpolatingFunc (double x)
 A soft step function with a very high degree of continuity at 0 and 1. More...
 
static double logFactorial (int x)
 returns log(x!) More...
 
static double logGamma (double x)
 returns log(Gamma(x)) More...
 
static double logistic (double x)
 The logistic sigmoid function. More...
 
static double logisticDerivative (double x)
 This evaluates the derivative of the sigmoid function. More...
 
static double logisticInverse (double y)
 This is the inverse of the logistic sigmoid function. More...
 
static double mackeyGlass (double x, double xt, double beta=0.2, double gamma=0.1, double n=10)
 Given x(t), returns x(t + 1) in the Mackey-Glass series. x is x(t), xt is x(t - TAO), and beta, gamma, and n are other Mackey-Glass parameters. Call this in a loop to get a series. More...
 
static double nChooseK (unsigned int n, unsigned int k)
 Returns the value of n choose k. More...
 
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 + ... More...
 
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. More...
 
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. More...
 
static double signedRoot (double x)
 Returns sign(x) * sqrt(ABS(x)) More...
 
static double softExponential (double alpha, double x)
 If alpha=1, returns exp(x). If alpha = 0, returns x. If alpha = -1, returns log_e(x). Alpha can be any continuous value from -1 to 1 to continuously interpolate among these functions. More...
 
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). More...
 
static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure. More...
 
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. More...
 
static double wilcoxonPValue (int n, double t)
 This computes the Wilcoxon P-value assuming n is large enough that the Normal approximation will suffice. More...
 

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)
inlinestatic

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)
inlinestatic

The derivative of the bend function.

static double GClasses::GMath::bendInverse ( double  y)
inlinestatic

The inverse of the bend function.

static double GClasses::GMath::functionInverse ( double(*)(const double *params, double x)  func,
const double *  params,
double  y,
double  x1,
double  x2,
double  epsilon 
)
static

Inverts a function using linear interpolation to iteratively find the target output. Assumes the function is monotonic in the region it will explore func gives the function to invert. params specifies parameters to the function. y is the target output. x1 and x2 are two initial estimates to seed the search. The search is complete when the output is within epsilon of the target. Throws an exception if progress stalls.

static double GClasses::GMath::fuzzy ( double  x,
double  y,
double  alpha 
)
static

If false = 0.0 and true = 1.0, then not(x) = -x = fuzzy(x, 0.0, 0), and(x, y) = fuzzy(x, y, 1.0), or(x, y) = -fuzzy(x, y, 0.0), xor(x, y) = -fuzzy(x, y, 0.5), nand(x, y) = -fuzzy(x, y, 1.0), nor(x, y) = fuzzy(x, y, 0.0), nxor(x, y) = fuzzy(x, y, 0.5).

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

The gamma function.

static double GClasses::GMath::gaussian ( double  x)
inlinestatic

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)
inlinestatic

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

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)
inlinestatic

The logistic sigmoid function.

static double GClasses::GMath::logisticDerivative ( double  x)
inlinestatic

This evaluates the derivative of the sigmoid function.

static double GClasses::GMath::logisticInverse ( double  y)
inlinestatic

This is the inverse of the logistic sigmoid function.

static double GClasses::GMath::mackeyGlass ( double  x,
double  xt,
double  beta = 0.2,
double  gamma = 0.1,
double  n = 10 
)
static

Given x(t), returns x(t + 1) in the Mackey-Glass series. x is x(t), xt is x(t - TAO), and beta, gamma, and n are other Mackey-Glass parameters. Call this in a loop to get a series.

static double GClasses::GMath::nChooseK ( unsigned int  n,
unsigned int  k 
)
inlinestatic

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)
inlinestatic

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

static double GClasses::GMath::softExponential ( double  alpha,
double  x 
)
static

If alpha=1, returns exp(x). If alpha = 0, returns x. If alpha = -1, returns log_e(x). Alpha can be any continuous value from -1 to 1 to continuously interpolate among these functions.

static double GClasses::GMath::softStep ( double  x,
double  steepness 
)
inlinestatic

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.