📄 densitytreepdf.hpp
字号:
#ifndef INDII_ML_AUX_DENSITYTREEPDF_HPP#define INDII_ML_AUX_DENSITYTREEPDF_HPP#include "Pdf.hpp"#include "DiracMixturePdf.hpp"#include "DensityTreeFactory.hpp"#include "DensityTreeNode.hpp"#include "DensityTreeInternal.hpp"#include "DensityTreeLeaf.hpp"namespace indii { namespace ml { namespace aux {/** * Probability density tree. * * @author Lawrence Murray <lawrence@indii.org> * @version $Rev: 401 $ * @date $Date: 2008-03-05 13:54:28 +0000 (Wed, 05 Mar 2008) $ * * Probability density tree implementation based on @ref Thrun1999 * "Thrun et al. (1999)". * * @section DensityTreePdf_serialization Serialization * * This class supports serialization through the Boost.Serialization * library. * * @section DensityTreePdf_references References * * @anchor Thrun1999 * Thrun, S.; Langford, J. & Fox, D. Monte Carlo Hidden Markov Models: * Learning Non-Parametric Models of Partially Observable Stochastic * Processes. <i>Proceedings of the International Conference on * Machine Learning</i> <b>1999</b>. */class DensityTreePdf : public Pdf {public: /** * Default constructor. * * Initialises the density tree with zero dimensions. This should * generally only be used when the object is to be restored from a * serialization. */ DensityTreePdf(); /** * Constructor. * * @param p Weighted sample set from which to build the density tree. * * A default DensityTreeFactory will be used to construct the nodes of * the tree. */ DensityTreePdf(DiracMixturePdf& p); /** * Constructor. * * @param p Weighted sample set from which to build the density tree. * @param factory Factory used to build nodes in the density tree. Use * this to set options such as the node splitting strategy and \f$\rho\f$ * shrinkage parameter. */ DensityTreePdf(DiracMixturePdf& p, const DensityTreeFactory& factory); /** * Copy constructor. */ DensityTreePdf(const DensityTreePdf& o); /** * Destructor. */ virtual ~DensityTreePdf(); /** * Assignment operator. Both sides must have same dimensionality. */ DensityTreePdf& operator=(const DensityTreePdf& o); /** * Get lower bound on the density tree. * * @return Lower bound on the density tree. */ const vector& getLower() const; /** * Get upper bound on the density tree. * * @return Upper bound on the density tree. */ const vector& getUpper() const; virtual unsigned int getDimensions() const; /** * Not supported. * * @see Pdf::setDimensions() */ virtual void setDimensions(const unsigned int N, const bool preserve = false); virtual const vector& getExpectation(); virtual const symmetric_matrix& getCovariance(); virtual vector sample(); virtual double densityAt(const vector& x);private: /** * \f$N\f$; number of dimensions. */ unsigned int N; /** * \f$\mathbf{\mu}\f$; mean of the distribution. */ vector mu; /** * \f$\Sigma\f$; covariance of the distribution. */ symmetric_matrix sigma; /** * Has \f$\mathbf{\mu}\f$ been calculated? */ bool haveMu; /** * Has \f$\Sigma\f$ been calculated? */ bool haveSigma; /** * Root node of density tree. */ DensityTreeNode* root; /** * Calculate expectation. */ void calculateExpectation(); /** * Calculate covariance. */ void calculateCovariance(); /** * Serialize. */ template<class Archive> void save(Archive& ar, const unsigned int version) const; /** * Restore from serialization. */ template<class Archive> void load(Archive& ar, const unsigned int version); /* * Boost.Serialization requirements. */ BOOST_SERIALIZATION_SPLIT_MEMBER() friend class boost::serialization::access;}; } }}template<class Archive>void indii::ml::aux::DensityTreePdf::save(Archive& ar, const unsigned int version) const { ar & boost::serialization::base_object<Pdf>(*this); ar & N; /* * To avoid inconvenient use of BOOST_CLASS_EXPORT by user for * DensityTreeInternal and DensityTreeLeaf derived from DensityTreeNode, * cast the root node to it's derived type to explicitly instantiate the * serialization code for this type. */ if (typeid(*root) == typeid(DensityTreeInternal)) { const bool isLeaf = false; const DensityTreeInternal* node = static_cast<DensityTreeInternal*>(root); ar & isLeaf; ar & *node; } else if (typeid(*root) == typeid(DensityTreeLeaf)) { const bool isLeaf = true; const DensityTreeLeaf* node = static_cast<DensityTreeLeaf*>(root); ar & isLeaf; ar & *node; } else { assert(false); }}template<class Archive>void indii::ml::aux::DensityTreePdf::load(Archive& ar, const unsigned int version) { bool isLeaf; if (root != NULL) { delete root; root = NULL; } ar & boost::serialization::base_object<Pdf>(*this); ar & N; ar & isLeaf; if (isLeaf) { DensityTreeLeaf* node = new DensityTreeLeaf(); ar & *node; root = node; } else { DensityTreeInternal* node = new DensityTreeInternal(); ar & *node; root = node; } haveMu = false; haveSigma = false; mu.resize(N, false); sigma.resize(N, false);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -