12 #ifndef MLPACK_METHODS_KDE_MODEL_HPP
13 #define MLPACK_METHODS_KDE_MODEL_HPP
25 #include <boost/variant.hpp>
32 template<
typename KernelType,
33 template<
typename TreeMetricType,
34 typename TreeStatType,
35 typename TreeMatType>
class TreeType>
42 arma::mat>::template DualTreeTraverser,
45 arma::mat>::template SingleTreeTraverser>;
55 HAS_MEM_FUNC(Normalizer, HasNormalizer);
59 template<
typename KernelType>
64 const typename std::enable_if<
65 !HasNormalizer<KernelType,
double(KernelType::*)(
size_t)>::value>::
70 template<
typename KernelType>
73 const size_t dimension,
74 arma::vec& estimations,
75 const typename std::enable_if<
76 HasNormalizer<KernelType,
double(KernelType::*)(
size_t)>::value>::
79 estimations /= kernel.Normalizer(dimension);
91 arma::vec& estimations;
95 template<
typename KernelType,
96 template<
typename TreeMetricType,
97 typename TreeStatType,
98 typename TreeMatType>
class TreeType>
102 template<
typename KernelType,
103 template<
typename TreeMetricType,
104 typename TreeStatType,
105 typename TreeMatType>
class TreeType>
106 void operator()(
KDETypeT<KernelType, TreeType>* kde)
const;
122 const size_t dimension;
125 const arma::mat& querySet;
128 arma::vec& estimations;
132 template<
typename KernelType,
133 template<
typename TreeMetricType,
134 typename TreeStatType,
135 typename TreeMatType>
class TreeType>
139 template<
typename KernelType,
140 template<
typename TreeMetricType,
141 typename TreeStatType,
142 typename TreeMatType>
class TreeType>
143 void operator()(
KDETypeT<KernelType, TreeType>* kde)
const;
148 DualBiKDE(arma::mat&& querySet, arma::vec& estimations);
158 arma::mat&& referenceSet;
162 template<
typename KernelType,
163 template<
typename TreeMetricType,
164 typename TreeStatType,
165 typename TreeMatType>
class TreeType>
166 void operator()(KDEType<KernelType, TreeType>* kde)
const;
181 template<
typename KDEType>
189 template<
typename KDEType>
234 boost::variant<KDEType<kernel::GaussianKernel, tree::KDTree>*,
274 KDEModel(
const double bandwidth = 1.0,
275 const double relError = 0.05,
276 const double absError = 0,
277 const KernelTypes kernelType = KernelTypes::GAUSSIAN_KERNEL,
278 const TreeTypes treeType = TreeTypes::KD_TREE);
299 template<
typename Archive>
300 void serialize(Archive& ar,
const unsigned int );
359 void Evaluate(arma::mat&& querySet, arma::vec& estimations);
369 void Evaluate(arma::vec& estimations);
380 #include "kde_model_impl.hpp"
KDE< KernelType, metric::EuclideanDistance, arma::mat, TreeType, TreeType< metric::EuclideanDistance, kde::KDEStat, arma::mat >::template DualTreeTraverser, TreeType< metric::EuclideanDistance, kde::KDEStat, arma::mat >::template SingleTreeTraverser > KDEType
Alias template.
KDEMode Mode() const
Get the mode of the model.
void operator()(KDEType *kde) const
Delete KDEType instance.
KDEMode
KDEMode represents the ways in which KDE algorithm can be executed.
void serialize(Archive &ar, const unsigned int)
Serialize the KDE model.
DualBiKDE computes a Kernel Density Estimation on the given KDEType.
double AbsoluteError() const
Get the absolute error tolerance.
KDEModel(const double bandwidth=1.0, const double relError=0.05, const double absError=0, const KernelTypes kernelType=KernelTypes::GAUSSIAN_KERNEL, const TreeTypes treeType=TreeTypes::KD_TREE)
Initialize KDEModel.
~KDEModel()
Destroy the KDEModel object.
KernelTypes & KernelType()
Modify the kernel type of the model.
ModeVisitor exposes the Mode() method of the KDEType.
void BuildModel(arma::mat &&referenceSet)
Build the KDE model with the given parameters and then trains it with the given reference data...
KDEMode & operator()(KDEType *kde) const
Return mode of KDEType instance.
double Bandwidth() const
Get the bandwidth of the kernel.
The KDE class is a template class for performing Kernel Density Estimations.
double RelativeError() const
Get the relative error tolerance.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
static void ApplyNormalizer(KernelType &kernel, const size_t dimension, arma::vec &estimations, const typename std::enable_if< HasNormalizer< KernelType, double(KernelType::*)(size_t)>::value >::type *=0)
Normalize kernels that have normalizer.
DualMonoKDE(arma::vec &estimations)
DualMonoKDE constructor.
static void ApplyNormalizer(KernelType &, const size_t, arma::vec &, const typename std::enable_if< !HasNormalizer< KernelType, double(KernelType::*)(size_t)>::value >::type *=0)
Normalization not needed.
KernelTypes KernelType() const
Get the kernel type of the model.
TreeTypes & TreeType()
Modify the tree type of the model.
KDEModel & operator=(KDEModel other)
Copy the given model.
double & RelativeError()
Modify the relative error tolerance.
double & AbsoluteError()
Modify the absolute error tolerance.
DualMonoKDE computes a Kernel Density Estimation on the given KDEType.
double & Bandwidth()
Modify the bandwidth of the kernel.
TrainVisitor trains a given KDEType using a reference set.
KernelNormalizer holds a set of methods to normalize estimations applying in each case the appropiate...
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
DualBiKDE(arma::mat &&querySet, arma::vec &estimations)
DualBiKDE constructor. Takes ownership of the given querySet.
TreeTypes TreeType() const
Get the tree type of the model.
void Evaluate(arma::mat &&querySet, arma::vec &estimations)
Perform kernel density estimation on the given query set.
TrainVisitor(arma::mat &&referenceSet)
TrainVisitor constructor. Takes ownership of the given referenceSet.