📄 densitytreenode.hpp
字号:
#ifndef INDII_ML_AUX_DENSITYTREENODE_HPP#define INDII_ML_AUX_DENSITYTREENODE_HPP#include "vector.hpp"#include "matrix.hpp"namespace indii { namespace ml { namespace aux {/** * Node of a density tree. * * @author Lawrence Murray <lawrence@indii.org> * @version $Rev: 401 $ * @date $Date: 2008-03-05 13:54:28 +0000 (Wed, 05 Mar 2008) $ * * A node has a weight \f$w\f$, volume \f$v\f$ and density \f$\delta\f$, * related by the identity \f$w = \delta v\f$. * * @section DensityTreeInternal_serialization Serialization * * This class supports serialization through the Boost.Serialization * library. */class DensityTreeNode {public: /** * Default constructor. * * This should generally only be used when the object is to be * restored from a serialization. */ DensityTreeNode(); /** * Constructor. * * @param lower Lower bound on the hyper-rectangle of the node. * @param upper Upper bound on the hyper-rectangle of the node. * @param weight \f$w\f$; weight of the node. * @param volume \f$v\f$; volume of the node. * * The density across the node will be calculated as * \f$\delta = w/v\f$. */ DensityTreeNode(const vector& lower, const vector& upper, const double weight, const double volume); /** * Destructor. */ virtual ~DensityTreeNode(); /** * Get the weight of the node. * * @return \f$w\f$; the weight of the node. */ double getWeight() const; /** * Get the volume of the node. * * @return \f$v\f$; the volume of the node. */ double getVolume() const; /** * Get the density of the node. * * @return \f$\delta\f$; the density of the node. */ double getDensity() const; /** * Provide contribution to the expectation sum. * * @return Contribution to the expectation sum. */ virtual vector sumExpectation() = 0; /** * Provide contribution to the covariance sum. * * @return Contribution to the expectation sum. */ virtual symmetric_matrix sumCovariance() = 0; /** * Sample from the tree. * * @param u Random number between 0 and the total weight of the node. * * @return A sample from the tree. */ virtual vector sample(const double u) = 0; /** * Calculate the density at a given point. * * @param x \f$\mathbf{x}\f$; point at which to evaluate the * density. * * @return \f$p(\mathbf{x})\f$; the density at \f$\mathbf{x}\f$. */ virtual double densityAt(const vector& x) = 0; /** * Get lower bound on the hyper-rectangle of the node. * * @return Lower bound on the hyper-rectangle of the node. */ const vector& getLower() const; /** * Get upper bound on the hyper-rectangle of the node. * * @return Upper bound on the hyper-rectangle of the node. */ const vector& getUpper() const;private: /** * Weight of the node. */ double weight; /** * Volume of the node. */ double volume; /** * Density of the node. */ double density; /** * Lower bound on the hyper-rectangle of the node. */ vector lower; /** * Upper bound on the hyper-rectangle of the node. */ vector upper; /** * Serialize, or restore from serialization. */ template<class Archive> void serialize(Archive& ar, const unsigned int version); /* * Boost.Serialization requirements. */ friend class boost::serialization::access;}; } }}template<class Archive>void indii::ml::aux::DensityTreeNode::serialize(Archive& ar, const unsigned int version) { ar & weight; ar & volume; ar & density; ar & lower; ar & upper; /* post-condition */ assert (weight > 0.0); assert (volume > 0.0); assert (density > 0.0); assert (lower.size() == upper.size());}inline double indii::ml::aux::DensityTreeNode::getWeight() const { return weight;}inline double indii::ml::aux::DensityTreeNode::getVolume() const { return volume;}inline double indii::ml::aux::DensityTreeNode::getDensity() const { return density;}inline const indii::ml::aux::vector& indii::ml::aux::DensityTreeNode::getLower() const { return lower;}inline const indii::ml::aux::vector& indii::ml::aux::DensityTreeNode::getUpper() const { return upper;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -