Graphitti
A toolkit/software architecture to ease creating high-performance neural network simulators
Loading...
Searching...
No Matches
Norm Class Reference

Generate normally distributed random numbers. More...

#include <Norm.h>

Inheritance diagram for Norm:
Collaboration diagram for Norm:

Public Member Functions

 Norm (BGFLOAT m=DEFAULT_m, BGFLOAT s=DEFAULT_s, uint32_t seed=DEFAULT_seed)
 
virtual BGFLOAT operator() (void) override
 
void seed (BGFLOAT m, BGFLOAT s, uint32_t seed)
 Allow Norm re-seeding (with same behavior as initializers)
 
virtual void seed (uint32_t seed) override
 
virtual void seed () override
 
template<class Archive >
void serialize (Archive &archive)
 Cereal serialization method.
 
- Public Member Functions inherited from MTRand
 MTRand (uint32_t oneSeed)
 
 MTRand (uint32_t *const bigSeed, uint32_t seedLength=N)
 
BGFLOAT rand ()
 
BGFLOAT rand (BGFLOAT n)
 
BGFLOAT randExc ()
 
BGFLOAT randExc (BGFLOAT n)
 
BGFLOAT randDblExc ()
 
BGFLOAT randDblExc (BGFLOAT n)
 
uint32_t randInt ()
 
uint32_t randInt (uint32_t n)
 
BGFLOAT inRange (BGFLOAT min, BGFLOAT max)
 
BGFLOAT rand53 ()
 
BGFLOAT randNorm (BGFLOAT mean=0.0, BGFLOAT variance=0.0)
 
void seed (uint32_t *const bigSeed, uint32_t seedLength=N)
 
void save (uint32_t *saveArray) const
 
void load (uint32_t *const loadArray)
 
template<class Archive >
void serialize (Archive &archive)
 Cereal serialization method.
 

Static Public Member Functions

static MTRandCreate ()
 
- Static Public Member Functions inherited from MTRand
static MTRandCreate ()
 

Additional Inherited Members

- Static Public Attributes inherited from MTRand
static const int N = 624
 
static const int SAVE = N + 1
 
- Protected Member Functions inherited from MTRand
void initialize (uint32_t oneSeed)
 
void reload ()
 
uint32_t hiBit (uint32_t u) const
 
uint32_t loBit (uint32_t u) const
 
uint32_t loBits (uint32_t u) const
 
uint32_t mixBits (uint32_t u, uint32_t v) const
 
uint32_t twist (uint32_t m, uint32_t s0, uint32_t s1) const
 
- Static Protected Member Functions inherited from MTRand
static uint32_t hash (time_t t, clock_t c)
 
- Protected Attributes inherited from MTRand
uint32_t state [N]
 
int iNext
 
int left
 
- Static Protected Attributes inherited from MTRand
static const int M = 397
 

Detailed Description

Generate normally distributed random numbers.

This class allows you to create RNG objects that are independently seeded upon construction and return normally distributed random numbers.

This function generates normally distributed random numbers with mean of mu and standard deviation of sigma, using the polar method of Marsaglia and Bray, "A Convenient Method for Generating Normal Variables", SIAM Rev., 6: 260-264 (1964).

The algorithm is as follows:

Generate two uniformly distributed numbers, U1 and U2.

Let Vi = 2*Ui-1 for i=1,2, and let W = V1*V1 + V2*V2.

If W > 1, go back to step 1. Otherwise, let

Y = sqrt(-2*ln(W)/W), X1 = V1*Y, and X2 = V2*Y. Then X1 and X2 are normally distributed with mean of 0 and variance of 1.

Random numbers with mean of mu and standard deviation of sigma

are calculated by: X_prime = mu + sigma X.

Note that numbers are generated in pairs. On odd-numbered calls to operator(), pairs are calculated. On even-numbered calls, the second value is returned.

Modified from norm.c, from xneuron3

Definition at line 57 of file Norm.h.

Constructor & Destructor Documentation

◆ Norm()

Norm::Norm ( BGFLOAT m = DEFAULT_m,
BGFLOAT s = DEFAULT_s,
uint32_t seed = DEFAULT_seed )

The constructor allows specification of the mean, variance (default zero and one, respectively), and initial seed for the random number generator. Once created, a Norm object cannot have its mean or variance changed.

Parameters
mmean
svariance
seedseed for random number generator

Definition at line 92 of file Norm.cpp.

Member Function Documentation

◆ Create()

static MTRand * Norm::Create ( )
inlinestatic

Creates an instance of the class.

Returns
Reference to the instance of the class.

Definition at line 64 of file Norm.h.

◆ operator()()

BGFLOAT Norm::operator() ( void )
overridevirtual

This method makes instances functors; it returns normally distributed random numbers. Just a cute way of doing things.

Returns
pseudorandom number drawn from a normal distribution.

Reimplemented from MTRand.

Definition at line 64 of file Norm.cpp.

◆ seed() [1/3]

void Norm::seed ( )
overridevirtual

Reimplemented from MTRand.

Definition at line 109 of file Norm.cpp.

◆ seed() [2/3]

void Norm::seed ( BGFLOAT m,
BGFLOAT s,
uint32_t seed )

Allow Norm re-seeding (with same behavior as initializers)

Definition at line 96 of file Norm.cpp.

◆ seed() [3/3]

void Norm::seed ( uint32_t seed)
overridevirtual

Reimplemented from MTRand.

Definition at line 104 of file Norm.cpp.

◆ serialize()

template<class Archive >
void Norm::serialize ( Archive & archive)

Cereal serialization method.

Definition at line 126 of file Norm.h.


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