Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MathFunctions.H File Reference


Detailed Description

Miscellaneous math functions

Definition in file MathFunctions.H.

#include "Util/Assert.H"
#include "Util/FastMathFunctions.H"
#include "Util/Promotions.H"
#include "rutz/compat_cmath.h"
#include <algorithm>
#include <cmath>

Include dependency graph for MathFunctions.H:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cheb_series_struct
#define D_PI   3.1415926535897932384626433832795029
 Miscellaneous math functions.
#define D_E   2.7182818284590452353602874713526625
 e
#define D_LOG_SQRT_2_PI   0.9189385332046727417803297364056176
 Log Root of 2 Pi.
#define D_SQRT_2_PI   2.5066282746310002416123552393401041
 Root of 2*Pi.
#define D_SQRT_PI   1.7724538509055160272981674833411451
 Root of Pi.
#define D_SQRT_2   1.4142135623730950488016887242096981
 Root of 2 DEFINED in cmath as M_SQRT2, but is not 128 bit.
#define D_LOG_2_PI   1.8378770664093454835606594728112353
 Natural Log of 2*Pi.
#define D_LOG_PI   1.1447298858494001741434273513530587
 Natural Log of Pi.
#define D_LOG_2   0.6931471805599453094172321214581766
 Natural Log of 2 DEFINED in cmath as M_LN2, but is not 128 bit.
#define D_LOG_SQRT_2   0.3465735902799726547086160607290883
 Natural Log of sqrt of 2.
#define D_2_PI   6.2831853071795862319959269370883703
 2*Pi
#define D_EULER_GAMMA   0.5772156649015328606065120900824024
 The Euler-Mascheroni Constant (Not the same as e).
#define D_DEGREE   0.0174532925199432957692369076848861
 Number of radians in one degree.
#define D_GOLDEN_RATIO   1.6180339887498948482045868343656381
 The golden ratio.
#define D_CATALAN   0.9159655941772190150546035149323841
 Catalan's Constant.
#define D_GLAISHER   1.2824271291006226368753425688697917
 Glaisher-Kinkelin Constant.
#define D_KHINCHIN   2.6854520010653064453097148354817956
 Khinchin's Constant.
#define D_SOLDNER   1.4513692348833810502839684858920274
 Ramanujan-Soldner's Constant.
#define D_APERY   1.2020569031595942853997381615114499
 Apery's Constant.
#define D_GAUSS_KUZMAN   0.3036630028987326585974481219015562
 Gauss-Kuzmin-Wirsing constant.
#define D_FRANSEN   2.8077702420285193652215011865577729
 Fransén-Robinson constant.
#define D_SERPINSKY   2.5849817595792532170658935873831711
 Sierpin'ski's constant.
#define D_MILL   1.3063778838630806904686144926026057
 Mills' constant.
#define D_OMEGA   0.5671432904097838729999686622103555
 Omega constant.
#define D_GOLOMB_DICKMAN   0.6243299885435508709929363831008372
 Golomb-Dickman constant.
#define L_PI   3.14159265358979323846264338327950288419716939937510582097494459230781L
 Pi.
#define L_E   2.71828182845904523536028747135266249775724709369995957496696762772407L
 e
#define L_LOG_SQRT_2_PI   0.91893853320467274178032973640561763986139747363778341281715154048276L
 Log Root of 2 Pi.
#define L_SQRT_2_PI   2.50662827463100050241576528481104525300698674060993831662992357634229L
 Root of 2*Pi.
#define L_SQRT_PI   1.77245385090551602729816748334114518279754945612238712821380778985291L
 Root of Pi.
#define L_SQRT_2   1.41421356237309514547462185873882845044136047363281250000000000000000L
 Root of 2 DEFINED in cmath as M_SQRT2, but is not > 128 bit.
#define L_LOG_2_PI   1.83787706640934548356065947281123527972279494727556682563430308096553L
 Natural Log of 2*Pi.
#define L_LOG_PI   1.14472988584940017414342735135305871164729481291531157151362307147214L
 Natural Log of Pi.
#define L_LOG_2   0.69314718055994528622676398299518041312694549560546875000000000000000L
 Natural Log of 2 DEFINED in cmath as M_LN2, but is not > 128 bit.
#define L_2_PI   6.28318530717958647692528676655900576839433879875021164194988918461560L
 2*Pi
#define L_DEGREE   0.01745329251994329576923690768488612713442871888541725456097191440171L
 Number of radians in one degree.
#define L_EULER_GAMMA   0.57721566490153286060651209008240243104215933593992359880576723488486L
 The Euler-Mascheroni Constant (Not the same as e).
#define L_GOLDEN_RATIO   1.61803398874989484820458683436563811772030917980576286213544862270526L
 The golden ratio.
#define L_CATALAN   0.91596559417721901505460351493238411077414937428167213426649811962176L
 Catalan's Constant.
#define L_GLAISHER   1.28242712910062263687534256886979172776768892732500119206374002174040L
 Glaisher-Kinkelin Constant.
#define L_KHINCHIN   2.68545200106530644530971483548179569382038229399446295305115234555721L
 Khinchin's Constant.

Basic numerical operations

template<class T>
int signOf (const T &x)
 Returns -1 if x is negative, or 1 if x is positve.
template<class T>
squareOf (const T &x)
 Returns the square of x.
template<class T, class T2>
clampValue (const T &val, const T2 &bound1, const T2 &bound2)
 Returns the number closest to val and between bound1 and bound2.

Numerical range and finiteness testing

bool isFinite (const byte &arg)
 Function to check for finite value.
bool isFinite (const int16 &arg)
 Function to check for finite value.
bool isFinite (const int32 &arg)
 Function to check for finite value.
bool isFinite (const float &arg)
 Function to check for finite value.
bool isFinite (const double &arg)
 Function to check for finite value.

Random number generation

void initRandomNumbers ()
 Initialize random seeds from pseudo-random sources (e.g. time(), getpid()).
void initRandomNumbersZero ()
 Initialize random seeds with zero, to produce deterministic pseudo-random sequences.
double randomDouble ()
 Generate a random double in [0.0,1.0).
double randomDoubleFromNormal (const double s)
 Generate a random double from a normal distribution with mean zero and standard deviation s.
int randomUpToIncluding (const int n)
 Generate a random integer in [0,n] (i.e., including n).
int randomUpToNotIncluding (const int n)
 Generate a random integer in [0,n) (i.e., not including n).
template<class T>
void randShuffle (T *array, const uint size)
 Randomly shuffle given array.
double ran2 (int &idum)
 Random number generator from Numerical Recipes in C book.
int getIdum (const bool useRandom=true)
 Get a random seed for ran2.
double gasdev (int &idum)
 Randomly distributed Gaussian deviate with zero mean and unit variance.
double expdev (int &idum)
 Randomly distributed Exponential deviate.

Special math functions with iterative implementations

double poisson (const unsigned int k, const double mu)
 Compute probability of drawing a value k from a Poisson of mean mu.
double lngamma (double x)
 Compute log of Gamma.
double psi (const double x)
 Compute the psi (derivarive of log of gamma) function (requires x > 0.0).

Scalar math functions corresponding with Pixel math functions in Pixels.h

template<class T>
maxmerge (T A, const T B)
template<class T>
minmerge (T A, const T B)
template<class T>
sec (T A)
 Secant.
template<class T>
cosec (T A)
 Cosecant.
template<class T>
cotan (T A)
 Cotangent.
template<class T>
asec (T A)
 inverse secant
template<class T>
acosec (T A)
 inverse cosecant
template<class T>
acotan (T A)
 inverse cotangent
template<class T>
sech (T A)
 Hyperbolic Secant.
template<class T>
cosech (T A)
 Hyperbolic Cosecant.
template<class T>
cotanh (T A)
 Hyperbolic Cotangent.
template<class T>
asech (T A)
 Inverse Hyperbolic Secant.
template<class T>
acosech (T A)
 Inverse Hyperbolic Cosecant.
template<class T>
acotanh (T A)
 Inverse Hyperbolic Cotangent.
template<class T>
sign (T A)
 return the sign of this item
template<class T>
logN (T A, const T n)
 logN for pixel
template<class T>
logsig (T A, const T a, const T b)
 log sigmoid for pixel
template<class T>
logsig2 (T x, const T a, const T b)
 log sigmoid for pixel with offset
template<class T>
tansig (T A)
 tan sigmoid for pixel
template<class T>
saturate (T A, const T n)
 saturate pixel at some value
template<class T>
gauss (T A, const T Mu, const T Std)
 find p from a Gaussian distribution
template<class T>
gauss (T diff, const T Std)
template<class T>
gamma (T X, const T A, const T B)
 find p from a gamma distrabution
template<class T>
max (T A)
 this nonsense operator is for compatability
template<class T>
min (T A)
 this nonsense operator is for compatability
template<class T>
bool isBounded (T A, const T upper, const T lower)
 find if this value or pixel is bounded by the other two
template<class T>
sum (T A)
 this nonsense operator is for compatability
template<class T>
mean (T A)
 this nonsense operator is for compatability

Typedefs

typedef cheb_series_struct cheb_series

Functions

template<class T>
onlineMean (T mu, T A, int n)
template<class T>
onlineStdev (T mu, T stdev, T A, int n)
double cheb_eval (const cheb_series *cs, const double x)
double cheb_eval_psi (const double x)
double cheb_eval_apsi (const double x)
double fast_psi (const double x)
template<class T>
wow (const T &k)
 Convert a number into Wows, for instance a KL distance.
template<class T>
KLjointGammaGamma (const T ai, const T aj, const T bi, const T bj, const T Ai, const T Aj, const T Bi, const T Bj, const bool doWow=false, const T gammaBiasi=1.0F, const T gammaBiasj=1.0F)
 Compute the KL distance for a joint gamma PDF.
template<class T>
KLjointGammaGauss (const T a, const T u, const T b, const T s, const T A, const T U, const T B, const T S, const bool doWow=false, const T gammaBias=1.0F, const T gaussBias=1.0F)
 Compute the KL distance for a joint gamma gauss PDF.
template<class T>
KLgamma (const T a, const T b, const T A, const T B, const bool doWow=false)
 Compute the KL distance for a single gamma PDF.
template<class T>
KLgammaConst (const T a, const T A, const T C1, const T C2, const bool doWow=false)
 Compute the KL distance for a single gamma PDF.
template<class T>
KLgamma (const T a, const T A, const bool doWow=false)
 Compute the KL distance for a single gamma PDF.
template<class T>
KLgauss (const T u, const T s, const T U, const T S, const bool doWow=false)
 Compute the KL distance for a single gauss PDF.
double AUC (const float *model, const float *rand, size_t sm, size_t sr, const double step=0.1)

Variables

static double psics_data [23]
static const cheb_series psi_cs = { psics_data, 22, -1, 1, 17 }
static double apsics_data [16]
static const cheb_series apsi_cs = { apsics_data, 15, -1, 1, 9 }


Define Documentation

#define D_2_PI   6.2831853071795862319959269370883703
 

2*Pi

Definition at line 83 of file MathFunctions.H.

Referenced by gauss().

#define D_APERY   1.2020569031595942853997381615114499
 

Apery's Constant.

Definition at line 99 of file MathFunctions.H.

#define D_CATALAN   0.9159655941772190150546035149323841
 

Catalan's Constant.

Definition at line 91 of file MathFunctions.H.

#define D_DEGREE   0.0174532925199432957692369076848861
 

Number of radians in one degree.

Definition at line 87 of file MathFunctions.H.

Referenced by LocalizationMapEntity::drawMe(), Particle::updatePosition(), and Util::vectorTo().

#define D_E   2.7182818284590452353602874713526625
 

e

Definition at line 65 of file MathFunctions.H.

#define D_EULER_GAMMA   0.5772156649015328606065120900824024
 

The Euler-Mascheroni Constant (Not the same as e).

Definition at line 85 of file MathFunctions.H.

#define D_FRANSEN   2.8077702420285193652215011865577729
 

Fransén-Robinson constant.

Definition at line 103 of file MathFunctions.H.

#define D_GAUSS_KUZMAN   0.3036630028987326585974481219015562
 

Gauss-Kuzmin-Wirsing constant.

Definition at line 101 of file MathFunctions.H.

#define D_GLAISHER   1.2824271291006226368753425688697917
 

Glaisher-Kinkelin Constant.

Definition at line 93 of file MathFunctions.H.

#define D_GOLDEN_RATIO   1.6180339887498948482045868343656381
 

The golden ratio.

Definition at line 89 of file MathFunctions.H.

#define D_GOLOMB_DICKMAN   0.6243299885435508709929363831008372
 

Golomb-Dickman constant.

Definition at line 111 of file MathFunctions.H.

#define D_KHINCHIN   2.6854520010653064453097148354817956
 

Khinchin's Constant.

Definition at line 95 of file MathFunctions.H.

#define D_LOG_2   0.6931471805599453094172321214581766
 

Natural Log of 2 DEFINED in cmath as M_LN2, but is not 128 bit.

Definition at line 79 of file MathFunctions.H.

Referenced by wow().

#define D_LOG_2_PI   1.8378770664093454835606594728112353
 

Natural Log of 2*Pi.

Definition at line 75 of file MathFunctions.H.

#define D_LOG_PI   1.1447298858494001741434273513530587
 

Natural Log of Pi.

Definition at line 77 of file MathFunctions.H.

#define D_LOG_SQRT_2   0.3465735902799726547086160607290883
 

Natural Log of sqrt of 2.

Definition at line 81 of file MathFunctions.H.

Referenced by SurpriseModelSPC::surprise().

#define D_LOG_SQRT_2_PI   0.9189385332046727417803297364056176
 

Log Root of 2 Pi.

Definition at line 67 of file MathFunctions.H.

Referenced by lngamma().

#define D_MILL   1.3063778838630806904686144926026057
 

Mills' constant.

Definition at line 107 of file MathFunctions.H.

#define D_OMEGA   0.5671432904097838729999686622103555
 

Omega constant.

Definition at line 109 of file MathFunctions.H.

#define D_PI   3.1415926535897932384626433832795029
 

Miscellaneous math functions.

Each constant is 128 bits IEEE quad. On a 64 bit system, a double is 128 bits. Thus, each number is a double on a modern system

# define M_El 2.7182818284590452353602874713526625L

is given for the value of 'e'. We follow this standard.

Note:

Definition at line 63 of file MathFunctions.H.

Referenced by Util::degToRad(), Util::ProbabilityDistribution(), and Util::radToDeg().

#define D_SERPINSKY   2.5849817595792532170658935873831711
 

Sierpin'ski's constant.

Definition at line 105 of file MathFunctions.H.

#define D_SOLDNER   1.4513692348833810502839684858920274
 

Ramanujan-Soldner's Constant.

Definition at line 97 of file MathFunctions.H.

#define D_SQRT_2   1.4142135623730950488016887242096981
 

Root of 2 DEFINED in cmath as M_SQRT2, but is not 128 bit.

Definition at line 73 of file MathFunctions.H.

Referenced by SurpriseModelSPC::surprise().

#define D_SQRT_2_PI   2.5066282746310002416123552393401041
 

Root of 2*Pi.

Definition at line 69 of file MathFunctions.H.

#define D_SQRT_PI   1.7724538509055160272981674833411451
 

Root of Pi.

Definition at line 71 of file MathFunctions.H.

#define L_2_PI   6.28318530717958647692528676655900576839433879875021164194988918461560L
 

2*Pi

Definition at line 138 of file MathFunctions.H.

#define L_CATALAN   0.91596559417721901505460351493238411077414937428167213426649811962176L
 

Catalan's Constant.

Definition at line 146 of file MathFunctions.H.

#define L_DEGREE   0.01745329251994329576923690768488612713442871888541725456097191440171L
 

Number of radians in one degree.

Definition at line 140 of file MathFunctions.H.

#define L_E   2.71828182845904523536028747135266249775724709369995957496696762772407L
 

e

Definition at line 122 of file MathFunctions.H.

#define L_EULER_GAMMA   0.57721566490153286060651209008240243104215933593992359880576723488486L
 

The Euler-Mascheroni Constant (Not the same as e).

Definition at line 142 of file MathFunctions.H.

#define L_GLAISHER   1.28242712910062263687534256886979172776768892732500119206374002174040L
 

Glaisher-Kinkelin Constant.

Definition at line 148 of file MathFunctions.H.

#define L_GOLDEN_RATIO   1.61803398874989484820458683436563811772030917980576286213544862270526L
 

The golden ratio.

Definition at line 144 of file MathFunctions.H.

#define L_KHINCHIN   2.68545200106530644530971483548179569382038229399446295305115234555721L
 

Khinchin's Constant.

Definition at line 150 of file MathFunctions.H.

#define L_LOG_2   0.69314718055994528622676398299518041312694549560546875000000000000000L
 

Natural Log of 2 DEFINED in cmath as M_LN2, but is not > 128 bit.

Definition at line 136 of file MathFunctions.H.

#define L_LOG_2_PI   1.83787706640934548356065947281123527972279494727556682563430308096553L
 

Natural Log of 2*Pi.

Definition at line 132 of file MathFunctions.H.

#define L_LOG_PI   1.14472988584940017414342735135305871164729481291531157151362307147214L
 

Natural Log of Pi.

Definition at line 134 of file MathFunctions.H.

#define L_LOG_SQRT_2_PI   0.91893853320467274178032973640561763986139747363778341281715154048276L
 

Log Root of 2 Pi.

Definition at line 124 of file MathFunctions.H.

#define L_PI   3.14159265358979323846264338327950288419716939937510582097494459230781L
 

Pi.

Each constant is 256 bits, This makes it a double long floating point on any modern 64 bit CPU.

Definition at line 120 of file MathFunctions.H.

#define L_SQRT_2   1.41421356237309514547462185873882845044136047363281250000000000000000L
 

Root of 2 DEFINED in cmath as M_SQRT2, but is not > 128 bit.

Definition at line 130 of file MathFunctions.H.

#define L_SQRT_2_PI   2.50662827463100050241576528481104525300698674060993831662992357634229L
 

Root of 2*Pi.

Definition at line 126 of file MathFunctions.H.

#define L_SQRT_PI   1.77245385090551602729816748334114518279754945612238712821380778985291L
 

Root of Pi.

Definition at line 128 of file MathFunctions.H.


Function Documentation

template<class T>
T acosec A  )  [inline]
 

inverse cosecant

Definition at line 314 of file MathFunctions.H.

References ASSERT.

Referenced by Pixels_xx_math_functions_xx_25().

template<class T>
T acosech A  )  [inline]
 

Inverse Hyperbolic Cosecant.

Definition at line 357 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_37().

template<class T>
T acotan A  )  [inline]
 

inverse cotangent

Definition at line 322 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_26().

template<class T>
T acotanh A  )  [inline]
 

Inverse Hyperbolic Cotangent.

Definition at line 364 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_38().

template<class T>
T asec A  )  [inline]
 

inverse secant

Definition at line 306 of file MathFunctions.H.

References ASSERT.

Referenced by Pixels_xx_math_functions_xx_24().

template<class T>
T asech A  )  [inline]
 

Inverse Hyperbolic Secant.

Definition at line 350 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_36().

template<class T, class T2>
T clampValue const T &  val,
const T2 &  bound1,
const T2 &  bound2
[inline]
 

Returns the number closest to val and between bound1 and bound2.

The bounds may be specified in either order (i.e., either (lo, hi) or (hi, lo).

Definition at line 537 of file MathFunctions.H.

Referenced by KLScorer::accum(), calc_x_contrib(), DirectFeedChannel::clampCoeffs(), drawCross(), drawCrossOR(), drawMeters(), drawPatch(), drawPatchBB(), fromVideoYUV422P(), genericRescale(), EnvSaliencyMap::getSalmap(), PixJpegYUV< T >::PixJpegYUV(), PixRGB< T >::PixRGB(), PixVideoYUV< T >::PixVideoYUV(), and warp3D().

template<class T>
T cosec A  )  [inline]
 

Cosecant.

Definition at line 292 of file MathFunctions.H.

References lobot::sin().

Referenced by Pixels_xx_math_functions_xx_20().

template<class T>
T cosech A  )  [inline]
 

Hyperbolic Cosecant.

Definition at line 336 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_31().

template<class T>
T cotan A  )  [inline]
 

Cotangent.

Definition at line 299 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_21().

template<class T>
T cotanh A  )  [inline]
 

Hyperbolic Cotangent.

Definition at line 343 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_32().

double expdev int &  idum  ) 
 

Randomly distributed Exponential deviate.

Definition at line 204 of file MathFunctions.C.

References log(), and ran2().

template<class T>
T gamma X,
const T  A,
const T  B
[inline]
 

find p from a gamma distrabution

Definition at line 449 of file MathFunctions.H.

References exp().

Referenced by ImageSpring< T >::computePos(), and main().

double gasdev int &  idum  ) 
 

Randomly distributed Gaussian deviate with zero mean and unit variance.

Definition at line 181 of file MathFunctions.C.

References log(), ran2(), and sqrt().

Referenced by ObjRec::generateNewEdgeState(), ObjRec::generateNewLineState(), getImage(), World2DInput::getLineOri(), and IRobotSim::getSensors().

template<class T>
T gauss diff,
const T  Std
[inline]
 

find p from a Gaussian distribution (instead of the mu and A, the difference is supplied)

Definition at line 439 of file MathFunctions.H.

References D_2_PI, exp(), and fastSqrt().

template<class T>
T gauss A,
const T  Mu,
const T  Std
[inline]
 

find p from a Gaussian distribution

Definition at line 428 of file MathFunctions.H.

References D_2_PI, exp(), and fastSqrt().

Referenced by gaborFilterRGB(), GaborPatch::GaborPatch(), Pixels_xx_math_functions_xx_45(), and Pixels_xx_math_functions_xx_46().

int getIdum const bool  useRandom = true  ) 
 

Get a random seed for ran2.

If useRandom is true, a random negative number will be return, otherwise a negative number that is always the same will be returned.

Definition at line 172 of file MathFunctions.C.

Referenced by ObjRec::generateNewEdgeState(), ObjRec::generateNewLineState(), getImage(), World2DInput::getLineOri(), and IRobotSim::getSensors().

void initRandomNumbers  ) 
 

Initialize random seeds from pseudo-random sources (e.g. time(), getpid()).

Definition at line 68 of file MathFunctions.C.

Referenced by BeeStemSim::BeeStemSim(), Contour::Contour(), Geons3D::Geons3D(), ObjRecBOF::getCodeWords(), SeaBee3MainDisplayForm::init(), main(), Objects::Objects(), ModelManager::paramChanged(), SimulationViewerI::run(), SceneGenerator::SceneGenerator(), ObjRec::start2(), Staircase::start2(), submain(), TwoHalfDSketch::TwoHalfDSketch(), and World2DInput::World2DInput().

void initRandomNumbersZero  ) 
 

Initialize random seeds with zero, to produce deterministic pseudo-random sequences.

Definition at line 77 of file MathFunctions.C.

Referenced by ModelManager::paramChanged().

template<class T>
bool isBounded A,
const T  upper,
const T  lower
[inline]
 

find if this value or pixel is bounded by the other two

Definition at line 474 of file MathFunctions.H.

bool isFinite const double &  arg  ) 
 

Function to check for finite value.

Definition at line 51 of file MathFunctions.C.

bool isFinite const float &  arg  ) 
 

Function to check for finite value.

Definition at line 50 of file MathFunctions.C.

bool isFinite const int32 arg  ) 
 

Function to check for finite value.

Definition at line 47 of file MathFunctions.C.

bool isFinite const int16 arg  ) 
 

Function to check for finite value.

Definition at line 46 of file MathFunctions.C.

bool isFinite const byte arg  ) 
 

Function to check for finite value.

Definition at line 45 of file MathFunctions.C.

template<class T>
T KLgamma const T  a,
const T  A,
const bool  doWow = false
[inline]
 

Compute the KL distance for a single gamma PDF.

Here we fix beta to be 1. This is a special case, but if we have it we can compute KL much faster. We can also use this if beta1 = beta2 The Chi Square is one such case where beta is 1/2 .

Parameters:
a New Alpha
A Current Alpha
doWow is true then convert output to Wows

Definition at line 1023 of file MathFunctions.H.

References fast_psi(), and wow().

template<class T>
T KLgamma const T  a,
const T  b,
const T  A,
const T  B,
const bool  doWow = false
[inline]
 

Compute the KL distance for a single gamma PDF.

Parameters:
a New Alpha
b New Beta
A Current Alpha
B Current Beta
doWow is true then convert output to Wows

Definition at line 915 of file MathFunctions.H.

References fast_psi(), fastLog(), and wow().

Referenced by KLjointGammaGamma(), and KLjointGammaGauss().

template<class T>
T KLgammaConst const T  a,
const T  A,
const T  C1,
const T  C2,
const bool  doWow = false
[inline]
 

Compute the KL distance for a single gamma PDF.

This method produces the best results for usage with RSVP data as measured by the MAG when using the example values for C1 and C2. It is also faster than the basic KL computation since we eliminate two divisions and one log computation.

Parameters:
a New Alpha
A Current Alpha
C1 the const standin for B/b - 1
C2 the const standin for log(b/B)
doWow is true then convert output to Wows

Definition at line 964 of file MathFunctions.H.

References fast_psi(), and wow().

template<class T>
T KLgauss const T  u,
const T  s,
const T  U,
const T  S,
const bool  doWow = false
[inline]
 

Compute the KL distance for a single gauss PDF.

Parameters:
u New Mean
s New Std.
U Current Mean
S Current Std.
doWow is true then convert output to Wows

Definition at line 1046 of file MathFunctions.H.

References log(), wow(), and x.

Referenced by KLjointGammaGauss().

template<class T>
T KLjointGammaGamma const T  ai,
const T  aj,
const T  bi,
const T  bj,
const T  Ai,
const T  Aj,
const T  Bi,
const T  Bj,
const bool  doWow = false,
const T  gammaBiasi = 1.0F,
const T  gammaBiasj = 1.0F
[inline]
 

Compute the KL distance for a joint gamma PDF.

Parameters:
ai New Alpha in model i
aj New Alpha in model j
bi New Beta in model i
bj New Beta in model j
Ai Current Alpha in model i
Aj Current Alpha in model j
Bi Current Beta in model i
Bj Current Beta in model j
doWow is true then convert output to Wows
This formula derived by T. Nathan Mundhenk 2007

Definition at line 799 of file MathFunctions.H.

References KLgamma(), and wow().

template<class T>
T KLjointGammaGauss const T  a,
const T  u,
const T  b,
const T  s,
const T  A,
const T  U,
const T  B,
const T  S,
const bool  doWow = false,
const T  gammaBias = 1.0F,
const T  gaussBias = 1.0F
[inline]
 

Compute the KL distance for a joint gamma gauss PDF.

Parameters:
a New Alpha in model 1
b New Beta in model 1
u New Mean in model 2
s New Std. in model 2
A Current Alpha in model 1
B Current Beta in model 1
U Current Mean in model 2
S Current Std. in model 2
doWow is true then convert output to Wows
This formula derived by T. Nathan Mundhenk 2007

Definition at line 863 of file MathFunctions.H.

References KLgamma(), KLgauss(), and wow().

double lngamma double  x  ) 
 

Compute log of Gamma.

Definition at line 215 of file MathFunctions.C.

References D_LOG_SQRT_2_PI, and log().

Referenced by poisson().

template<class T>
T logN A,
const T  n
[inline]
 

logN for pixel

Definition at line 380 of file MathFunctions.H.

References log().

Referenced by Pixels_xx_math_functions_xx_40().

template<class T>
T logsig A,
const T  a,
const T  b
[inline]
 

log sigmoid for pixel

Definition at line 390 of file MathFunctions.H.

References exp().

Referenced by featureClusterVision< FLOAT >::fCVrunStandAloneMSBatchTest(), and Pixels_xx_math_functions_xx_41().

template<class T>
T logsig2 x,
const T  a,
const T  b
[inline]
 

log sigmoid for pixel with offset

Values like a = 10 and b = 5 create a nice sigmoid for x = 0 to 1 since the center of the sigmoid is at b/a.

Parameters:
a The slope for the sigmoid
b The offset for the sigmoid

Definition at line 403 of file MathFunctions.H.

References exp().

Referenced by H2SVChannel::doInput().

template<class T>
T max A  )  [inline]
 

this nonsense operator is for compatability

Definition at line 460 of file MathFunctions.H.

template<class T>
T mean A  )  [inline]
 

this nonsense operator is for compatability

Definition at line 488 of file MathFunctions.H.

template<class T>
T min A  )  [inline]
 

this nonsense operator is for compatability

Definition at line 467 of file MathFunctions.H.

template<class T>
T onlineMean mu,
A,
int  n
[inline]
 

Compute the mean online by supplying the current mean and a new value mu is the previous mean, A is the current value and n is the number of values proceses so far

Definition at line 503 of file MathFunctions.H.

Referenced by HeliPose::getIMUBias().

double poisson const unsigned int  k,
const double  mu
 

Compute probability of drawing a value k from a Poisson of mean mu.

Definition at line 250 of file MathFunctions.C.

References exp(), lngamma(), and log().

Referenced by SurpriseModelOD::surprise().

double psi const double  x  )  [inline]
 

Compute the psi (derivarive of log of gamma) function (requires x > 0.0).

Definition at line 711 of file MathFunctions.H.

References cheb_eval(), fastLog(), LFATAL, and t.

Referenced by cuda_global_gaborFilter3(), lobot::filter(), gaborFilter(), gaborFilter2(), gaborFilter3(), and grating().

double ran2 int &  idum  ) 
 

Random number generator from Numerical Recipes in C book.

Long period >2x10^18 random number generator of L Ecuyer with Bays-Durham shuffle. Return a uniform deviate in the interval (0,1). Call with int variable as argument set to a negative value, and don't change this variable between calls unless you want to reseed the generator. You can get ain initial seed using the function getIdum()

Definition at line 130 of file MathFunctions.C.

References temp.

Referenced by expdev(), and gasdev().

double randomDouble  ) 
 

Generate a random double in [0.0,1.0).

This is a thin wrapper around drand48() or rand(), depending on which is available on the build platform.

Definition at line 86 of file MathFunctions.C.

References Dlist::rand().

Referenced by WTAwinner::buildFromSMcoords(), createCloud(), doAction(), lobot::doctored(), generateInput(), World2DInput::getLineOri(), getTargetPos(), Staircase::getValues(), image_patch(), inplaceAddBGnoise2(), inplaceSpeckleNoise(), likelihood(), main(), lobot::random_time_to_impact(), randomDoubleFromNormal(), BPnnet::randomizeWeights(), randomUpToNotIncluding(), HippocampusI::resampleParticles(), IT::resampleParticles(), V4::resampleParticles(), V4d::resampleParticles(), sample(), ObjRec::samplePosterior(), Beowulf::send(), and submain().

double randomDoubleFromNormal const double  s  ) 
 

Generate a random double from a normal distribution with mean zero and standard deviation s.

This function call randomDouble() 12 times to sample from normal distribution

Definition at line 96 of file MathFunctions.C.

References i, randomDouble(), and sum.

Referenced by Particle::drift_angle(), Particle::drift_position(), Contour::evolve(), MapperI::moveParticles(), IT::proposeParticles(), V4::proposeParticles(), V4d::proposeParticles(), V4d::proposeParticlesHarris(), Objects::proposeState(), TwoHalfDSketch::proposeState(), BeoHawkSim::simLoop(), HarrierSim::simLoop(), HippocampusI::updateParticleMotion(), and SeaBee3Simulator::updateSensors().

int randomUpToIncluding const int  n  ) 
 

Generate a random integer in [0,n] (i.e., including n).

This is a thin wrapper around lrand48() or rand(), depending on which is available on the build platform.

Definition at line 106 of file MathFunctions.C.

References randomUpToNotIncluding().

Referenced by ArmPlanner::calcGradient(), calcGradient(), Contour::Contour(), BeeStemSim::getSensors(), ArmPlanner::gibbsSampling(), gibbsSampling(), inplaceColorSpeckleNoise(), main(), randArmMove(), and SimulationViewerI::run().

int randomUpToNotIncluding const int  n  ) 
 

Generate a random integer in [0,n) (i.e., not including n).

This is a thin wrapper around lrand48() or rand(), depending on which is available on the build platform.

Definition at line 112 of file MathFunctions.C.

References randomDouble().

Referenced by PsychoDisplay::displayEyeTrackerCalibration(), ObjRecBOF::getCodeWords(), World2DInput::getLineLength(), ImageSpring< T >::getStats(), ImageSpring< T >::getStatsDist(), SimulationViewerCompress::getTraj(), inplaceColorSpeckleNoise(), main(), World2DInput::placeSquare(), randomUpToIncluding(), randShuffle(), ObjRec::sampleOriFromEdgeSpace(), ObjRec::sampleOriFromLineSpace(), ObjRec::samplePosFromEdgeSpace(), ObjRec::samplePosFromLineSpace(), ObjRec::samplePosterior(), ObjRec::sampleSizeFromLineSpace(), SimulationViewerStats::save1(), scramble(), and submain().

template<class T>
void randShuffle T *  array,
const uint  size
[inline]
 

Randomly shuffle given array.

Definition at line 553 of file MathFunctions.H.

References i, and randomUpToNotIncluding().

Referenced by PsychoDisplay::displayNumbers(), main(), run(), setCoherence(), and submain().

template<class T>
T saturate A,
const T  n
[inline]
 

saturate pixel at some value

Definition at line 419 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_43().

template<class T>
T sec A  )  [inline]
 

Secant.

Definition at line 285 of file MathFunctions.H.

References lobot::cos().

Referenced by main(), Pixels_xx_math_functions_xx_19(), BufferedFrameIstream::startStream(), Staircase::stop1(), EventLog::stop2(), and EyeTrackerISCAN::stopTracking().

template<class T>
T sech A  )  [inline]
 

Hyperbolic Secant.

Definition at line 329 of file MathFunctions.H.

Referenced by Pixels_xx_math_functions_xx_30().

template<class T>
T sign A  )  [inline]
 

return the sign of this item

Definition at line 371 of file MathFunctions.H.

template<class T>
int signOf const T &  x  )  [inline]
 

Returns -1 if x is negative, or 1 if x is positve.

Definition at line 530 of file MathFunctions.H.

Referenced by Contour::calcLineLikelihood(), drawLine(), V4d::getLineProbability(), and V4::getLineProbability().

template<class T>
T squareOf const T &  x  )  [inline]
 

Returns the square of x.

Definition at line 533 of file MathFunctions.H.

Referenced by avgOrient(), corrcoef(), count_pixels(), drawCircle(), drawDisk(), drawDiskCheckTarget(), V4::evaluateGeonParticles(), IT::evaluateObjectParticles(), V4d::evaluateParticles(), find_eigenvectors_2x2_positive_semi_def_real_matrix(), ImageSpring< T >::getClusteredImage(), ImageSpring< T >::getDistanceMasses(), V4::getGeonLikelihood(), Scorbot::getIKArmPos(), SoxChannel::getNonlinearResponse(), IT::getObjectLikelihood(), V4d::getParticleLikelihood(), ImageSpring< T >::getStatsDist(), Scorbot::gravityComp(), iorHelper(), V2::lineSegmentDetection(), main(), powell(), BeoSubCanny::powell(), segmentColor(), and HippocampusI::updateParticleSlamObservation().

template<class T>
T sum A  )  [inline]
 

this nonsense operator is for compatability

Definition at line 481 of file MathFunctions.H.

template<class T>
T tansig A  )  [inline]
 

tan sigmoid for pixel

Definition at line 411 of file MathFunctions.H.

References exp().

Referenced by Pixels_xx_math_functions_xx_42().

template<class T>
T wow const T &  k  )  [inline]
 

Convert a number into Wows, for instance a KL distance.

Wow's in this computation is the same as the conversion from Nats to Bits in KL

Definition at line 772 of file MathFunctions.H.

References D_LOG_2.

Referenced by KLgamma(), KLgammaConst(), KLgauss(), KLjointGammaGamma(), and KLjointGammaGauss().


Variable Documentation

double apsics_data[16] [static]
 

Initial value:

 {
  -.0204749044678185,
  -.0101801271534859,
   .0000559718725387,
  -.0000012917176570,
   .0000000572858606,
  -.0000000038213539,
   .0000000003397434,
  -.0000000000374838,
   .0000000000048990,
  -.0000000000007344,
   .0000000000001233,
  -.0000000000000228,
   .0000000000000045,
  -.0000000000000009,
   .0000000000000002,
  -.0000000000000000
}

Definition at line 626 of file MathFunctions.H.

Referenced by cheb_eval_apsi().

double psics_data[23] [static]
 

Initial value:

 {
  -.038057080835217922,
   .491415393029387130,
  -.056815747821244730,
   .008357821225914313,
  -.001333232857994342,
   .000220313287069308,
  -.000037040238178456,
   .000006283793654854,
  -.000001071263908506,
   .000000183128394654,
  -.000000031353509361,
   .000000005372808776,
  -.000000000921168141,
   .000000000157981265,
  -.000000000027098646,
   .000000000004648722,
  -.000000000000797527,
   .000000000000136827,
  -.000000000000023475,
   .000000000000004027,
  -.000000000000000691,
   .000000000000000118,
  -.000000000000000020
}

Definition at line 598 of file MathFunctions.H.

Referenced by cheb_eval_psi().


Generated on Sun Nov 22 13:45:10 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4