📄 densitytreefactory.hpp
字号:
#ifndef INDII_ML_AUX_DENSITYTREEFACTORY#define INDII_ML_AUX_DENSITYTREEFACTORY#include "DensityTreeNode.hpp"#include "DiracMixturePdf.hpp"namespace indii { namespace ml { namespace aux {/** * Factory for producing density tree nodes. * * @author Lawrence Murray <lawrence@indii.org> * @version $Rev: 387 $ * @date $Date: 2008-02-15 22:27:57 +0000 (Fri, 15 Feb 2008) $ */class DensityTreeFactory {public: /** * Strategies for hyper-rectangle splits. */ enum DensityTreeSplitStrategy { /** * Split on the dimension with greatest variance. */ SPLIT_VARIANCE, /** * Split on the dimension with greatest length. */ SPLIT_LENGTH, /** * Split on a random dimension. */ SPLIT_RANDOM };private: /** * Bounded weighted sample set. */ struct BoundedDiracMixturePdf { /** * The weighted sample set. */ DiracMixturePdf p; /** * Lower bound on the hyper-rectangle enclosing the weighted samples. */ vector* lower; /** * Upper bound on the hyper-rectangle enclosing the weighted samples. */ vector* upper; }; /** * Split bounded weighted sample set. */ struct SplitDiracMixturePdf { /** * Left side of the split. */ DiracMixturePdf left; /** * Right side of the split. */ DiracMixturePdf right; /** * Index of the split dimension. */ unsigned int index; /** * Value at the split. */ double value; }; /** * Bounds. */ struct Bounds { /** * Lower bound. */ vector lower; /** * Upper bound. */ vector upper; };public: /** * Constructor. * * @param P \f$P\f$; used to calibrate the sample and depth thresholds * which determine whether to create an internal or leaf node. The sample * threshold will be set to \f$\sqrt{P}\f$ and the depth threshold to * \f$\frac{1}{4}\log_{2}P\f$. Usually @p P is the total number of samples * in the weighted sample set from which the tree will be constructed. * @param rho \f$\rho\f$; shrinkage parameter for mixing density * calculations from multiple levels of the tree. * @param strategy Hyper-rectangle splitting strategy. */ DensityTreeFactory(const unsigned int P, const double rho = 0.0, const DensityTreeSplitStrategy strategy = SPLIT_RANDOM); /** * Constructor. * * @param sampleThreshold Minimum number of samples for a node to be * split so as to become an internal node. * @param depthThreshold Maximum depth of tree. * @param rho \f$\rho\f$; shrinkage parameter for mixing density * calculations from multiple levels of the tree. * @param strategy Hyper-rectangle splitting strategy. */ DensityTreeFactory(const unsigned int sampleThreshold, const unsigned int depthThreshold, const double rho = 0.0, const DensityTreeSplitStrategy strategy = SPLIT_RANDOM); /** * Destructor. */ virtual ~DensityTreeFactory(); /** * Create new density tree node. * * @param p Weighted sample set from which to build the density tree. * * Hyper-rectangle bounds will be calculated from the extreme points * in the weighted sample set. * * @return The density tree node. Caller claims ownership. */ DensityTreeNode* create(DiracMixturePdf& p) const;private: /** * Minimum number of samples for node to be split. */ const unsigned int sampleThreshold; /** * Maximum depth of tree. */ const unsigned int depthThreshold; /** * \f$\rho\f$; shrinkage parameter for mixing density calculations from * multiple levels of the tree. */ const double rho; /** * Hyper-rectangle splitting strategy. */ const DensityTreeSplitStrategy strategy; /** * Create new density tree node. * * @param p Bounded weighted sample set from which to build the density * tree. * @param mixDensity Parent node density to mix with the node's local * density calculation. * @param depth Depth of the node in the tree, 0 for the root node. * * @return The density tree node. Caller claims ownership. */ DensityTreeNode* create(BoundedDiracMixturePdf& p, const double mixDensity = 0.0, const unsigned int depth = 0) const; /** * Split bounded weighted sample set using the factory's splitting * strategy. * * @param b The bounded weighted sample set to split. * * @return The split weighted sample set. */ SplitDiracMixturePdf split(BoundedDiracMixturePdf& b) const; /** * Split weighted sample set into two sets at mean of dimension with * greatest variance. * * @param p The weighted sample set to split. * * @return The split weighted sample set. */ static SplitDiracMixturePdf splitVariance(DiracMixturePdf& b); /** * Split bounded weighted sample set into two sets along midpoint of * longest dimension. * * @param b The bounded weighted sample set to split. * * @return The split weighted sample set. */ static SplitDiracMixturePdf splitLength(BoundedDiracMixturePdf& b); /** * Split bounded weighted sample set into two sets along midpoint of a * random dimension. * * @param b The bounded weighted sample set to split. * * @return The split weighted sample set. */ static SplitDiracMixturePdf splitRandom(BoundedDiracMixturePdf& b); /** * Split weighted sample set into two sets at a given point along a given * dimension. * * @param p The weighted sample set to split. * @param index Index of the dimension along which to split. * @param value Value at which to split on the given dimension. * * @return The split weighted sample set. */ static SplitDiracMixturePdf split(DiracMixturePdf& p, const unsigned int index, const double value); /** * Calculate bounds using extreme points of a sample set. * * @param p The sample set for which to calculate bounds. * * @return Bounds on the sample set calculated from the most extreme * points along each dimension. */ static Bounds bound(DiracMixturePdf& p); }; } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -