#include <ACDCGen.h>
Public Types | |
typedef Rnd | RndType |
Template argument typedef. | |
typedef ACDCRandomTraits< RndType > | RndTraits |
Template argument typedef. | |
typedef FncPtr | FncPtrType |
Template argument typedef. | |
typedef vector< ACDCGenCell * > | CellVector |
A vector of cells. | |
typedef vector< FncPtrType > | FncVector |
A vector of function objects. | |
typedef vector< DimType > | DimVector |
A vector of integers. | |
typedef DimVector::size_type | size_type |
The size type of the vectors used. | |
typedef ACDCFncTraits< FncPtrType > | FncTraits |
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 DVector & | lastPoint () 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< ACDCGenCellInfo > | extractCellInfo () 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< Level > | LevelVector |
A vector (stack) of levels. | |
Private Member Functions | |
double | doMaxInt () |
Calculate the overestimated integral for all functions. | |
const FncVector & | functions () const |
Return the vector of functions. | |
FncPtrType | function (size_type i) const |
Return the i'th function. | |
const DimVector & | dimensions () 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 CellVector & | cells () const |
Return the roots of all cell trees. | |
ACDCGenCell * | cell (size_type i) const |
Return the root cell for the i'th function. | |
ACDCGenCell * | lastPrimary () const |
Return the root cell for the function chosen for the last generated point. | |
const DVector & | sumMaxInts () const |
Return a vector with the incremental sum of overestimated integrals for each function. | |
ACDCGenCell * | lastCell () 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. | |
ACDCGen & | operator= (const ACDCGen &) |
Assignment is private and not implemented. | |
Private Attributes | |
RndType * | theRnd |
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. | |
ACDCGenCell * | theLastCell |
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... |
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.
typedef Rnd ACDCGenerator::ACDCGen< Rnd, FncPtr >::RndType |
typedef ACDCRandomTraits<RndType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::RndTraits |
typedef FncPtr ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncPtrType |
typedef vector<ACDCGenCell*> ACDCGenerator::ACDCGen< Rnd, FncPtr >::CellVector |
typedef vector<FncPtrType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncVector |
typedef vector<DimType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::DimVector |
typedef DimVector::size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::size_type |
typedef ACDCFncTraits<FncPtrType> ACDCGenerator::ACDCGen< Rnd, FncPtr >::FncTraits |
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().
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().
void ACDCGenerator::ACDCGen< Rnd, FncPtr >::reject | ( | ) | [inline] |
Reject the last generated point.
Only used in the evaluation of the total integral.
const DVector& ACDCGenerator::ACDCGen< Rnd, FncPtr >::lastPoint | ( | ) | const [inline] |
Return the last generated point.
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.
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.)
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.
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.
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.
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.
bool ACDCGenerator::ACDCGen< Rnd, FncPtr >::useCheapRandom [private] |
size_type ACDCGenerator::ACDCGen< Rnd, FncPtr >::maxsize [static] |