Class PDF

Inheritance Relationships

Derived Type

Class Documentation

class PDF

A class representing a PDF composed of one or more segments.

This class represents a PDF composed of one or more segments. This PDF can be properly normalized (so that the integral over all segments is unity) or not. It provides methods for sampling from the PDF and computing various integrals and expectation values from it.

Subclassed by pdfs::PDFReflect

Public Functions

template<typename SC, typename WC>
inline PDF(SC seg, WC wgt, SamplingMethods method = SamplingMethods::stopNearest, bool normalize = true)

Construct from array of segments and weights.

Template Parameters:
  • SC – Any contiguous container of PDFSegment pointers

  • WC – Any contiguous container of doubles

Parameters:
  • seg – Container of pointers to segments

  • wgt – Container of weights; must have same size as seg, all elements must be positive

  • method – Sampling method

  • normalize – Normalize or not?

template<typename SegT>
inline explicit PDF(std::unique_ptr<SegT> seg, const double wgt = 1.0, SamplingMethods method = SamplingMethods::stopNearest)

Construct a normalized PDF containing a single segment.

Templated on the concrete segment type (rather than taking a unique_ptr<PDFSegment> directly), even though seg is immediately stored as a unique_ptr<PDFSegment>, so that passing a unique_ptr to some derived segment type (the normal way to call this) is an exact match here rather than needing an implicit derived-to-base unique_ptr conversion; without that, overload resolution would sometimes prefer the array-of-segments-and-weights constructor above instead, mistaking the sampling method argument for a weights container.

Template Parameters:

SegT – The concrete segment type; must derive from PDFSegment

Parameters:
  • seg – A unique_ptr to the segment to use

  • wgt – Weight of the PDF

  • method – Sampling method

inline PDF()

Construct an empty PDF with no segments.

virtual ~PDF() = default
PDF(const PDF&) = delete
auto operator=(const PDF&) -> PDF& = delete
PDF(PDF&&) = default
auto operator=(PDF&&) -> PDF& = default
inline auto valid() const

Report if PDF has been initialized.

Returns:

True if the PDF is initialized and usable, false if not

inline auto getMin() const -> double

Get the lower limit of the segment.

Returns:

The lower limit of the segment.

inline auto getMax() const -> double

Get the upper limit of the segment.

Returns:

The upper limit of the segment.

inline auto getWeights() const -> const std::valarray<double>&

Get the weights of segments.

Returns:

The weights of the segments

inline auto getSampling() const -> SamplingMethods

Get sampling method.

Returns:

The current sampling method

inline void setSampling(SamplingMethods method)

Set sampling method.

Parameters:

method – Method to set

inline auto normalizePDF() -> void

Normalize the PDF.

inline auto normalized() const -> bool

Return whether the PDF is normalized.

inline virtual auto operator()(double x) const -> double

Evaluate the PDF at a given point.

Parameters:

x – The point at which to evaluate the PDF.

Returns:

The value of the PDF at the given point.

inline virtual auto expectationValue(const double a, const double b) const -> double

Calculate the expectation value of the PDF segment.

Parameters:
  • a – The lower limit of the range for expectation value calculation; if set to a value <= sMin, will be set to sMin_.

  • b – The upper limit of the range for expectation value calculation; if set to a value >= sMax, will be set to sMax_.

Returns:

The expectation value of the PDF segment.

inline virtual auto expectationValue() const -> double

Calculate the expectation value of the PDF segment over its entire range.

Returns:

The expectation value of the PDF segment.

inline virtual auto integral(const double a, const double b) const -> double

Calculate the integral of the PDF over a specified range.

Parameters:
  • a – The lower limit of the range for integral calculation; if set to a value <= sMin, will be set to sMin_.

  • b – The upper limit of the range for integral calculation; if set to a value >= sMax, will be set to sMax_.

Returns:

The integral of the PDF over the specified range.

inline auto integral() const -> double

Calculate the integral of the PDF over its full range.

Returns:

The integral of the PDF segment over the specified range.

inline virtual auto deltas() const -> std::vector<std::pair<double, double>>

Get the location and weight of every delta-function segment.

A delta-function segment is one whose own support is a single point (getMin() == getMax()). operator() never includes such a segment (a density is undefined there), but integral() does, so any quadrature against operator() must add these point masses separately – see utils::PDFIntegrator::integrate().

Returns:

One (location, weight) pair per delta-function segment, in segment order; empty if there are none

inline virtual auto draw(const double a = std::numeric_limits<double>::lowest(), const double b = std::numeric_limits<double>::max()) const -> double

Sample a random value from the PDF within a specified range.

Parameters:
  • a – The lower limit of the sampling range (should be >= sMin_, equal to sMin_ if unspecified).

  • b – The upper limit of the sampling range (should be <= sMax_, equal to sMax_ if unspecified).

Returns:

A random value drawn from the PDF within the specified range.

inline virtual auto draw(unsigned int nDraw, double a = std::numeric_limits<double>::lowest(), double b = std::numeric_limits<double>::max()) const -> std::vector<double>

Sample nDraw random values from the PDF within the specified range.

Parameters:
  • nDraw – Number of samples to draw.

  • a – The lower limit of the sampling range (should be >= sMin_, equal to sMin_ if not set).

  • b – The upper limit of the sampling range (should be <= sMax_, equal to sMax_ if not set).

Returns:

A vector of nDraw random values drawn from the PDF within the specified range.

inline virtual auto drawTarget(double target, double a = std::numeric_limits<double>::lowest(), double b = std::numeric_limits<double>::max()) const -> std::vector<double>

Draw a sample from the PDF targeting a fixed total value.

Parameters:
  • target – Target total to draw

  • a – The lower limit of the sampling range (should be >= sMin_, equal to sMin_ if not set).

  • b – The upper limit of the sampling range (should be <= sMax_, equal to sMax_ if not set).

Protected Attributes

std::vector<std::unique_ptr<PDFSegment>> seg_

Segments in the PDF

std::valarray<double> wgt_

Weights of segments

double sMin_

PDF lower limit

double sMax_

PDF upper limit

SamplingMethods method_

Sampling method for this PDF

bool normalized_

Is this PDF properly normalized?