Template Class PDF

Nested Relationships

Nested Types

Class Documentation

template<typename _T>
class PDF

A container that supports probabilistic sampling over weighted data.

Public Functions

PDF() = default

Constructs an empty PDF.

inline PDF(const std::vector<_T> &d, const std::vector<double> &weights)

Constructs a PDF containing a given vector of data with given weights.

inline ~PDF()

Destructor. Clears allocated memory.

inline const std::vector<Element*> &getElements()

Get the current set of stored elements.

inline Element *add(const _T &d, const double w)

Adds a piece of data with a given weight to the PDF. Returns a corresponding Element, which can be used to subsequently update or remove the data from the PDF.

inline _T &sample(double r) const

Returns a piece of data from the PDF according to the input sampling value, which must be between 0 and 1.

inline void update(Element *elem, const double w)

Updates the data in the given Element with a new weight value.

inline double getWeight(const Element *elem) const

Returns the current weight of the given Element.

inline void remove(Element *elem)

Removes the data in the given Element from the PDF. After calling this function, the Element object should no longer be used.

inline void clear()

Clears the PDF.

inline std::size_t size() const

Returns the number of elements in the PDF.

inline const _T &operator[](unsigned int i) const

Returns indexed data from the PDF, according to order of insertion.

inline bool empty() const

Returns whether the PDF contains no data.

inline void printTree(std::ostream &out = std::cout) const

Prints the PDF tree to a given output stream. Used for debugging purposes.

class Element

A class that will hold data contained in the PDF.

Public Members

_T data_

The data contained in this Element.