SORTIE Core C++ Documentation
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
clModelMath Class Reference

SORTIE math library. More...

#include <ModelMath.h>

Public Member Functions

 ~clModelMath ()
 

Static Public Member Functions

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

Static Public Attributes

static gsl_rng * randgen
 Random number generator. More...
 

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.

I have made some wrappers for GSL, for back-compatibility from before GSL was used. But I have also opened up the random number generator so that other classes can use the GSL functions directly if they wish.

Copyright 2005 Charles D. Canham.

Author
Lora E. Murphy


Edit history:
--------------—
October 20, 2011 - Wiped the slate clean for SORTIE 7.0 (LEM)

Constructor & Destructor Documentation

◆ ~clModelMath()

clModelMath::~clModelMath ( )
inline

Member Function Documentation

◆ AddBarkToDBH()

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:

  • DIB = diameter inside bark at 1.35 meters, in cm
  • DBH = diameter outside bark at 1.35 meters, in cm
  • a, b, and c are parameters
Parameters
fDIBDiameter 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
modelErrif DIB is less than or equal to 0, or large enough to create float overflow.

◆ CalcPointValue()

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

Returns the value of a linear function.

Parameters
fXPoint for which to calculate the function.
fSlopeSlope of the function.
fInterceptIntercept of the function.
Returns
Function value at the given point.

◆ CalculateBasalArea()

static float clModelMath::CalculateBasalArea ( float  fDbh)
static

Calculates basal area.

Parameters
fDbhDBH in cm for which to calculate basal area.
Returns
Basal area in square meters.
Exceptions
modelErrif DBH is less than or equal to 0.

◆ CalculateLognormalFunction()

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
fX0Value of X0 variable
fXbValue of Xb variable
fDistanceDistance, in meters, at which to calculate the function
Returns
Value of function
Exceptions
modelErrif fX0 or fDistance are not greater than 0, or if fXb is zero.

◆ CalculateWeibullFunction()

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
fDispersalValue of dispersal variable
fThetaValue of theta variable
fDistanceDistance, in meters, at which to calculate the function
Returns
Value of function

◆ GammaRandomDraw()

static float clModelMath::GammaRandomDraw ( float  fMean,
float  fScale 
)
static

Returns a random number drawn from the gamma distribution.

This is a wrapper for the GSL function gsl_ran_gamma. For this function, a = shape parameter, and b = scale parameter. The shape parameter a = mean / scale.

Parameters
fMeanFunction mean.
fScaleScale parameter.
Returns
Desired random deviate.

◆ GetRand()

static float clModelMath::GetRand ( )
static

Random number generator.

This just wraps a call to GSL's uniform random number generator.

Returns
a random number between 0 and 1.

◆ InverseGaussianRandomDraw()

static float clModelMath::InverseGaussianRandomDraw ( float  fMu,
float  fLambda 
)
static

Returns a random number over the inverse Gaussian distribution.

I got this code from http://www.cbr.washington.edu/node/617, which is the dissertation "Spatial and Temporal Models of Migrating Juvenile Salmon with Applications", by Richard W. Zabel, University of Washington.

The inverse Gaussian PDF is: f(x; μ, λ) = [λ /(2πx3)]^(1/2) * exp[(-λ(x-μ)2 )/ (2 μ2x)]

Parameters
fMumu.
fLambdalambda.

◆ LognormalRandomDraw()

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 just wraps the appropriate GSL function.

Parameters
fMeanMean of the distribution, or zeta in the above formula.
fStdDevStandard deviation of the distribution, or sigma in the above formula.
Returns
Random lognormally-distributed number.

◆ NegBinomialRandomDraw()

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
fMeanFunction mean.
fClumpingClumping parameter.
Returns
Random negative-binomially-distributed number.

◆ NormalRandomDraw()

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 just wraps the appropriate GSL function.

Parameters
fStdDevStandard deviation.
Returns
Random normally-distributed number.

◆ PoissonRandomDraw()

static int clModelMath::PoissonRandomDraw ( float  fLambda)
static

Returns a random Poisson-distributed number.

This just wraps the appropriate GSL function.

Parameters
fLambdaLambda (mean) of the Poisson function.
Returns
Integer random draw.

◆ RandomRound()

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
fNumberNumber to round.
Returns
Rounded number.

◆ Round()

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
fNumberNumber to round.
iNumDigitsNumber of digits to round the number to. If 0, the number is rounded to the nearest integer.
Returns
Rounded number.

◆ SetRandomSeed()

static void clModelMath::SetRandomSeed ( long  iSeed)
inlinestatic

Sets the random seed.

This should always be a negative number.

Parameters
iSeedSeed to set.

Member Data Documentation

◆ randgen

gsl_rng* clModelMath::randgen
static

Random number generator.

Currently set to the Mersenne Twister algorithm.


The documentation for this class was generated from the following file: