Class PDFReflect

Inheritance Relationships

Base Type

Class Documentation

class PDFReflect : public pdfs::PDF

A non-owning view of a PDF, reflected about a pivot point.

PDFReflect wraps a non-owning reference to another PDF and presents it, unmodified in shape, but reflected: a point x is mapped to reflect(x) = 2 * pivot - x before being handed to (or after being returned from) the wrapped PDF, where pivot defaults to the midpoint of the wrapped PDF’s own support, (getMin() + getMax()

) / 2, if not given explicitly. This is useful when an integrator or sampler needs to treat “distance

from some reference point” as its natural coordinate (e.g. stellar age – distance from the current simulation time – when the underlying

PDF is indexed by formation time instead) without having to construct a whole new PDF: a PDFReflect can be passed anywhere a const PDF& is expected (e.g. PDFIntegrator’s own p parameter), and every method below performs the appropriate coordinate flip transparently. An explicit pivot need not be the midpoint of the wrapped PDF’s own support (e.g. reflecting a star-formation-rate PDF about half of the current simulation time, rather than half of its own, typically much larger, declared support, to obtain an age coordinate) – see the two-argument constructor below.

Since PDFReflect derives from PDF but never populates seg_ or wgt_ with its own segments (getWeights() returns wgt_, which is set to a copy of the wrapped PDF’s own weights purely so the inherited, unmodified integral() – see its own comment below – still returns the correct total), valid() (which checks seg_.empty()) always reports false for a PDFReflect; that is not meaningful for this view and should not be relied on. Likewise, getMin()/getMax() always report the wrapped PDF’s own support, unchanged, regardless of pivot – not that support’s own image under reflect() – so that they remain useful as a safety clamp on integration bounds (see PDFIntegrator::integrate()’s own clamp) rather than an increasingly extreme range as pivot moves away from the wrapped PDF’s own midpoint.

Public Functions

inline explicit PDFReflect(const PDF &pdf)

Construct a reflected view of an existing PDF, about the midpoint of its own support.

Delegates to the explicit-pivot constructor below with pivot = (pdf.getMin() + pdf.getMax()) / 2, which reduces reflect(x) = 2 * pivot - x to pdf.getMax() - (x - pdf.getMin()) – i.e. this constructor’s own behavior is unchanged from reflecting about the midpoint of the wrapped PDF’s own support.

Parameters:

pdf – The PDF to view, reflected about (pdf.getMin() + pdf.getMax()) / 2; stored by reference, so it must outlive this PDFReflect

inline PDFReflect(const PDF &pdf, const double pivot)

Construct a reflected view of an existing PDF, about an explicit pivot.

Copies pdf’s own sMin_/sMax_/weights, unmodified by pivot – see this class’s own comment for why – so that getMin()/ getMax() (unmodified, inherited) and the no-argument integral() (also unmodified, inherited – see its own comment) report the correct values without needing to be overridden.

Parameters:
  • pdf – The PDF to view, reflected about pivot; stored by reference, so it must outlive this PDFReflect

  • pivot – The point to reflect about: x maps to 2 * pivot - x. Need not be the midpoint of pdf’s own support, or even lie within it (e.g. reflecting about half of a simulation’s current time, to obtain an age coordinate from a star-formation-rate PDF whose own support is deliberately much larger than any realistic simulation time – see io::SimControls’s own buildConstantSFR()).

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

Evaluate the reflected PDF at a given point.

Parameters:

x – The point at which to evaluate the PDF

Returns:

pdf(reflect(x))

inline virtual auto expectationValue() const -> double override

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

Returns:

reflect(pdf.expectationValue())

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

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

Returns:

pdf.deltas(), with each location reflected

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

Calculate the expectation value of the reflected PDF over a specified range.

Parameters:
  • a – The lower limit of the range, in the reflected (view) coordinate

  • b – The upper limit of the range, in the reflected (view) coordinate

Returns:

reflect(pdf.expectationValue(reflect(b), reflect(a)))

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

Calculate the integral of the reflected PDF over a specified range.

The no-argument integral() needs no override – see the constructor’s own comment.

Parameters:
  • a – The lower limit of the range, in the reflected (view) coordinate

  • b – The upper limit of the range, in the reflected (view) coordinate

Returns:

pdf.integral(reflect(b), reflect(a))

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

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

Parameters:
  • a – The lower limit of the sampling range, in the reflected (view) coordinate

  • b – The upper limit of the sampling range, in the reflected (view) coordinate

Returns:

reflect(pdf.draw(reflect(b), reflect(a)))

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> override

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

Parameters:
  • nDraw – Number of samples to draw

  • a – The lower limit of the sampling range, in the reflected (view) coordinate

  • b – The upper limit of the sampling range, in the reflected (view) coordinate

Returns:

pdf.draw(nDraw, reflect(b), reflect(a)), with reflect() applied to every element

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

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

Parameters:
  • target – Target total to draw

  • a – The lower limit of the sampling range, in the reflected (view) coordinate

  • b – The upper limit of the sampling range, in the reflected (view) coordinate

Returns:

pdf.drawTarget(target, reflect(b), reflect(a)), with reflect() applied to every element

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.