Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

LDSqBase Class Reference

This is the base class for all the simulation sequences including Monte Carlo (just random numbers). More...

#include <SimSeqs.h>

Inheritance diagram for LDSqBase:

Inheritance graph
[legend]
List of all members.

Public Methods

 LDSqBase (long *b=NULL, long dm=0, long iterations=0, long genau=0, double genau1=0., char *ex="",char *nm="")
virtual ~LDSqBase ()
virtual long GetDimension ()
virtual long GetLength ()
virtual char* GetName ()
virtual char* GetExtension ()
virtual long SetBases (long *b, long dm, long genau, double genau1)
virtual long GetBases (long *b, long dm)
virtual long NextElement (double *buffer, long bufflen, long nr=-1)
virtual bool CreateNumbers ()
virtual void SetNames (char *ex="",char *nm="")
virtual void SetSeed (long int status)
double ran1 (long *idum)
double ran2 (long *idum)
double ran3 (long *idum)

Public Attributes

long lastnr
bool qmc

Protected Methods

virtual void InitMethod (long *b=NULL, long dm=0, long iterations=0, long genau=0, double genau1=0., char *ex="",char *nm="")
virtual long CalculateNextElement (long nr, double *buffer, long bufflen)
virtual long InitData (long genau, double genau1)
virtual long ExitData ()
virtual long* InitGenericBases (long dm)

Protected Attributes

char* name
char * ext
long dim
long len
long* bases
double* numbers
bool created
long state
long iy
long iv [NTAB]
long type

Detailed Description

This is the base class for all the simulation sequences including Monte Carlo (just random numbers).

If you intend to use MC / QMC sequences in your program, use an object of LDSqBase* type, so that you can later determine which sequence you really want. To initialize the sequence, just initialize a subclass and type-cast it to LDSqBase*. To get the next element, use the method NextElement(double*buffer, long bufflen, long nr=-1); To get the name of the sequence use GetName() or GetExtension() You probably won't need any other methods.

If you decide you want any other sequence, just use a diffent constructor, you don't have to change anything else. e.g.

		 void docalc() {
			 // definition of vars, memory for buffer, get bases etc.
			 // ...
			 LDSqBase*numbers;
			 numbers=(LDSqBase*)new MonteCarlo();
			 //numbers=(LDSqBase*)new Halton(bases, 5); // uncomment this if you want to use the Halton -sequence. This is the only place where you need to change something if you want a different sequence.

			 numbers->NextElement(buffer, bufflen); // This is the same, whatever sequence you use!!!
			 // .. do whatever you want
			 numbers->NextElement(buffer, bufflen, 271); // returns the 271. element of the sequence

			 //.. some more code,
			 delete numbers; // This is the same for all sequences, too
			 //free mem etc.
		 }
		 

So, you see, to use different sequences, just initialize a differen object, but since all use LDSqBase as base class (which supplies the framework and the virtual functions that are implemented by the other sequence classes), the rest of the program, where you really work with the sequence just stays the same.

Author(s):
Reinhold Kainhofer


Constructor & Destructor Documentation

LDSqBase::LDSqBase ( long * b = NULL,
long dm = 0,
long iterations = 0,
long genau = 0,
double genau1 = 0.,
char * ex = "",
char * nm = "" )
 

Constructor, initializes the sequence.

Parameters:
b   Pointer to an array of longs containing the bases for the sequence (if needed, NULL or 0 otherwise). If the sequence needs bases, but NULL is given, it calls InitGenericBases(..) to create default bases (usually the lowest dim prime numbers)
dm   dimension of the sequence.
iterations   Number of points needed (e.g. used for the Hammesley-point set)
genau   Needed for the Halton-sequence (and maybe for some other sequences as well)
genau1   like genau
ex   extension returned by GetExtension(), usually you leave this to its default value
nm   Name of the sequence, returned by GetName(), usually you leave this to its default value

LDSqBase::~LDSqBase ( ) [virtual]
 


Member Function Documentation

long LDSqBase::CalculateNextElement ( long nr,
double * buffer,
long bufflen ) [protected, virtual]
 

Calculates the next element and stores it to the buffer.

If bufflen>dim, the remaining dimensions are pseudo-random numbers (i.e. the sequence is a hybrid sequence) This function should never be called directly! Use NextElement(..) instead!!!

See also:
NextElement()

Reimplemented in LDSqMonteCarlo, LDSqAfflerbach, LDSqNAlpha, LDSqHalton, LDSqAtanassov, LDSqHammersley, LDSqSobol, LDSqFaure, LDSqNetz, and LDSqNiederreiter.

bool LDSqBase::CreateNumbers ( ) [virtual]
 

Creates all the numbers (len defines how many are needed) and stores them in the array numbers, so that NextElement(..) can just copy them from the array and does not have to calcualate them.

long LDSqBase::ExitData ( ) [protected, virtual]
 

Do class-specific freeing of memory etc.

Called by the destructor

Reimplemented in LDSqMonteCarlo, LDSqHalton, LDSqAtanassov, LDSqSobol, LDSqFaure, LDSqNetz, and LDSqNiederreiter.

long LDSqBase::GetBases ( long * b,
long dm ) [virtual]
 

Returns the bases used for this sequence into the buffer b, at most dm of them and returns how many bases have been copied to b.

long LDSqBase::GetDimension ( ) [virtual]
 

Returns the dimension of the LD sequence (stored in the member variable dim).

char * LDSqBase::GetExtension ( ) [virtual]
 

long LDSqBase::GetLength ( ) [virtual]
 

Returns len (the number of points of this point set or sequence).

char * LDSqBase::GetName ( ) [virtual]
 

long LDSqBase::InitData ( long genau,
double genau1 ) [protected, virtual]
 

initialize the method specific data.

Reimplemented in LDSqMonteCarlo, LDSqHalton, LDSqAtanassov, LDSqSobol, LDSqFaure, LDSqNetz, and LDSqNiederreiter.

long * LDSqBase::InitGenericBases ( long dm ) [protected, virtual]
 

If no array of bases was given in the constructor, but the sequence needs them, this creates generic bases, e.g.

most of the time these are the dm lowest prime numbers, but you can override this by reimplementing InitGenericBases in your subclass

Reimplemented in LDSqNAlpha, LDSqHalton, LDSqAtanassov, and LDSqNetz.

void LDSqBase::InitMethod ( long * b = NULL,
long dm = 0,
long iterations = 0,
long genau = 0,
double genau1 = 0.,
char * ex = "",
char * nm = "" ) [protected, virtual]
 

Initializes the method, allocates memory needed,sets default values for the variables needed and calls InitData to do class-specific initialization...

Parameters:
b   Pointer to an array of longs containing the bases for the sequence (if needed, NULL or 0 otherwise)
dm   dimension of the sequence.
iterations   Number of points needed (e.g. used for the Hammesley-point set)
genau   Needed for the Halton-sequence (and maybe for some other sequences as well)
genau1   like genau
ex   extension returned by GetExtension(), usually you leave this to its default value
nm   Name of the sequence, returned by GetName(), usually you leave this to its default value

long LDSqBase::NextElement ( double * buffer,
long bufflen,
long nr = -1 ) [virtual]
 

Writes the nr-th element (if nr=-1 or not given, it writes the next element) of the sequence in a buffer.

If bufflen>dim, the remaining dimensions are pseudo-random numbers (i.e. the sequence is a hybrid sequence). This is the method you should call from within your program.

If the number have been pre-created (because CreateNumbers() has been called to create them), it just copies the appropriate element to the buffer, otherwise it will really calculate it.

long LDSqBase::SetBases ( long * b,
long dm,
long genau,
double genau1 ) [virtual]
 

Set the bases for the sequence (or change them if they were already given in the constructor).

void LDSqBase::SetNames ( char * ex = "",
char * nm = "" ) [virtual]
 

Changes the name of the sequence and the default extension (return value of GetName() and GetExtension()).

They are initialized by the constructor

void LDSqBase::SetSeed ( long int status ) [virtual]
 

Sets the seed for the ran1, ran2 and ran3 pseudo-number generators.

double LDSqBase::ran1 ( long * idum )
 

ran1 pseudo-Random number generator from the "Numerical Recipies in C": "minimal" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards.

double LDSqBase::ran2 ( long * idum )
 

ran2 improved pseudo-Random number generator from the "Numerical Recipies in C" long period rng of L'Ecuyer with Bays-Durham shuffle and added safeguards.

double LDSqBase::ran3 ( long * idum )
 

ran3 improved pseudo-Random number generator from the "Numerical Recipies in C" Knuth's subtractive method rng.


Member Data Documentation

long * LDSqBase::bases [protected]
 

long-field that stores the bases (if needed), e.g.

for the Halton/Hammersley sequence

bool LDSqBase::created [protected]
 

flag to show whether the elements are pre-created into the field numbers already and just need to be copied from there.

If false, the element needs to be calculated.

long LDSqBase::dim [protected]
 

number of dimensions (also the length of long* bases).

char * LDSqBase::ext [protected]
 

Strings, which contain the name and the 3-letter name of the sequence, e.g.

name="Halton", ext="hal"

long LDSqBase::iv [protected]
 

long LDSqBase::iy [protected]
 

long LDSqBase::lastnr
 

store the index of the last created element, to use lastnr+1 as default...

Some sequences can be calculated recursively (like the Halton sequences), so compare if the number needed is lastnr+1 (if yes, use the previous element to create the next one much faster

long LDSqBase::len [protected]
 

Number of points of this point set (for sequences this has no important meaning, but for the Hammersley set this is vital).

char * LDSqBase::name [protected]
 

Strings, which contain the name and the 3-letter name of the sequence, e.g.

name="Halton", ext="hal"

double * LDSqBase::numbers [protected]
 

If all the numbers should be created at the beginning, this field stores all the elements.

This can be quite effective if you need the same elements quite often in your code, since they are created just once at the beginning and not on the fly when needed (as it is the default

bool LDSqBase::qmc
 

Determines whether the sequence is a Low Discrepancy Sequence or not.

This is a flag that is set once in the constructor. Your Program can check if (numberObject->qmc) {Do for QMC-sequence} else {Do for pseudo-random sequence}

long LDSqBase::state [protected]
 

long LDSqBase::type [protected]
 


The documentation for this class was generated from the following files:
Generated at Wed Jun 20 19:48:19 2001 for LDSequences by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001