thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::CompSelector< T, WeightType > Class Template Reference

The CompSelector class works like the Selector class in that it can be used to randomly select objects according to associated probabilities. More...

#include <CompSelector.h>

Inheritance diagram for ThePEG::CompSelector< T, WeightType >:

Classes

struct  Level
 Internal struct used for bookkeeping when compensating. More...
 

Public Member Functions

Standard constructors and destructors.
 CompSelector (double newMargin=1.1, double newTolerance=1.0e-6)
 The default constructor.
 
The main function controlling the selection and compensation.
WeightType insert (WeightType d, const T &t)
 Insert an object given a probability for this object.
 
template<typename RNDGEN >
T & select (RNDGEN &rnd)
 Selct an object randomly.
 
WeightType reweight (double &weight)
 Report the weight associated with the last selected object.
 
void reset ()
 Exit compensation mode and start selection procedure from scratch.
 
void clear ()
 Erases all objects.
 
void margin (double m)
 Set the margin used to get a new overestimated probability for an object when entering compensation mode.
 
void tolerance (double t)
 Set the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.
 
Simple access functions.
bool compensating ()
 Return true if this CompSelector is in a compensating state.
 
long compleft () const
 If in a compensating mode, return the number of selection needed before exiting this mode.
 
WeightType sum () const
 Return the sum of probabilities of the objects inserted.
 
double margin () const
 Return the margin used to get a new overestimated probability for an object when entering compensation mode.
 
double tolerance () const
 Return the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.
 

I/O functions.

Selector< T, WeightType > selector
 The underlying selector.
 
long N
 The number of selections so far.
 
last
 The last selected object.
 
double theMargin
 The margin used to get a new overestimated probability for an object when entering compensation mode.
 
double theTolerance
 Set the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.
 
vector< Levellevels
 The currently active compensation levels.
 
template<typename OStream >
void output (OStream &os) const
 Output to a stream.
 
template<typename IStream >
void input (IStream &is)
 Input from a stream.
 

Detailed Description

template<typename T, typename WeightType = double>
class ThePEG::CompSelector< T, WeightType >

The CompSelector class works like the Selector class in that it can be used to randomly select objects according to associated probabilities.

In addition, the CompSelector class is able to handle the case where the associated probabilities are overestimates and the selected object will be discarded according to some weight. If then a weight above one is encountered, this means that the overestimated probability for the selected object was wrong and it should in fact have been higher. If this happens, the CompSelecteor will go into compensation mode, which means that the selected object will be oversampled a period after the violation to compensate for having been undersampled before. Also the associated probability is adjusted to reflect the new overestimate.

The available functions are not as many as in Selector, and some of the works somewhat differently. Before starting sampling the objects should be added to a CompSelector object with the insert() function. To selct an object the select() function should be used. After that the weight with which the object should be accepted should be presented with the reweight() function which normally returns zero. If, however, the weight is larger than unity the new overestimated probability is returned and the CompSelector enters the compensating mode. Note that the weight is passed as a reference and may be changed in by the reweight function if in the compensating mode.

Definition at line 47 of file CompSelector.h.

Constructor & Destructor Documentation

◆ CompSelector()

template<typename T , typename WeightType = double>
ThePEG::CompSelector< T, WeightType >::CompSelector ( double  newMargin = 1.1,
double  newTolerance = 1.0e-6 
)
inline

The default constructor.

The optional argument gives the margin used to get a new overestimated probability for an object when entering compensation mode.

Definition at line 58 of file CompSelector.h.

Member Function Documentation

◆ clear()

template<typename T , typename WeightType = double>
void ThePEG::CompSelector< T, WeightType >::clear ( )
inline

◆ compensating()

template<typename T , typename WeightType = double>
bool ThePEG::CompSelector< T, WeightType >::compensating ( )
inline

◆ compleft()

template<typename T , typename WeightType = double>
long ThePEG::CompSelector< T, WeightType >::compleft ( ) const
inline

If in a compensating mode, return the number of selection needed before exiting this mode.

Definition at line 185 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::levels, and ThePEG::CompSelector< T, WeightType >::N.

◆ input()

template<typename T , typename WeightType = double>
template<typename IStream >
void ThePEG::CompSelector< T, WeightType >::input ( IStream &  is)
inline

◆ insert()

template<typename T , typename WeightType = double>
WeightType ThePEG::CompSelector< T, WeightType >::insert ( WeightType  d,
const T &  t 
)
inline

Insert an object given a probability for this object.

If the probability is zero or negative, the object will not be inserted and the probability itself is returned. Otherwise the sum of probabilities so far is returned. Note that if selection has already started and this CompSelector is in compensating mode, it will immediately leave this mode and the selection procedure will start from scratch.

Definition at line 75 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::reset(), and ThePEG::CompSelector< T, WeightType >::selector.

◆ margin() [1/2]

template<typename T , typename WeightType = double>
double ThePEG::CompSelector< T, WeightType >::margin ( ) const
inline

Return the margin used to get a new overestimated probability for an object when entering compensation mode.

Definition at line 199 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::theMargin.

Referenced by ThePEG::CompSelector< T, WeightType >::reweight().

◆ margin() [2/2]

template<typename T , typename WeightType = double>
void ThePEG::CompSelector< T, WeightType >::margin ( double  m)
inline

Set the margin used to get a new overestimated probability for an object when entering compensation mode.

Definition at line 160 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::theMargin.

◆ output()

template<typename T , typename WeightType = double>
template<typename OStream >
void ThePEG::CompSelector< T, WeightType >::output ( OStream &  os) const
inline

◆ reset()

template<typename T , typename WeightType = double>
void ThePEG::CompSelector< T, WeightType >::reset ( )
inline

◆ reweight()

template<typename T , typename WeightType = double>
WeightType ThePEG::CompSelector< T, WeightType >::reweight ( double &  weight)
inline

Report the weight associated with the last selected object.

Returns the zero if weight was below unity, otherwise the compensation mode will be entered and the new overestimated probabilty for the last selected object will be returned.

Definition at line 105 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::compensating(), ThePEG::CompSelector< T, WeightType >::last, ThePEG::CompSelector< T, WeightType >::Level::lastN, ThePEG::CompSelector< T, WeightType >::levels, ThePEG::CompSelector< T, WeightType >::margin(), ThePEG::CompSelector< T, WeightType >::N, ThePEG::CompSelector< T, WeightType >::selector, ThePEG::CompSelector< T, WeightType >::tolerance(), and ThePEG::CompSelector< T, WeightType >::Level::weight.

◆ select()

template<typename T , typename WeightType = double>
template<typename RNDGEN >
T & ThePEG::CompSelector< T, WeightType >::select ( RNDGEN &  rnd)
inline

Selct an object randomly.

Given a random number generator which generates flat random numbers in the interval ]0,1[ with the operator()() function, select an object according to the individual probabilities specified when they were inserted. If the generated number is outside the allowed range or the Selector is empty, a range_error will be thrown. The generator should have a push_back function which will be used push back a uniform random number in the interval ]0,1[ calculated from the fraction of rnd which was in the range of the selected object.

Definition at line 93 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::compensating(), ThePEG::CompSelector< T, WeightType >::last, ThePEG::CompSelector< T, WeightType >::N, and ThePEG::CompSelector< T, WeightType >::selector.

◆ sum()

template<typename T , typename WeightType = double>
WeightType ThePEG::CompSelector< T, WeightType >::sum ( ) const
inline

Return the sum of probabilities of the objects inserted.

Note that probabilities specified when objects are inserted are rescaled with this number to give unit probability for 'select()'.

Definition at line 193 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::selector.

◆ tolerance() [1/2]

template<typename T , typename WeightType = double>
double ThePEG::CompSelector< T, WeightType >::tolerance ( ) const
inline

Return the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.

Definition at line 205 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::theTolerance.

Referenced by ThePEG::CompSelector< T, WeightType >::reweight().

◆ tolerance() [2/2]

template<typename T , typename WeightType = double>
void ThePEG::CompSelector< T, WeightType >::tolerance ( double  t)
inline

Set the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.

Definition at line 166 of file CompSelector.h.

References ThePEG::CompSelector< T, WeightType >::theTolerance.

Referenced by ThePEG::LesHouchesEventHandler::LesHouchesEventHandler().

Member Data Documentation

◆ last

◆ levels

◆ N

◆ selector

◆ theMargin

template<typename T , typename WeightType = double>
double ThePEG::CompSelector< T, WeightType >::theMargin
private

The margin used to get a new overestimated probability for an object when entering compensation mode.

Definition at line 273 of file CompSelector.h.

Referenced by ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::margin(), and ThePEG::CompSelector< T, WeightType >::output().

◆ theTolerance

template<typename T , typename WeightType = double>
double ThePEG::CompSelector< T, WeightType >::theTolerance
private

Set the tolerance for how much a weight is allowed to be larger than unity before starting the compensation.

Definition at line 279 of file CompSelector.h.

Referenced by ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::output(), and ThePEG::CompSelector< T, WeightType >::tolerance().


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