Class KernelDensity::PercentileCut

Nested Relationships

This class is a nested type of Template Class KernelDensity.

Nested Types

Class Documentation

class PercentileCut

A cut through the tree, bounding a marginal cumulative distribution, for percentile()

Holds the active terms – unopened nodes, each with its weight and extent in the dimension, and points evaluated exactly – and constant bounds on the terms retired from them, with the slack those add to the gap between the bounds. With s the square root of the marginal kernel’s metric, each term’s kernel cumulative distribution is Phi(u) = erfc(-s u) / 2.

Public Types

enum class Bound : std::uint8_t

Which bound on the cumulative distribution to evaluate

Values:

enumerator lower

F_L

enumerator upper

F_U

enumerator mean

(F_L + F_U) / 2

Public Functions

inline PercentileCut(const KernelDensity &kde, const std::size_t dim, const double s, const double tolP)

Start the cut at the root.

Parameters:
  • kde – The estimate

  • dim – The dimension

  • s – The square root of the marginal kernel’s metric

  • tolP – The tolerance in probability

inline auto eval(const double t, const Bound which) const -> std::pair<double, double>

Evaluate a bound and its derivative.

Parameters:
  • t – Where to evaluate it

  • which – The bound

Returns:

The bound and its derivative at t

inline auto solve(const Bound which, const double target, double a, double b, const double ftol) const -> std::pair<double, double>

Narrow a bracket on where a bound reaches a target.

Parameters:
  • which – The bound (non-decreasing)

  • target – The target

  • a – Left end of the bracket

  • b – Right end of the bracket

  • ftol – Stop once the bound at an end is within ftol of target

Returns:

[l, r] within [a, b], with the bound at l at most, and at r at least, the target (l = r = a if the bound at a is at least the target, b if the bound at b is at most it), narrowed by safeguarded Newton iterations until the bound at an end is within ftol of the target, or [l, r] is at rounding

inline auto hasNodes() const -> bool

Whether any active term is a node.

Returns:

True if some node is still unopened

inline void refine(const double tLo, const double tHi, const double tC)

Refine the cut for a bracket and candidate.

Retires the terms wholly left or right of [tLo, tHi] whose slack fits the budget, then opens the nodes contributing most to F_U - F_L at tC, largest first, until those left unopened sum to at most a quarter of the tolerance (all of them, for a zero tolerance), a leaf’s points becoming exact terms.

Parameters:
  • tLo – Left end of the bracket on the percentile

  • tHi – Right end of the bracket

  • tC – The candidate