MeanWalker
|
This class implements the Metropolis-Hastings method for taking samples from a particular probability distribution. More...
#include <metropoliswalker.h>
Public Member Functions | |
MetropolisWalker (RandomNumberGenerator *pRndGen) | |
Constructor, in which you need to specify the random number generator to be used. | |
bool | init (Function *pProbFunction, const double *pMinCoords, const double *pMaxCoords, const double *pStartCoords, bool keepInside=true) |
Initialize the sampler. | |
void | setNewStartCoordinates (double *pStartCoords) |
Set this position as the current position of the walker. | |
Protected Member Functions | |
virtual void | stepToNewCoords (const double *pCurCoords, double *pNewCoords) |
By overriding this function, you can change the way the walker steps to a new coordinate (be careful if you change this, without obeying certain rules, the underlying probability distribution will not be sampled correctly). |
This class implements the Metropolis-Hastings method for taking samples from a particular probability distribution.
This class implements the Metropolis-Hastings method for taking samples from a particular probability distribution. Is does this by creating a 'walker', an item which performs a sort of biased random walk, so that it takes samples from the specified distribution. The probability distribution can be specified either by itself, or as the logarithm of the distribution. In the first case, multiplication by a constant factor doens't matter (i.e. it doesn't have to be normed), which in the second case means that adding a specific constant does not matter.
meanwalker::MetropolisWalker::MetropolisWalker | ( | RandomNumberGenerator * | pRndGen | ) |
Constructor, in which you need to specify the random number generator to be used.
bool meanwalker::MetropolisWalker::init | ( | Function * | pProbFunction, |
const double * | pMinCoords, | ||
const double * | pMaxCoords, | ||
const double * | pStartCoords, | ||
bool | keepInside = true |
||
) |
Initialize the sampler.
Initialize the sampler.
pProbFunction | The probability density to be sampled. |
pMinCoords | Sets the minimum coordinates which are used together with the maximum coordinates to calculate the scale of the steps used in the random walk. |
pMaxCoords | Sets the maximum coordinates which are used together with the minimum coordinates to calculate the scale of the steps used in the random walk. |
pStartCoords | If not null, the walker will start at these coordinates. If null, a random position between pMinCoords and pMaxCoords is used as starting point. |
keepInside | If true, the random walk is not allowed to go beyond the boundaries specified by the minimum coordinates. If false, the walker can go outside these bounds. In that case the boundaries are only used to calculate the step size. |
void meanwalker::MetropolisWalker::setNewStartCoordinates | ( | double * | pStartCoords | ) |
Set this position as the current position of the walker.
virtual void meanwalker::MetropolisWalker::stepToNewCoords | ( | const double * | pCurCoords, |
double * | pNewCoords | ||
) | [protected, virtual] |
By overriding this function, you can change the way the walker steps to a new coordinate (be careful if you change this, without obeying certain rules, the underlying probability distribution will not be sampled correctly).