herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
ExSample::SimpleCellGrid Class Reference

A simple cell grid providing basic adaption and sampling. More...

#include <SimpleCellGrid.h>

Inheritance diagram for ExSample::SimpleCellGrid:

Classes

struct  Counter
 A simple counter to store information used for adaption. More...
 

Public Member Functions

 SimpleCellGrid ()
 Default constructor.
 
 SimpleCellGrid (const std::vector< double > &newLowerLeft, const std::vector< double > &newUpperRight, bool keepWeightInformation=true, double newWeight=0.0)
 Construct given boundaries and a weight.
 
virtual CellGridmakeInstance () const
 Produce a new instance of a cell grid.
 
virtual CellGridmakeInstance (const std::vector< double > &newLowerLeft, const std::vector< double > &newUpperRight, double newWeight=0.0) const
 Produce a new instance of a cell grid.
 
virtual void split (std::size_t newSplitDimension, double newSplitCoordinate)
 Split this cell grid in the given dimension and coordinate, if it is a leaf.
 
virtual void splitter (size_t dim, int rat)
 
const SimpleCellGridfirstChild () const
 Return the first child.
 
SimpleCellGridfirstChild ()
 Access the first child.
 
const SimpleCellGridsecondChild () const
 Return the second child.
 
SimpleCellGridsecondChild ()
 Access the second child.
 
const std::vector< std::pair< Counter, Counter > > & weightInformation () const
 Return weight information for adaption steps.
 
std::vector< std::pair< Counter, Counter > > & weightInformation ()
 Access weight information for adaption steps.
 
virtual void updateWeightInformation (const std::vector< double > &p, double w)
 Update the weight information for the given point.
 
void adjustReferenceWeight (double w)
 Adjust the reference weight.
 
double getReferenceWeight () const
 Return the reference weight.
 
virtual void adapt (double gain, double epsilon, std::set< SimpleCellGrid * > &newCells)
 Perform a default adaption step, splitting along the dimension which shows up the largest difference in average weights; if this exceeds gain, perform the split.
 
virtual void setWeights ()
 Update the weights of the cells from information accumulated so far.
 
template<class RndGenerator >
void sampleFlatPoint (std::vector< double > &p, RndGenerator &rnd) const
 Sample a point flat in this cell.
 
template<class RndGenerator >
void sampleFlatPoint (std::vector< double > &p, const std::vector< bool > &parameterFlags, RndGenerator &rnd) const
 Sample a point flat in this cell, keeping parameters fixed.
 
template<class RndGenerator , class Function >
void explore (std::size_t nPoints, RndGenerator &rnd, Function &f, std::set< SimpleCellGrid * > &newCells, std::ostream &warn)
 Explore the cell grid, given a number of points to be sampled in each cell; the weights of the cell will contain the maximum weight encountered.
 
template<class RndGenerator >
SimpleCellGridselectCell (RndGenerator &rnd)
 Select a cell.
 
template<class RndGenerator , class Function >
double sample (RndGenerator &rnd, Function &f, std::vector< double > &p, bool unweight, bool adjustReference)
 Sample a point and return its weight.
 
template<class RndGenerator , class Function >
std::pair< double, double > generate (RndGenerator &rnd, Function &f, std::vector< double > &p)
 Sample a point and return its weight.
 
template<class RndGenerator , class Function >
std::pair< double, double > generate (RndGenerator &rnd, Function &f, std::vector< double > &p, const std::vector< bool > &parameterFlags)
 Sample a point and return its weight.
 
virtual void fromXML (const XML::Element &)
 Fill CellGrid data from an XML element.
 
virtual XML::Element toXML () const
 Return an XML element for the data of this CellGrid.
 
- Public Member Functions inherited from ExSample::CellGrid
 CellGrid ()
 Default constructor.
 
 CellGrid (const std::vector< double > &newLowerLeft, const std::vector< double > &newUpperRight, double newWeight=0.0)
 Construct given boundaries and a weight.
 
virtual CellGridmakeInstance () const
 Produce a new instance of a cell grid.
 
virtual CellGridmakeInstance (const std::vector< double > &newLowerLeft, const std::vector< double > &newUpperRight, double newWeight=0.0) const
 Produce a new instance of a cell grid.
 
virtual ~CellGrid ()
 The destructor.
 
void boundaries (const std::vector< double > &newLowerLeft, const std::vector< double > &newUpperRight)
 Set the boundaries.
 
const std::vector< double > & lowerLeft () const
 Return the lower left corner of the cell grid.
 
const std::vector< double > & upperRight () const
 Return the upper right corner of the cell grid.
 
const std::vector< bool > & upperBoundInclusive () const
 Flag in which dimension this cell is upper bound inclusive.
 
double volume (const std::vector< double > &lowerLeft, const std::vector< double > &upperRight) const
 Calculate a volume given upper and lower bound.
 
bool isLeaf () const
 Return true, if this is a leaf in the tree.
 
std::size_t depth () const
 Return the depth of this grid.
 
std::size_t size () const
 Return the number of nodes contained in this grid.
 
virtual void split (std::size_t newSplitDimension, double newSplitCoordinate)
 Split this cell grid in the given dimension and coordinate, if it is a leaf.
 
std::pair< std::size_t, double > splitPoint () const
 Return the dimension and coordinate along which the first split of this grid occurs.
 
const CellGridfirstChild () const
 Return the first child.
 
CellGridfirstChild ()
 Access the first child.
 
const CellGridsecondChild () const
 Return the second child.
 
CellGridsecondChild ()
 Access the second child.
 
void splitCoordinates (std::size_t, std::set< double > &) const
 Fill split coordinates along a given dimension.
 
bool active () const
 Return true, if this grid is active with respect to the last parameter point passed.
 
double volume () const
 Return the volume relevant for the last parameter point set.
 
double integral () const
 Return the integral relevant for the last parameter point set.
 
double weight () const
 Return the weight.
 
void weight (double w)
 Set the weight.
 
void updateIntegral ()
 Update the integrals.
 
void minimumSelection (double p=0.1)
 Ensure a minimum cell selection probability.
 
bool contains (const std::vector< double > &point, const std::vector< bool > &parameterFlags) const
 Return true, if this grid contains the given parameter point.
 
double nonParametricVolume (const std::vector< double > &point, const std::vector< bool > &parameterFlags) const
 Get the volume relevant for the dimensions not considered parameters.
 
void updateIntegral (const std::vector< double > &point, const std::vector< bool > &parameterFlags, std::vector< bool >::iterator hashPosition)
 Set a parameter point and flag which dimensions are considered parameters.
 
double projectInterval (const std::pair< double, double > &interval, std::size_t dimension) const
 Return the projection to the given interval and dimension, provided the interval is not overlapping with more than one cell in the given dimension.
 
std::map< std::pair< double, double >, double > project (std::pair< double, double > interval, std::size_t dimension) const
 Return the projection to the given interval and dimension.
 
virtual void fromXML (const XML::Element &)
 Fill CellGrid data from an XML element.
 
virtual XML::Element toXML () const
 Return an XML element for the data of this CellGrid.
 
template<class RndGenerator >
void randomGrid (RndGenerator &rnd, std::size_t maxDepth, bool forceSplit=true)
 Generate a random grid of given maximum depth.
 
void dumpToC (std::ostream &os, const std::string &name) const
 Write out C code corresponding to the cell grid function.
 
void dumpPartToC (std::ostream &os, std::string prefix="") const
 Write out C code corresponding to the cell grid function.
 

Private Attributes

std::vector< std::pair< Counter, Counter > > theWeightInformation
 Weight information for adaption steps.
 
double theReferenceWeight
 The reference weight to be used for unweighting.
 

Detailed Description

A simple cell grid providing basic adaption and sampling.

Author
Simon Platzer

Definition at line 22 of file SimpleCellGrid.h.

Constructor & Destructor Documentation

◆ SimpleCellGrid()

ExSample::SimpleCellGrid::SimpleCellGrid ( )
inline

Default constructor.

Definition at line 30 of file SimpleCellGrid.h.

Member Function Documentation

◆ adjustReferenceWeight()

void ExSample::SimpleCellGrid::adjustReferenceWeight ( double  w)
inline

Adjust the reference weight.

Definition at line 172 of file SimpleCellGrid.h.

References theReferenceWeight.

Referenced by sample().

◆ explore()

template<class RndGenerator , class Function >
void ExSample::SimpleCellGrid::explore ( std::size_t  nPoints,
RndGenerator &  rnd,
Function &  f,
std::set< SimpleCellGrid * > &  newCells,
std::ostream &  warn 
)
inline

Explore the cell grid, given a number of points to be sampled in each cell; the weights of the cell will contain the maximum weight encountered.

If newCells is non-empty explore only these cells, otherwise explore all cells.

Definition at line 233 of file SimpleCellGrid.h.

References explore(), firstChild(), ExSample::CellGrid::isLeaf(), ExSample::CellGrid::lowerLeft(), sampleFlatPoint(), secondChild(), ExSample::CellGrid::size(), and updateWeightInformation().

Referenced by explore().

◆ firstChild() [1/2]

SimpleCellGrid & ExSample::SimpleCellGrid::firstChild ( )
inline

Access the first child.

Definition at line 74 of file SimpleCellGrid.h.

References ExSample::CellGrid::firstChild().

◆ firstChild() [2/2]

const SimpleCellGrid & ExSample::SimpleCellGrid::firstChild ( ) const
inline

Return the first child.

Definition at line 67 of file SimpleCellGrid.h.

References ExSample::CellGrid::firstChild().

Referenced by explore(), and selectCell().

◆ fromXML()

virtual void ExSample::SimpleCellGrid::fromXML ( const XML::Element )
virtual

Fill CellGrid data from an XML element.

Reimplemented from ExSample::CellGrid.

◆ generate() [1/2]

template<class RndGenerator , class Function >
std::pair< double, double > ExSample::SimpleCellGrid::generate ( RndGenerator &  rnd,
Function &  f,
std::vector< double > &  p 
)
inline

Sample a point and return its weight.

Definition at line 322 of file SimpleCellGrid.h.

References sampleFlatPoint(), selectCell(), updateWeightInformation(), and ExSample::CellGrid::weight().

◆ generate() [2/2]

template<class RndGenerator , class Function >
std::pair< double, double > ExSample::SimpleCellGrid::generate ( RndGenerator &  rnd,
Function &  f,
std::vector< double > &  p,
const std::vector< bool > &  parameterFlags 
)
inline

Sample a point and return its weight.

Definition at line 336 of file SimpleCellGrid.h.

References sampleFlatPoint(), selectCell(), updateWeightInformation(), and ExSample::CellGrid::weight().

◆ getReferenceWeight()

double ExSample::SimpleCellGrid::getReferenceWeight ( ) const
inline

Return the reference weight.

Definition at line 179 of file SimpleCellGrid.h.

References theReferenceWeight.

Referenced by sample().

◆ makeInstance() [1/2]

virtual CellGrid * ExSample::SimpleCellGrid::makeInstance ( ) const
virtual

Produce a new instance of a cell grid.

Reimplemented from ExSample::CellGrid.

◆ makeInstance() [2/2]

virtual CellGrid * ExSample::SimpleCellGrid::makeInstance ( const std::vector< double > &  newLowerLeft,
const std::vector< double > &  newUpperRight,
double  newWeight = 0.0 
) const
virtual

Produce a new instance of a cell grid.

Reimplemented from ExSample::CellGrid.

◆ sample()

template<class RndGenerator , class Function >
double ExSample::SimpleCellGrid::sample ( RndGenerator &  rnd,
Function &  f,
std::vector< double > &  p,
bool  unweight,
bool  adjustReference 
)
inline

◆ sampleFlatPoint() [1/2]

template<class RndGenerator >
void ExSample::SimpleCellGrid::sampleFlatPoint ( std::vector< double > &  p,
const std::vector< bool > &  parameterFlags,
RndGenerator &  rnd 
) const
inline

Sample a point flat in this cell, keeping parameters fixed.

Definition at line 215 of file SimpleCellGrid.h.

References ExSample::CellGrid::lowerLeft(), ExSample::CellGrid::size(), and ExSample::CellGrid::upperRight().

◆ sampleFlatPoint() [2/2]

template<class RndGenerator >
void ExSample::SimpleCellGrid::sampleFlatPoint ( std::vector< double > &  p,
RndGenerator &  rnd 
) const
inline

Sample a point flat in this cell.

Definition at line 203 of file SimpleCellGrid.h.

References ExSample::CellGrid::lowerLeft(), ExSample::CellGrid::size(), and ExSample::CellGrid::upperRight().

Referenced by explore(), generate(), and sample().

◆ secondChild() [1/2]

SimpleCellGrid & ExSample::SimpleCellGrid::secondChild ( )
inline

Access the second child.

Definition at line 88 of file SimpleCellGrid.h.

References ExSample::CellGrid::secondChild().

◆ secondChild() [2/2]

const SimpleCellGrid & ExSample::SimpleCellGrid::secondChild ( ) const
inline

Return the second child.

Definition at line 81 of file SimpleCellGrid.h.

References ExSample::CellGrid::secondChild().

Referenced by explore(), and selectCell().

◆ selectCell()

template<class RndGenerator >
SimpleCellGrid * ExSample::SimpleCellGrid::selectCell ( RndGenerator &  rnd)
inline

◆ split()

virtual void ExSample::SimpleCellGrid::split ( std::size_t  newSplitDimension,
double  newSplitCoordinate 
)
virtual

Split this cell grid in the given dimension and coordinate, if it is a leaf.

Reimplemented from ExSample::CellGrid.

◆ toXML()

virtual XML::Element ExSample::SimpleCellGrid::toXML ( ) const
virtual

Return an XML element for the data of this CellGrid.

Reimplemented from ExSample::CellGrid.

◆ weightInformation() [1/2]

std::vector< std::pair< Counter, Counter > > & ExSample::SimpleCellGrid::weightInformation ( )
inline

Access weight information for adaption steps.

Definition at line 161 of file SimpleCellGrid.h.

References theWeightInformation.

◆ weightInformation() [2/2]

const std::vector< std::pair< Counter, Counter > > & ExSample::SimpleCellGrid::weightInformation ( ) const
inline

Return weight information for adaption steps.

Definition at line 156 of file SimpleCellGrid.h.

References theWeightInformation.

Member Data Documentation

◆ theReferenceWeight

double ExSample::SimpleCellGrid::theReferenceWeight
private

The reference weight to be used for unweighting.

Definition at line 369 of file SimpleCellGrid.h.

Referenced by adjustReferenceWeight(), and getReferenceWeight().

◆ theWeightInformation

std::vector<std::pair<Counter,Counter> > ExSample::SimpleCellGrid::theWeightInformation
private

Weight information for adaption steps.

Definition at line 364 of file SimpleCellGrid.h.

Referenced by weightInformation().


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