13#ifndef MLPACK_METHODS_KDE_KDE_HPP
14#define MLPACK_METHODS_KDE_KDE_HPP
48 static constexpr double mcProb = 0.95;
76 typename MatType = arma::mat,
77 template<
typename TreeMetricType,
78 typename TreeStatType,
80 template<
typename RuleType>
class DualTreeTraversalType =
83 MatType>::template DualTreeTraverser,
84 template<
typename RuleType>
class SingleTreeTraversalType =
87 MatType>::template SingleTreeTraverser>
92 typedef TreeType<MetricType, kde::KDEStat, MatType>
Tree;
116 KernelType kernel = KernelType(),
118 MetricType metric = MetricType(),
174 void Train(
Tree* referenceTree, std::vector<size_t>* oldFromNewReferences);
190 void Evaluate(MatType querySet, arma::vec& estimations);
208 const std::vector<size_t>& oldFromNewQueries,
209 arma::vec& estimations);
224 const KernelType&
Kernel()
const {
return kernel; }
230 const MetricType&
Metric()
const {
return metric; }
294 template<
typename Archive>
295 void serialize(Archive& ar,
const unsigned int version);
308 std::vector<size_t>* oldFromNewReferences;
317 bool ownsReferenceTree;
332 size_t initialSampleSize;
345 static void CheckErrorValues(
const double relError,
const double absError);
348 static void RearrangeEstimations(
const std::vector<size_t>& oldFromNew,
349 arma::vec& estimations);
363namespace serialization{
365template<
typename KernelType,
368 template<
typename TreeMetricType,
369 typename TreeStatType,
370 typename TreeMatType>
class TreeType,
371 template<typename RuleType> class DualTreeTraversalType,
372 template<typename RuleType> class SingleTreeTraversalType>
373struct version<
mlpack::kde::KDE<KernelType,
377 DualTreeTraversalType,
378 SingleTreeTraversalType>>
381 typedef mpl::integral_c_tag
tag;
384 boost::mpl::int_<256>>));
391#include "kde_impl.hpp"
Extra data for each node in the tree for the task of kernel density estimation.
The KDE class is a template class for performing Kernel Density Estimations.
Tree * ReferenceTree()
Get the reference tree.
KDE(const KDE &other)
Construct KDE object as a copy of the given model.
double MCEntryCoef() const
Get Monte Carlo entry coefficient.
KernelType & Kernel()
Modify the kernel.
void MCProb(const double newProb)
Modify Monte Carlo probability of error being bounded by relative error.
KDEMode & Mode()
Modify the mode of KDE.
void Train(MatType referenceSet)
Trains the KDE model.
const MetricType & Metric() const
Get the metric.
double RelativeError() const
Get relative error tolerance.
double MCBreakCoef() const
Get Monte Carlo break coefficient.
KDE(const double relError=KDEDefaultParams::relError, const double absError=KDEDefaultParams::absError, KernelType kernel=KernelType(), const KDEMode mode=KDEDefaultParams::mode, MetricType metric=MetricType(), const bool monteCarlo=KDEDefaultParams::monteCarlo, const double mcProb=KDEDefaultParams::mcProb, const size_t initialSampleSize=KDEDefaultParams::initialSampleSize, const double mcEntryCoef=KDEDefaultParams::mcEntryCoef, const double mcBreakCoef=KDEDefaultParams::mcBreakCoef)
Initialize KDE object using custom instantiated Metric and Kernel objects.
void RelativeError(const double newError)
Modify relative error tolerance (0 <= newError <= 1).
bool & MonteCarlo()
Modify whether Monte Carlo estimations are being used or not.
double MCProb() const
Get Monte Carlo probability of error being bounded by relative error.
bool OwnsReferenceTree() const
Check whether reference tree is owned by the KDE model.
bool IsTrained() const
Check whether KDE model is trained or not.
KDE & operator=(KDE other)
Copy a KDE model.
~KDE()
Destroy the KDE object.
void serialize(Archive &ar, const unsigned int version)
Serialize the model.
KDEMode Mode() const
Get the mode of KDE.
TreeType< MetricType, kde::KDEStat, MatType > Tree
Convenience typedef.
void Evaluate(arma::vec &estimations)
Estimate density of each point in the reference set given the data of the reference set.
MetricType & Metric()
Modify the metric.
size_t MCInitialSampleSize() const
Get Monte Carlo initial sample size.
const KernelType & Kernel() const
Get the kernel.
void Evaluate(MatType querySet, arma::vec &estimations)
Estimate density of each point in the query set given the data of the reference set.
bool MonteCarlo() const
Get whether Monte Carlo estimations are being used or not.
void MCEntryCoef(const double newCoef)
Modify Monte Carlo entry coefficient. (newCoef >= 1).
void Evaluate(Tree *queryTree, const std::vector< size_t > &oldFromNewQueries, arma::vec &estimations)
Estimate density of each point in the query set given the data of an already created query tree.
double AbsoluteError() const
Get absolute error tolerance.
void AbsoluteError(const double newError)
Modify absolute error tolerance (0 <= newError).
KDE(KDE &&other)
Construct KDE object taking ownership of the given model.
size_t & MCInitialSampleSize()
Modify Monte Carlo initial sample size.
void MCBreakCoef(const double newCoef)
Modify Monte Carlo break coefficient. (0 < newCoef <= 1).
void Train(Tree *referenceTree, std::vector< size_t > *oldFromNewReferences)
Trains the KDE model.
The standard Gaussian kernel.
Set the serialization version of the adaboost class.
KDEMode
KDEMode represents the ways in which KDE algorithm can be executed.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
BOOST_STATIC_CONSTANT(int, value=version::type::value)
BOOST_MPL_ASSERT((boost::mpl::less< boost::mpl::int_< 1 >, boost::mpl::int_< 256 > >))
KDEDefaultParams contains the default input parameter values for KDE.
static constexpr KDEMode mode
KDE algorithm mode.
static constexpr bool monteCarlo
Whether to use Monte Carlo estimations when possible.
static constexpr double absError
Absolute error tolerance.
static constexpr double mcProb
Probability of a Monte Carlo estimation to be bounded by the relative error tolerance.
static constexpr double mcBreakCoef
Monte Carlo break coefficient.
static constexpr double mcEntryCoef
Monte Carlo entry coefficient.
static constexpr size_t initialSampleSize
Initial sample size for Monte Carlo estimations.
static constexpr double relError
Relative error tolerance.