ACDCGenerator::ACDCGen< Rnd, FncPtr > Class Template Reference

ACDCGen is a general class for sampling multi-dimensional functions. More...

#include <ACDCGen.h>

List of all members.

Public Types

typedef Rnd RndType
 Template argument typedef.
typedef ACDCRandomTraits< RndTypeRndTraits
 Template argument typedef.
typedef FncPtr FncPtrType
 Template argument typedef.
typedef vector< ACDCGenCell * > CellVector
 A vector of cells.
typedef vector< FncPtrTypeFncVector
 A vector of function objects.
typedef vector< DimTypeDimVector
 A vector of integers.
typedef DimVector::size_type size_type
 The size type of the vectors used.
typedef ACDCFncTraits< FncPtrTypeFncTraits
 Template argument typedef.

Public Member Functions

 ACDCGen (Rnd *r)
 Standard constructor requiring a random generator object to be used.
 ACDCGen ()
 Default Constructor.
 ~ACDCGen ()
 Destructor.
bool addFunction (DimType dim, FncPtrType f, double maxrat=-1.0)
 Add a function of a given dimension, dim, according to which points will be generated.
void clear ()
 Remove all added functions and reset the generator;.
FncPtrType generate ()
 Generate a point, choosing between the different functions specified.
void reject ()
 Reject the last generated point.
const DVectorlastPoint () const
 Return the last generated point.
double lastF () const
 Return the value of the last chosen function in the last point.
FncPtrType lastFunction () const
 Return the function chosen for the last generated point.
size_type last () const
 return the index of the function chosen for the last generated point.
template<typename POStream>
void output (POStream &) const
 This function is to be used in ThePEG for output to a persistent stream and will not work properly for normal ostreams.
template<typename PIStream>
void input (PIStream &)
 This function is to be used in ThePEG for input from a persistent stream and will not work properly for normal istreams.
Functions influencing the efficiency of the generation.
void eps (double newEps)
 Set the minimum cell size considered for this generation.
void margin (double newMargin)
 Set the safety margin used to multiply the highest found function value in a cell when setting its overestimated value.
void nTry (size_type newNTry)
 Set the number of points (with non-zero function value) used to initialize the tree of cells to use in the generation for each function.
void maxTry (long)
 Set the maximum number of attempts to generate a phase space point, or to find non-zero points in the initialization.
Information about the current generation.
double integral (FncPtrType f=FncPtrType()) const
 Return the current Monte Carlo estimate of the integral of the specified function (or all functions if NULL) over the unit volume.
double integralErr (FncPtrType f=FncPtrType()) const
 Return the error on the current Monte Carlo estimate of the integral of the specified function (or all functions if NULL) over the unit volume.
long n () const
 The number of accepted points so far.
long N () const
 The number of calls to generate() so far.
double efficiency () const
 The ratio of the number of accepted and number of tried points n()/N();.
int nBins () const
 Return the number of active cells created so far.
int depth () const
 Return the maximum depth of any tree of cells used.
double maxInt () const
 Return the current overestimation of the full integral of all specified functions over the unit volume.
Access to member variables.
double eps () const
 The minimum cell size considered for this generation.
double margin () const
 The safety margin used to multiply the highest found function value in a cell when setting its overestimated value.
size_type nTry () const
 The number of points used to initialize the tree of cells to use in the generation.
long maxTry () const
 The maximum number of attempts to generate a phase space point, or to find non-zero points in the initialization.
bool cheapRandom () const
 Returns true if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.
size_type size () const
 The number of functions used.
bool compensating ()
 Returns true if the generator is currently in a state of compensating an erroneous overestimation of one of the specified functions.
long compleft () const
 Return an estimate of how many points need to be sampled before the generator finishes compensating.
vector< ACDCGenCellInfoextractCellInfo () const
 Return a vector with information about all cells.
Functions related to the random number generator.
void cheapRandom (bool b)
 Set to true if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.
void setRnd (Rnd *r)
 Set a new random number generator.
double rnd () const
 Double precision number in the interval ]0,1[.
double rnd (double lo, double up) const
 Double precision number in the interval ]lo,up[.
void rnd (const DVector &lo, const DVector &up, DVector &r) const
 Fill the r vector with doubles r[i] in the interval ]lo[i],up[i][.
void rnd (DimType D, DVector &r) const
 Fill the D first elements in the r vector with doubles in the interval ]0,1[.
long rndInt (long x) const
 Integer in the interval [0,x[.

Static Public Attributes

static size_type maxsize
 The maximum recursion depth of the compensation so far.

Private Types

typedef vector< LevelLevelVector
 A vector (stack) of levels.

Private Member Functions

double doMaxInt ()
 Calculate the overestimated integral for all functions.
const FncVectorfunctions () const
 Return the vector of functions.
FncPtrType function (size_type i) const
 Return the i'th function.
const DimVectordimensions () const
 Return a vector with the dimensions of all functions.
DimType dimension (size_type i) const
 Return the dimension of the i'th function.
DimType lastDimension () const
 Return the dimension of the function chosen for the last generated point.
const CellVectorcells () const
 Return the roots of all cell trees.
ACDCGenCellcell (size_type i) const
 Return the root cell for the i'th function.
ACDCGenCelllastPrimary () const
 Return the root cell for the function chosen for the last generated point.
const DVectorsumMaxInts () const
 Return a vector with the incremental sum of overestimated integrals for each function.
ACDCGenCelllastCell () const
 Return the cell chosen for the last generated point.
void chooseCell (DVector &lo, DVector &up)
 Choose a function according to its overestimated integral and choose a cell to generate a point in.
void compensate (const DVector &lo, const DVector &up)
 Start the compensation procedure for the last chosen cell when a function velue has been found which exceeds the previous overestimation.
 ACDCGen (const ACDCGen &)
 Copy constructor is private and not implemented.
ACDCGenoperator= (const ACDCGen &)
 Assignment is private and not implemented.

Private Attributes

RndTypetheRnd
 The random number generator to be used for this Generator.
long theNAcc
 The number of accepted points (weight > 0) so far.
long theN
 The number of attempted points so far.
vector< long > theNI
 The number of attempts per function so far.
DVector theSumW
 The summed weights per function so far.
DVector theSumW2
 The summed squared weights per function so far.
double theEps
 The smallest possible division allowed.
double theMargin
 The factor controlling the loss of efficiency when compensating.
size_type theNTry
 The number of points to use to find initial average.
long theMaxTry
 The maximum number of attempts to generate a phase space point, or to find non-zero points in the initialization.
bool useCheapRandom
 True if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.
FncVector theFunctions
 A vector of functions.
DimVector theDimensions
 The dimensions of the functions in theFunctions.
CellVector thePrimaryCells
 The root of the cell tree for the functions in theFunctions.
DVector theSumMaxInts
 The accumulated sum of overestimated integrals of the functions in theFunctions.
size_type theLast
 The last index chosen.
ACDCGenCelltheLastCell
 The last cell chosen.
DVector theLastPoint
 The last point generated.
double theLastF
 The function value of the last point.
LevelVector levels
 The vector (stack) of levels.

Classes

struct  Level
 A helper struct representing a level of compensation. More...
struct  Slicer
 This is a help struct to perform the divide-and-conquer slicing of cells before starting the compensation procedure. More...


Detailed Description

template<typename Rnd, typename FncPtr>
class ACDCGenerator::ACDCGen< Rnd, FncPtr >

ACDCGen is a general class for sampling multi-dimensional functions.

ACDCGen can sample several functions simultaneously, selecting different functions according to the relative probabilities determined by their total integrals. The functions are sampled on a unit hypercube. Function object of any class can be used as long as the ACDCFncTraits class is specialized correctly. ACDCFncTraits can also be used to rescale values in the unit hypercube to any desired range. ACDCGen needs a random number generator. Again, random number generators of any class can be used as long as the ACDCRandomTraits class is specialized correctly.

To give an unweighted samlpe ACDCGen uses a compensating algorithm. Before the production sampling begins, the functions are sampled randomly in the hypercube a user-defined number of times to find an approximate maxumum value. The hypercube is then divided into cells each of which have an approximate maximum value of the function, to enable efficient sampling. The maxima are only approximate though and, if a function value is found above the maximum in a cell the ACDCGen will go into a compensating mode. The cell is then first subdivided further and in the following this cell will be over-sampled to compensate for that fact that it was under-sampled before. In this way the probability of obtaining a biased sample is reduced. Also rather functions with large peaks are then sampled rather efficiently. Functions with narrow peaks should, however, be avoided since there is no guarantee that the peack is actually hit.

Definition at line 48 of file ACDCGen.h.


Member Typedef Documentation

template<typename Rnd, typename FncPtr>
typedef Rnd ACDCGenerator::ACDCGen< Rnd, FncPtr >::RndType

Template argument typedef.

Definition at line 53 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef ACDCRandomTraits<RndType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::RndTraits

Template argument typedef.

Definition at line 55 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef FncPtr ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncPtrType

Template argument typedef.

Definition at line 57 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef vector<ACDCGenCell*> ACDCGenerator::ACDCGen< Rnd, FncPtr >::CellVector

A vector of cells.

Definition at line 59 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef vector<FncPtrType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncVector

A vector of function objects.

Definition at line 61 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef vector<DimType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::DimVector

A vector of integers.

Definition at line 63 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef DimVector::size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::size_type

The size type of the vectors used.

Definition at line 65 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
typedef ACDCFncTraits<FncPtrType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncTraits

Template argument typedef.

Definition at line 67 of file ACDCGen.h.


Member Function Documentation

template<typename Rnd, typename FncPtr>
bool ACDCGenerator::ACDCGen< Rnd, FncPtr >::addFunction ( DimType  dim,
FncPtrType  f,
double  maxrat = -1.0 
) [inline]

Add a function of a given dimension, dim, according to which points will be generated.

Note that each function, f, added like this will have its own tree of cells. The maxrat argument determines the lowest ratio of values allowed between the cell with lowest and highest value. If negative it is given by 1/nTry().

template<typename Rnd, typename FncPtr>
FncPtrType ACDCGenerator::ACDCGen< Rnd, FncPtr >::generate (  )  [inline]

Generate a point, choosing between the different functions specified.

The chosen function is returned, while the generated point is obtained by the function lastPoint().

template<typename Rnd, typename FncPtr>
void ACDCGenerator::ACDCGen< Rnd, FncPtr >::reject (  )  [inline]

Reject the last generated point.

Only used in the evaluation of the total integral.

template<typename Rnd, typename FncPtr>
const DVector& ACDCGenerator::ACDCGen< Rnd, FncPtr >::lastPoint (  )  const [inline]

Return the last generated point.

Returns:
a vector of doubles, each in the interval ]0,1[.

template<typename Rnd, typename FncPtr>
void ACDCGenerator::ACDCGen< Rnd, FncPtr >::eps ( double  newEps  )  [inline]

Set the minimum cell size considered for this generation.

The default is the machine limit for double precision times a hundred.

template<typename Rnd, typename FncPtr>
void ACDCGenerator::ACDCGen< Rnd, FncPtr >::margin ( double  newMargin  )  [inline]

Set the safety margin used to multiply the highest found function value in a cell when setting its overestimated value.

(Default is 1.1.)

template<typename Rnd, typename FncPtr>
long ACDCGenerator::ACDCGen< Rnd, FncPtr >::N (  )  const [inline]

The number of calls to generate() so far.

Note that the number of calls to the specified functions may be larger. It is up to the user to keep track of those.

template<typename Rnd, typename FncPtr>
bool ACDCGenerator::ACDCGen< Rnd, FncPtr >::cheapRandom (  )  const [inline]

Returns true if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.

Otherwise random numbers used for this will be reused.

template<typename Rnd, typename FncPtr>
bool ACDCGenerator::ACDCGen< Rnd, FncPtr >::compensating (  )  [inline]

Returns true if the generator is currently in a state of compensating an erroneous overestimation of one of the specified functions.

If so, the integral and the generated points are not statistically correct.

template<typename Rnd, typename FncPtr>
void ACDCGenerator::ACDCGen< Rnd, FncPtr >::cheapRandom ( bool  b  )  [inline]

Set to true if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.

Otherwise random numbers used for this will be reused.


Member Data Documentation

template<typename Rnd, typename FncPtr>
bool ACDCGenerator::ACDCGen< Rnd, FncPtr >::useCheapRandom [private]

True if generating random numbers are so cheap that a new one can be thrown everytime a sub-cell is chosen.

Otherwise random numbers used for this will be reused.

Definition at line 471 of file ACDCGen.h.

template<typename Rnd, typename FncPtr>
size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::maxsize [static]

The maximum recursion depth of the compensation so far.

Definition at line 744 of file ACDCGen.h.


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

Generated on Thu Apr 29 12:42:55 2010 for ThePEG by  doxygen 1.5.5