Public Member Functions | Private Attributes | Static Private Attributes

RanNumGen Class Reference

The Random Number Generator class. More...

#include <ocsRanNumGen.hh>

List of all members.

Public Member Functions

 RanNumGen (string InFileName)
 Class constructor.
 ~RanNumGen ()
 Class destructor.
void SaveCurrentState (void)
 Saves the current state of the random number generator.
void ResetRanNumGen (void)
 or that was saved by a call to RanNumGen::SaveCurrentState
float GetRanNum (void)
 Returns the next random number in the sequence. Returns values between 0 and 1.
float GetRanCosineBiased (double alpha, double beta, double *LikelihoodRatio)
 This method generates a biased sample for importance sampling.
float GetLikelihoodRatioForRanCosineBiased (double alpha, double ValFunction)
float GetRanSignBiased (double alpha, double *LikelihoodRatio)
float GetRanCosineBiased (double alpha, double *LikelihoodRatio)
float GetGaussianDeviate (void)
void ReadRanSeqParameters (string InFileName)
void WriteRanSeqParameters (string OutFileName)
 Writes the current state of the RNG to a file.

Private Attributes

long idum
long idumStart
long idum2
long idum2Start
long iy
long iyStart
long iv [NTAB]
long ivStart [NTAB]
string ContinuationFileName
 The name of the file to which the current state of the RNG is written.
string RestartFileName
int DebugLevel
 DebugLevel.

Static Private Attributes

static const long IM1 = 2147483563
static const long IM2 = 2147483399
static const double AM = 1.0/2147483563
static const long IMM1 = IM1 - 1
static const long IA1 = 40014
static const long IA2 = 40692
static const long IQ1 = 53668
static const long IQ2 = 52774
static const long IR1 = 12211
static const long IR2 = 3791
static const int NTAB = 32
static const long NDIV = (1+IMM1/NTAB)
static const double RNMX = 1.0 - 1.2e-7

Detailed Description

The Random Number Generator class.

The RanNumGen class uses the Random Number Generator (RNG) ran2 from Numerical Recipes in C. A helpful discussion of this random number generator can be found in the book Numerical Recipes in C or Online Numerical Recipes. Additional discussion can be found in "Random Number Generation and Monte Carlo Methods" by James E. Gentle (Springer).

The class contains methods that read and write the state of the RNG from and to a file. When running multiple jobs this feature enables the user to either continue along the random sequence from where you left off at the end of the last job or restart the RNG at the point in the sequence where the previous job started. The RNG can also be restarted within a job.

The class also contains methods that are used in importance sampling.


Constructor & Destructor Documentation

RanNumGen::RanNumGen ( string  InFileName  ) 

Class constructor.

The constructor reads parameters from an input parameter file.

Parameters:
InFileName,: Name of the input parameter file (string)

It does the following:

  1. Reads in OperationMode and initializes state of RNG accordingly.
  2. Writes the current state of the RNG to the file InFileName + ".restart"
  3. Initializes variables which store the state of the RNG at the time the constructor is called for possible later use by the method ResetRanNumGen()

The possible OperationModes are

  • 1: Starts the RNG in the state determined by the longint Seed which is to be specified in the input parameter file.
  • 2: Continue along the random sequence from where the previous job stopped by reading in the state of the RNG from the file InFileName + ".continue". This is the normal mode of operation.
  • 3: Restarts the RNG at the sme point in the sequence the the previous job started by reading in the state of the RNG from the file InFileName + ".restart".

References ContinuationFileName, DebugLevel, idum, idum2, iy, LogFile, LogFileSeparator(), LOWER_AND_UPPER, LOWER_ONLY, OPTIONAL_NO_WARNING, ReadInt(), ReadLongInt(), ReadRanSeqParameters(), RestartFileName, SaveCurrentState(), and WriteRanSeqParameters().

RanNumGen::~RanNumGen (  ) 

Class destructor.

Calls the method void WriteRanSeqParameters(string OutFileName) which writes the final state of the RNG to a file. Hence it should be explicitly called in application programs!

See also:
void WriteRanSeqParameters(string OutFileName)

References ContinuationFileName, and WriteRanSeqParameters().

Referenced by ChiSquareReceiver::~ChiSquareReceiver().


Member Function Documentation

float RanNumGen::GetGaussianDeviate ( void   ) 
float RanNumGen::GetLikelihoodRatioForRanCosineBiased ( double  alpha,
double  ValFunction 
)
float RanNumGen::GetRanCosineBiased ( double  alpha,
double  beta,
double *  LikelihoodRatio 
)
float RanNumGen::GetRanCosineBiased ( double  alpha,
double *  LikelihoodRatio 
)

The method returns a float which is the value of the biased sample.

Parameters:
alpha,: The biasing parameter.
LikelihoodRatio,: The value of the liklihood ratio of the sample that has been generated.

This is the biasing function that we used in the Reduced Model Applications.

References GetLikelihoodRatioForRanCosineBiased(), GetRanNum(), and log().

float RanNumGen::GetRanNum ( void   ) 

Returns the next random number in the sequence. Returns values between 0 and 1.

This code was taken directly from Numerical Recipes in C, function ran2.
See http://www.nr.com/ for documention.

References AM, IA1, IA2, idum, idum2, IM1, IM2, IMM1, IQ1, IQ2, IR1, IR2, iv, iy, NDIV, NTAB, and RNMX.

Referenced by RamanAmp::AddNoise(), Photodetector::AddShotNoise(), Photodetector::AddShotNoiseOLD(), OptAmplifier::AmplifyHomogeneous(), OptAmplifier::AmplifyOptSignalScalar(), OptAmplifier::AmplifyOptSignalVector(), OptAmplifier::AmplifyOptSignalVectorWithGainProfile(), RamanAmp::GeneticAlgorithms(), RamanAmp::GeneticAlgorithmsVaryCW(), RamanAmp::GeneticAlgorithmsVictor(), ReduOptFiber::GetFiberSampleCompleteScatt(), OptFiber::GetFiberSampleCompleteScatt(), OptFiber::GetFiberSampleImportSamplingCosRx(), OptFiber::GetFiberSampleImportSamplingExp(), OptFiber::GetFiberSampleImportSamplingFstSndOrderPDV_Exp(), OptFiber::GetFiberSampleImportSamplingFstSndOrderPDV_VariableAngleExp(), OptFiber::GetFiberSampleImportSamplingSndOrderPDV_Exp(), OptFiber::GetFiberSampleImportSamplingSndOrderPDV_VariableAngleExp(), OptFiber::GetFiberSampleUnifRxRzRy(), OptFiber::GetFiberSampleUnifRyRzRy(), OptFiber::GetFiberSampleUnifRz(), GetGaussianDeviate(), OptFiber::GetHeuristicBalanceForSndOrderPDV_VariableAngleExp(), ReduPolarizTransformer::GetImportSampPolarizTransformation(), OptFiberLocalError::GetNewFiberRealization(), GetRanCosineBiased(), OptSignal::GetRandomJones(), ReduOptFiber::GetRandomStepLengths(), OptFiber::GetRandomStepLengths(), GetRanSignBiased(), RamanAmp::PropagateNoise(), RamanAmp::PropagateSignalandNoise(), OptAmplifier::PropagateSignalandNoise(), BitString::SetRandomString(), RamanAmp::ShootingGeneticAlgorithms(), RamanAmp::ShootingGeneticAlgorithmsVaryCW(), and RamanAmp::ShootingGeneticAlgorithmsVictor().

float RanNumGen::GetRanSignBiased ( double  alpha,
double *  LikelihoodRatio 
)

References GetRanNum(), log(), and sgn().

void RanNumGen::ReadRanSeqParameters ( string  InFileName  ) 

Initializes the state of the RNG by reading the state parameters from a file

References idum, idum2, iv, iy, LogFile, NTAB, and WriteRanSeqParameters().

Referenced by RanNumGen().

void RanNumGen::ResetRanNumGen ( void   ) 

or that was saved by a call to RanNumGen::SaveCurrentState

Resets the RNG to the state it was in at the beginning of the job

References idum, idum2, idum2Start, idumStart, iv, ivStart, iy, iyStart, and NTAB.

Referenced by OptFiber::GetHeuristicBalanceForSndOrderPDV_VariableAngleExp().

void RanNumGen::SaveCurrentState ( void   ) 

Saves the current state of the random number generator.

Should be used in conjunction with RanNumGen::ResetRanNumGen

References idum, idum2, idum2Start, idumStart, iv, ivStart, iy, iyStart, and NTAB.

Referenced by RanNumGen().

void RanNumGen::WriteRanSeqParameters ( string  OutFileName  ) 

Writes the current state of the RNG to a file.

See also:
~RanNumGen()

References idum, idum2, iv, iy, and NTAB.

Referenced by RanNumGen(), ReadRanSeqParameters(), and ~RanNumGen().


Member Data Documentation

const double RanNumGen::AM = 1.0/2147483563 [static, private]

Referenced by GetRanNum().

The name of the file to which the current state of the RNG is written.

Referenced by RanNumGen(), and ~RanNumGen().

int RanNumGen::DebugLevel [private]

DebugLevel.

DebugLevel to LogFile

  1. 0: No output
  2. 1: Maximum output

Referenced by RanNumGen().

const long RanNumGen::IA1 = 40014 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IA2 = 40692 [static, private]

Referenced by GetRanNum().

long RanNumGen::idum [private]
long RanNumGen::idum2 [private]
long RanNumGen::idum2Start [private]

Referenced by ResetRanNumGen(), and SaveCurrentState().

long RanNumGen::idumStart [private]

Referenced by ResetRanNumGen(), and SaveCurrentState().

const long RanNumGen::IM1 = 2147483563 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IM2 = 2147483399 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IMM1 = IM1 - 1 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IQ1 = 53668 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IQ2 = 52774 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IR1 = 12211 [static, private]

Referenced by GetRanNum().

const long RanNumGen::IR2 = 3791 [static, private]

Referenced by GetRanNum().

long RanNumGen::iv[NTAB] [private]
long RanNumGen::ivStart[NTAB] [private]

Referenced by ResetRanNumGen(), and SaveCurrentState().

long RanNumGen::iy [private]
long RanNumGen::iyStart [private]

Referenced by ResetRanNumGen(), and SaveCurrentState().

const long RanNumGen::NDIV = (1+IMM1/NTAB) [static, private]

Referenced by GetRanNum().

const int RanNumGen::NTAB = 32 [static, private]
string RanNumGen::RestartFileName [private]

The name of the file to which the state of the RNG at the start of the current job is written.

Referenced by RanNumGen().

const double RanNumGen::RNMX = 1.0 - 1.2e-7 [static, private]

Referenced by GetRanNum().


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