clModelMath Class Reference

SORTIE math library. More...

#include <ModelMath.h>

List of all members.

Static Public Member Functions

static float CalcPointValue (float fX, float fSlope, float fIntercept=0.0)
 Returns the value of a linear function.
static float GetRand ()
 Random number generator.
static float CalculateBasalArea (float fDbh)
 Calculates basal area.
static float Round (float fNumber, int iNumDigits)
 Rounds a number to a specified number of digits.
static int RandomRound (float fNumber)
 Uses a random number to decide whether to round a number up or down to the next integer.
static float CalculateWeibullFunction (float fDispersal, float fTheta, float fDistance)
 Calculates the exponential of the Weibull probability distribution function at a particular point.
static float CalculateLognormalFunction (float fX0, float fXb, float fDistance)
 Calculates the exponential of the Lognormal probability distribution function at a particular point.
static int PoissonRandomDraw (float fLambda)
 Returns a random Poisson-distributed number.
static float LognormalRandomDraw (float fMean, float fStdDev)
 Returns a random lognormally-distributed number.
static float NormalRandomDraw (float fStdDev)
 Returns a random normally-distributed number with mean zero and standard deviation sigma.
static int NegBinomialRandomDraw (float fMean, float fClumping)
 Returns a random negative binomially-distributed number.
static float AddBarkToDBH (float fDIB, float fA, float fB, float fC)
 Adds bark to a tree diameter.
static float GammaLn (float fX)
 For the use of PoissonRandomDraw.

Friends

class clSimManager
class clTestModelMath
 For testing random number generator.


Detailed Description

SORTIE math library.

This library provides some model-specific math functions.

The random number generator is very important. To make sure that no one can mess with the seed, I put the seed and the seed setting function in the private portion. Then clSimManager is a friend class and is the only one that can change the seed.

This used to be a library of C-style functions. But it turns out that the random number generator doesn't work right unless the seed is a class member.

Copyright 2005 Charles D. Canham.

Author:
Lora E. Murphy

Edit history:
-----------------
April 28, 2004 - Submitted as beta (LEM)
October25, 2004: Added AddBarkToDBH (LEM)
February 20, 2005: Changed into class (LEM)


Member Function Documentation

static float clModelMath::AddBarkToDBH ( float  fDIB,
float  fA,
float  fB,
float  fC 
) [static]

Adds bark to a tree diameter.

The equation is:

DBH = a + b * DIB + c * DIB2
where:

Parameters:
fDIB Diameter inside bark at 1.35 meters' height, in cm
fA "a" term in equation above
fB "b" term in equation above
fC "c" term in equation above
Returns:
Diameter outside the bark at 1.35 meters' height, in cm
Exceptions:
modelErr if DIB is less than or equal to 0, or large enough to create float overflow.

static float clModelMath::CalcPointValue ( float  fX,
float  fSlope,
float  fIntercept = 0.0 
) [static]

Returns the value of a linear function.

Parameters:
fX Point for which to calculate the function.
fSlope Slope of the function.
fIntercept Intercept of the function.
Returns:
Function value at the given point.

static float clModelMath::CalculateBasalArea ( float  fDbh  )  [static]

Calculates basal area.

Parameters:
fDbh DBH in cm for which to calculate basal area.
Returns:
Basal area in square meters.
Exceptions:
modelErr if DBH is less than or equal to 0.

static float clModelMath::CalculateLognormalFunction ( float  fX0,
float  fXb,
float  fDistance 
) [static]

Calculates the exponential of the Lognormal probability distribution function at a particular point.

Parameters:
fX0 Value of X0 variable
fXb Value of Xb variable
fDistance Distance, in meters, at which to calculate the function
Returns:
Value of function
Exceptions:
modelErr if fX0 or fDistance are not greater than 0, or if fXb is zero.

static float clModelMath::CalculateWeibullFunction ( float  fDispersal,
float  fTheta,
float  fDistance 
) [static]

Calculates the exponential of the Weibull probability distribution function at a particular point.

Parameters:
fDispersal Value of dispersal variable
fTheta Value of theta variable
fDistance Distance, in meters, at which to calculate the function
Returns:
Value of function

static float clModelMath::GammaLn ( float  fX  )  [static]

For the use of PoissonRandomDraw.

Returns the value ln(gamma(fX)) for fX > 0. Credit the Numerical Recipes in C book for this code, originally called gammln().

Parameters:
fX Value for which to compute the ln of the gamma function.
Returns:
Value of the function.

static float clModelMath::GetRand (  )  [static]

Random number generator.

This is a "minimal" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values). The value in m_iRandomSeed, below, is used as the seed. RNMX should approximate the largest floating value that is less than 1. Credit the Numerical Recipes in C book for this code, originally called ran1(). I have made it so it uses the seed in this class rather than requiring the seed to be passed in each call.

Returns:
a random number between 0 and 1.

static float clModelMath::LognormalRandomDraw ( float  fMean,
float  fStdDev 
) [static]

Returns a random lognormally-distributed number.

The lognormal distribution has the form

p(x) dx = 1/(x * sqrt(2 pi sigma2)) exp(-(ln(x) - zeta)2/2 sigma2) dx

for x > 0. Lognormal random numbers are the exponentials of gaussian random numbers.

This code is from the GSL (GNU Scientific Library). I simplified it to use our random number generator, and cut it from double to float precision.

Parameters:
fMean Mean of the distribution, or zeta in the above formula.
fStdDev Standard deviation of the distribution, or sigma in the above formula.
Returns:
Random lognormally-distributed number.

static int clModelMath::NegBinomialRandomDraw ( float  fMean,
float  fClumping 
) [static]

Returns a random negative binomially-distributed number.

The form of the distribution is from Equation 3.103 from Hilborn and Mangel (The Ecological Detective). Charlie Canham created this code.

Parameters:
fMean Function mean.
fClumping Clumping parameter.
Returns:
Random negative-binomially-distributed number.

static float clModelMath::NormalRandomDraw ( float  fStdDev  )  [static]

Returns a random normally-distributed number with mean zero and standard deviation sigma.

The probability distribution for normal random variates is, p(x) dx = {1 / sqrt{2 π σ2}} exp (-x2 / 2σ2) dx for x in the range -infty to +infty. Use the transformation z = mu + x on the numbers returned to obtain a normal distribution with mean mu. This function uses the Box-Mueller algorithm which requires two calls to the random number generator. This code is from the GSL (GNU Scientific Library) and was originally called gsl_ran_gaussian.

Parameters:
fStdDev Standard deviation.
Returns:
Random normally-distributed number.

static int clModelMath::PoissonRandomDraw ( float  fLambda  )  [static]

Returns a random Poisson-distributed number.

Credit the Numerical Recipes in C book for this code (originally called poidev())- I don't claim to understand it entirely).

Parameters:
fLambda Lambda (mean) of the Poisson function.
Returns:
Integer random draw.

static int clModelMath::RandomRound ( float  fNumber  )  [static]

Uses a random number to decide whether to round a number up or down to the next integer.

The number is split into integer and fractional parts. A random number is compared to the fractional part; if it is less than or equal to it, one is added to the integer part; otherwise the integer part is returned as-is.

Parameters:
fNumber Number to round.
Returns:
Rounded number.

static float clModelMath::Round ( float  fNumber,
int  iNumDigits 
) [static]

Rounds a number to a specified number of digits.

For this function, credit www.codeproject.com.

Parameters:
fNumber Number to round.
iNumDigits Number of digits to round the number to. If 0, the number is rounded to the nearest integer.
Returns:
Rounded number.


The documentation for this class was generated from the following file:
Generated on Wed Nov 29 08:42:22 2006 for SORTIE Core C++ Documentation by  doxygen 1.4.7