#include <util.hh>
A nice implementation of an algorithm that samples from a gamma distributionwith code modified from the book :
Press, Teukolsky, Vetterling, and Flannery. "Numerical Recipes, The art of Scientific Computing", Third Edition. 2007 Cambridge University Press.
It additionally has a parameter that allows the entire distribution to be shifted by a given amount and a generate function that resamples until the chosen number is within a particular range. In the chemotaxis model, this code is used primarily to choose a new random angle from the distribution of changes in direction (fig 3 from Berg & Brown, Chemotaxis in Escherichia coli analysed by Three-dimensional Tracking, Nature, volume 239, (1972) )
Public Member Functions | |
GammaSampler (double alpha, double beta) | |
GammaSampler (double alpha, double beta, double meanShift) | |
double | gen () |
double | gen (double minAcceptableValue, double maxAcceptableValue) |
Protected Attributes | |
double | alpha |
double | oalpha |
double | beta |
double | a1 |
double | a2 |
double | meanShift |
GammaSampler::GammaSampler | ( | double | alpha, | |
double | beta | |||
) |
Constructor to generate a basic gamma distribution.
alpha | the alpha parameter (note, alpha=k=shape). | |
beta | the beta parameter (note, beta=1/theta=1/scale). |
GammaSampler::GammaSampler | ( | double | alpha, | |
double | beta, | |||
double | meanShift | |||
) |
Constructor to generate a gamma distribution that is shifted by the given amount.
alpha | the alpha parameter (note, alpha=k=shape). | |
beta | the beta parameter (note, beta=1/theta=1/scale). | |
meanShift | shifts the entire distribution by this amount. |
double GammaSampler::gen | ( | ) |
Generates a new random number (using the NFutil Mersenne Twister random number generator) sampled from the initialized gamma distribution.
double GammaSampler::gen | ( | double | minAcceptableValue, | |
double | maxAcceptableValue | |||
) |
Generates a new random number (using the NFutil Mersenne Twister random number generator) sampled from the initialized gamma distribution that lies within (inclusive) of the range given. Carefull here! Your range should be such that it doesn't take forever to find a number in the range!
minAcceptableValue | the minimum random value this function will return. | |
maxAcceptableValue | the maximum random value this function will return. |
double ChemotaxisUtil::GammaSampler::alpha [protected] |
double ChemotaxisUtil::GammaSampler::oalpha [protected] |
double ChemotaxisUtil::GammaSampler::beta [protected] |
double ChemotaxisUtil::GammaSampler::a1 [protected] |
double ChemotaxisUtil::GammaSampler::a2 [protected] |
double ChemotaxisUtil::GammaSampler::meanShift [protected] |