ThePEG 2.3.0
|
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>
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. | |
T | 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< Level > | levels |
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. | |
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.
|
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.
|
inline |
Erases all objects.
Definition at line 151 of file CompSelector.h.
References ThePEG::CompSelector< T, WeightType >::reset(), and ThePEG::CompSelector< T, WeightType >::selector.
|
inline |
Return true if this CompSelector is in a compensating state.
Definition at line 175 of file CompSelector.h.
References ThePEG::CompSelector< T, WeightType >::levels, and ThePEG::CompSelector< T, WeightType >::N.
Referenced by ThePEG::CompSelector< T, WeightType >::reweight(), and ThePEG::CompSelector< T, WeightType >::select().
|
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.
|
inline |
Input from a stream.
Definition at line 224 of file CompSelector.h.
References ThePEG::CompSelector< T, WeightType >::last, ThePEG::CompSelector< T, WeightType >::levels, ThePEG::CompSelector< T, WeightType >::N, ThePEG::CompSelector< T, WeightType >::selector, ThePEG::CompSelector< T, WeightType >::theMargin, and ThePEG::CompSelector< T, WeightType >::theTolerance.
|
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.
|
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().
|
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.
|
inline |
Output to a stream.
Definition at line 214 of file CompSelector.h.
References ThePEG::CompSelector< T, WeightType >::last, ThePEG::CompSelector< T, WeightType >::levels, ThePEG::CompSelector< T, WeightType >::N, ThePEG::CompSelector< T, WeightType >::selector, ThePEG::CompSelector< T, WeightType >::theMargin, and ThePEG::CompSelector< T, WeightType >::theTolerance.
|
inline |
Exit compensation mode and start selection procedure from scratch.
Definition at line 142 of file CompSelector.h.
References ThePEG::CompSelector< T, WeightType >::last, ThePEG::CompSelector< T, WeightType >::levels, and ThePEG::CompSelector< T, WeightType >::N.
Referenced by ThePEG::CompSelector< T, WeightType >::clear(), and ThePEG::CompSelector< T, WeightType >::insert().
|
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.
|
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.
|
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.
|
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().
|
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().
|
private |
The last selected object.
Definition at line 267 of file CompSelector.h.
Referenced by ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::output(), ThePEG::CompSelector< T, WeightType >::reset(), ThePEG::CompSelector< T, WeightType >::reweight(), and ThePEG::CompSelector< T, WeightType >::select().
|
private |
The currently active compensation levels.
Definition at line 284 of file CompSelector.h.
Referenced by ThePEG::CompSelector< T, WeightType >::compensating(), ThePEG::CompSelector< T, WeightType >::compleft(), ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::output(), ThePEG::CompSelector< T, WeightType >::reset(), and ThePEG::CompSelector< T, WeightType >::reweight().
|
private |
The number of selections so far.
Definition at line 262 of file CompSelector.h.
Referenced by ThePEG::CompSelector< T, WeightType >::compensating(), ThePEG::CompSelector< T, WeightType >::compleft(), ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::output(), ThePEG::CompSelector< T, WeightType >::reset(), ThePEG::CompSelector< T, WeightType >::reweight(), and ThePEG::CompSelector< T, WeightType >::select().
|
private |
The underlying selector.
Definition at line 257 of file CompSelector.h.
Referenced by ThePEG::CompSelector< T, WeightType >::clear(), ThePEG::CompSelector< T, WeightType >::input(), ThePEG::CompSelector< T, WeightType >::insert(), ThePEG::CompSelector< T, WeightType >::output(), ThePEG::CompSelector< T, WeightType >::reweight(), ThePEG::CompSelector< T, WeightType >::select(), and ThePEG::CompSelector< T, WeightType >::sum().
|
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().
|
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().