NAMD
|
#include <Random.h>
Public Member Functions | |
Random (void) | |
Random (unsigned long seed) | |
void | init (unsigned long seed) |
void | skip (void) |
void | split (int iStream, int numStreams) |
BigReal | uniform (void) |
BigReal | gaussian (void) |
BigReal | sum_of_squared_gaussians (int64_t num_gaussians) |
Return the sum of i.i.d. squared Gaussians. More... | |
Vector | gaussian_vector (void) |
long | integer (void) |
template<class Elem > | |
void | reorder (Elem *a, int n) |
void | uniform_array_f (float *a, int n) |
void | gaussian_array_f (float *a, int n) |
|
inline |
|
inline |
|
inline |
Definition at line 116 of file Random.h.
References uniform().
Referenced by Controller::adaptTempUpdate(), gaussian_array_f(), gaussian_vector(), Controller::langevinPiston1(), Controller::langevinPiston2(), colvarproxy_namd::rand_gaussian(), Controller::stochRescaleCoefficient(), and sum_of_squared_gaussians().
|
inline |
Fill length n array from standard Gaussian distribution.
Definition at line 255 of file Random.h.
References gaussian().
Referenced by Sequencer::langevinVelocitiesBBK2_SOA().
|
inline |
Definition at line 219 of file Random.h.
References gaussian().
Referenced by Controller::langevinPiston1(), Controller::langevinPiston2(), Sequencer::langevinVelocities(), Sequencer::langevinVelocitiesBBK2(), Sequencer::langevinVelocitiesBBK2_SOA(), Sequencer::reassignVelocities(), and Sequencer::reinitVelocities().
|
inline |
Definition at line 61 of file Random.h.
References RAND48_ADD, RAND48_MULT, RAND48_SEED, and UINT64_LITERAL.
Referenced by Random().
|
inline |
Definition at line 225 of file Random.h.
References skip(), and UINT64_LITERAL.
Referenced by reorder().
|
inline |
Definition at line 231 of file Random.h.
References integer().
Referenced by WorkDistrib::buildNodeAwarePeOrdering(), ComputePmeMgr::initialize(), ComputePmeMgr::initialize_pencils(), PmePencil< CBase_PmeZPencil >::order_init(), HomePatch::registerProxy(), and ParallelIOMgr::sendAtomsToHomePatchProcs().
|
inline |
|
inline |
Definition at line 77 of file Random.h.
References skip().
Referenced by Controller::Controller(), Sequencer::Sequencer(), and Node::startup().
|
inline |
Return the sum of i.i.d. squared Gaussians.
The sum of k squared standard normal random variables is equivalent to drawing a value from a chi-squared distribution with the shape given as the number of Gaussians. That is,
X ~ sum_n=1^k N(0, 1)^2 ~ chi^2(k).
This is in turn a special case of the Gamma distribution with shape k/2 and scale 2 (we could also use rate = 1/scale)
X ~ chi^2(k) ~ Gamma(k/2, 2) ~ 2*Gamma(k/2, 1).
The second relation follows from the scaling property of the Gamma distribution. Furthermore, when a Gamma distribution has unit scale and a large shape, it can be well-approximated by a normal distribution with mean and variance equal to the shape. Thus,
X ~ 2*Gamma(k/2, 1) ~= 2*N(k/2, sqrt(k/2)).
A quick numerical test shows that the mean integrated square error for this approximation is <10^-5 for shape >30 and <10^-6 for shape >100. We'll be conservative and use the latter cutoff.
We thus have three cases for k Gaussians:
0 < k <= 2 - just brute force generate and sum the Gaussians 2 < k <= 200 - use a (slightly modified) version of the Gamma distribution algorithm from Marsaglia and Tsang that is implemented in the GNU Science Library (GSL) else - use a single Gaussian distribution
The brute force method is almost certainly the slowest method, even for k = 3. The rigorous method takes about 150% as long as the approximate method (but this is invariant to the value of k).
num_gaussians | A positive integer number of Gaussians |
Definition at line 189 of file Random.h.
References gaussian(), and uniform().
Referenced by Controller::stochRescaleCoefficient().
|
inline |
Definition at line 109 of file Random.h.
References skip(), and UINT64_LITERAL.
Referenced by Controller::adaptTempUpdate(), gaussian(), Controller::monteCarloPressure_accept(), Controller::monteCarloPressure_prepare(), sum_of_squared_gaussians(), and uniform_array_f().
|
inline |