thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ACDCGenerator::ACDCGen< Rnd, FncPtr > Class Template Reference

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

#include <ACDCGen.h>

Inheritance diagram for ACDCGenerator::ACDCGen< Rnd, FncPtr >:

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...
 

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.
 
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.

typedef vector< LevelLevelVector
 A vector (stack) of levels.
 
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.
 
static size_type maxsize
 The maximum recursion depth of the compensation so far.
 
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[.
 
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.
 
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 &)=delete
 Assignment is private and not implemented.
 

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 49 of file ACDCGen.h.

Member Typedef Documentation

◆ CellVector

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

A vector of cells.

Definition at line 60 of file ACDCGen.h.

◆ DimVector

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

A vector of integers.

Definition at line 64 of file ACDCGen.h.

◆ FncPtrType

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

Template argument typedef.

Definition at line 58 of file ACDCGen.h.

◆ FncTraits

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

Template argument typedef.

Definition at line 68 of file ACDCGen.h.

◆ FncVector

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

A vector of function objects.

Definition at line 62 of file ACDCGen.h.

◆ LevelVector

template<typename Rnd , typename FncPtr >
typedef vector<Level> ACDCGenerator::ACDCGen< Rnd, FncPtr >::LevelVector
private

A vector (stack) of levels.

Definition at line 554 of file ACDCGen.h.

◆ RndTraits

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

Template argument typedef.

Definition at line 56 of file ACDCGen.h.

◆ RndType

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

Template argument typedef.

Definition at line 54 of file ACDCGen.h.

◆ size_type

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 66 of file ACDCGen.h.

Member Function Documentation

◆ addFunction()

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().

◆ cheapRandom() [1/2]

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.

◆ cheapRandom() [2/2]

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.

◆ compensating()

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.

◆ eps()

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.

◆ generate()

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().

◆ lastPoint()

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[.

◆ margin()

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.)

◆ N()

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.

◆ reject()

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.

Member Data Documentation

◆ levels

template<typename Rnd , typename FncPtr >
LevelVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::levels
private

The vector (stack) of levels.

Definition at line 559 of file ACDCGen.h.

◆ maxsize

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 745 of file ACDCGen.h.

◆ theDimensions

template<typename Rnd , typename FncPtr >
DimVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theDimensions
private

The dimensions of the functions in theFunctions.

Definition at line 482 of file ACDCGen.h.

◆ theEps

template<typename Rnd , typename FncPtr >
double ACDCGenerator::ACDCGen< Rnd, FncPtr >::theEps
private

The smallest possible division allowed.

Definition at line 449 of file ACDCGen.h.

◆ theFunctions

template<typename Rnd , typename FncPtr >
FncVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theFunctions
private

A vector of functions.

Definition at line 477 of file ACDCGen.h.

◆ theLast

template<typename Rnd , typename FncPtr >
size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::theLast
private

The last index chosen.

Definition at line 498 of file ACDCGen.h.

◆ theLastCell

template<typename Rnd , typename FncPtr >
ACDCGenCell* ACDCGenerator::ACDCGen< Rnd, FncPtr >::theLastCell
private

The last cell chosen.

Definition at line 503 of file ACDCGen.h.

◆ theLastF

template<typename Rnd , typename FncPtr >
double ACDCGenerator::ACDCGen< Rnd, FncPtr >::theLastF
private

The function value of the last point.

Definition at line 513 of file ACDCGen.h.

◆ theLastPoint

template<typename Rnd , typename FncPtr >
DVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theLastPoint
private

The last point generated.

Definition at line 508 of file ACDCGen.h.

◆ theMargin

template<typename Rnd , typename FncPtr >
double ACDCGenerator::ACDCGen< Rnd, FncPtr >::theMargin
private

The factor controlling the loss of efficiency when compensating.

Definition at line 454 of file ACDCGen.h.

◆ theMaxTry

template<typename Rnd , typename FncPtr >
long ACDCGenerator::ACDCGen< Rnd, FncPtr >::theMaxTry
private

The maximum number of attempts to generate a phase space point, or to find non-zero points in the initialization.

Definition at line 465 of file ACDCGen.h.

◆ theN

template<typename Rnd , typename FncPtr >
long ACDCGenerator::ACDCGen< Rnd, FncPtr >::theN
private

The number of attempted points so far.

Definition at line 429 of file ACDCGen.h.

◆ theNAcc

template<typename Rnd , typename FncPtr >
long ACDCGenerator::ACDCGen< Rnd, FncPtr >::theNAcc
private

The number of accepted points (weight > 0) so far.

Definition at line 424 of file ACDCGen.h.

◆ theNI

template<typename Rnd , typename FncPtr >
vector<long> ACDCGenerator::ACDCGen< Rnd, FncPtr >::theNI
private

The number of attempts per function so far.

Definition at line 434 of file ACDCGen.h.

◆ theNTry

template<typename Rnd , typename FncPtr >
size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::theNTry
private

The number of points to use to find initial average.

Definition at line 459 of file ACDCGen.h.

◆ thePrimaryCells

template<typename Rnd , typename FncPtr >
CellVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::thePrimaryCells
private

The root of the cell tree for the functions in theFunctions.

Definition at line 487 of file ACDCGen.h.

◆ theRnd

template<typename Rnd , typename FncPtr >
RndType* ACDCGenerator::ACDCGen< Rnd, FncPtr >::theRnd
private

The random number generator to be used for this Generator.

Definition at line 419 of file ACDCGen.h.

◆ theSumMaxInts

template<typename Rnd , typename FncPtr >
DVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theSumMaxInts
private

The accumulated sum of overestimated integrals of the functions in theFunctions.

Definition at line 493 of file ACDCGen.h.

◆ theSumW

template<typename Rnd , typename FncPtr >
DVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theSumW
private

The summed weights per function so far.

Definition at line 439 of file ACDCGen.h.

◆ theSumW2

template<typename Rnd , typename FncPtr >
DVector ACDCGenerator::ACDCGen< Rnd, FncPtr >::theSumW2
private

The summed squared weights per function so far.

Definition at line 444 of file ACDCGen.h.

◆ useCheapRandom

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 472 of file ACDCGen.h.


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