Go to the documentation of this file.
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 const double bandwidth;
185 template<
typename KernelType,
186 template<
typename TreeMetricType,
187 typename TreeStatType,
188 typename TreeMatType>
class TreeType>
189 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
202 const double relError;
206 template<
typename KernelType,
207 template<
typename TreeMetricType,
208 typename TreeStatType,
209 typename TreeMatType>
class TreeType>
210 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
223 const double absError;
227 template<
typename KernelType,
228 template<
typename TreeMetricType,
229 typename TreeStatType,
230 typename TreeMatType>
class TreeType>
231 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
244 const bool monteCarlo;
248 template<
typename KernelType,
249 template<
typename TreeMetricType,
250 typename TreeStatType,
251 typename TreeMatType>
class TreeType>
252 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
265 const double probability;
269 template<
typename KernelType,
270 template<
typename TreeMetricType,
271 typename TreeStatType,
272 typename TreeMatType>
class TreeType>
273 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
287 const size_t sampleSize;
291 template<
typename KernelType,
292 template<
typename TreeMetricType,
293 typename TreeStatType,
294 typename TreeMatType>
class TreeType>
295 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
308 const double entryCoef;
312 template<
typename KernelType,
313 template<
typename TreeMetricType,
314 typename TreeStatType,
315 typename TreeMatType>
class TreeType>
316 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
329 const double breakCoef;
333 template<
typename KernelType,
334 template<
typename TreeMetricType,
335 typename TreeStatType,
336 typename TreeMatType>
class TreeType>
337 void operator()(
KDEType<KernelType, TreeType>* kde)
const;
350 template<
typename KDEType>
358 template<
typename KDEType>
407 size_t initialSampleSize;
419 boost::variant<KDEType<kernel::GaussianKernel, tree::KDTree>*,
473 const KernelTypes kernelType = KernelTypes::GAUSSIAN_KERNEL,
474 const TreeTypes treeType = TreeTypes::KD_TREE,
500 template<
typename Archive>
501 void serialize(Archive& ar,
const unsigned int version);
590 void Evaluate(arma::mat&& querySet, arma::vec& estimations);
614 #include "kde_model_impl.hpp"
void BuildModel(arma::mat &&referenceSet)
Build the KDE model with the given parameters and then trains it with the given reference data.
KDEModel & operator=(KDEModel other)
Copy the given model.
double MCProbability() const
Get Monte Carlo probability of error being bounded by relative error.
KDEMode & Mode()
Modify the mode of the model.
DualMonoKDE computes a Kernel Density Estimation on the given KDEType.
MCEntryCoefVisitor sets the Monte Carlo entry coefficient.
static constexpr KDEMode mode
KDE algorithm mode.
double MCBreakCoefficient() const
Get Monte Carlo break coefficient.
void MCInitialSampleSize(const size_t newSampleSize)
Modify the initial sample size for Monte Carlo estimations.
double MCEntryCoefficient() const
Get Monte Carlo entry coefficient.
KernelNormalizer holds a set of methods to normalize estimations applying in each case the appropiate...
MCBreakCoefVisitor(const double breakCoef)
MCBreakCoefVisitor constructor.
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.
RelErrorVisitor modifies relative error tolerance for a KDEType.
BOOST_TEMPLATE_CLASS_VERSION(template<>, mlpack::kde::KDEModel, 1)
Set the serialization version of the KDEModel class.
void AbsoluteError(const double newAbsError)
Modify the absolute error tolerance.
KDEModel(const KDEModel &other)
Copy constructor of the given model.
TreeTypes TreeType() const
Get the tree type of the model.
MCBreakCoefVisitor sets the Monte Carlo break coefficient.
void MCBreakCoefficient(const double newBreakCoef)
Modify Monte Carlo break coefficient.
The KDE class is a template class for performing Kernel Density Estimations.
static constexpr double mcBreakCoef
Monte Carlo break coefficient.
AbsErrorVisitor modifies absolute error tolerance for a KDEType.
void MonteCarlo(const bool newMonteCarlo)
Modify whether the model is using Monte Carlo estimations or not.
MCSampleSizeVisitor(const size_t sampleSize)
MCSampleSizeVisitor constructor.
DualBiKDE computes a Kernel Density Estimation on the given KDEType.
Linear algebra utility functions, generally performed on matrices or vectors.
void RelativeError(const double newRelError)
Modify the relative error tolerance.
~KDEModel()
Destroy the KDEModel object.
double AbsoluteError() const
Get the absolute error tolerance.
RelErrorVisitor(const double relError)
RelErrorVisitor constructor.
void Evaluate(arma::vec &estimations)
Perform kernel density estimation on the reference set.
void MCEntryCoefficient(const double newEntryCoef)
Modify Monte Carlo entry coefficient.
void MCProbability(const double newMCProb)
Modify Monte Carlo probability of error being bounded by relative error.
void serialize(Archive &ar, const unsigned int version)
Serialize the KDE model.
static constexpr double absError
Absolute error tolerance.
double Bandwidth() const
Get the bandwidth of the kernel.
KernelTypes & KernelType()
Modify the kernel type of the model.
TrainVisitor trains a given KDEType using a reference set.
void Bandwidth(const double newBandwidth)
Modify the bandwidth of the kernel.
BandwidthVisitor(const double bandwidth)
BandwidthVisitor constructor.
bool MonteCarlo() const
Get whether the model is using Monte Carlo estimations or not.
void operator()(KDEType *kde) const
Delete KDEType instance.
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.
static constexpr double mcEntryCoef
Monte Carlo entry coefficient.
size_t MCInitialSampleSize() const
Get the initial sample size for Monte Carlo estimations.
KernelTypes KernelType() const
Get the kernel type of the model.
KDEMode Mode() const
Get the mode of the model.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
KDEMode & operator()(KDEType *kde) const
Return mode of KDEType instance.
MCEntryCoefVisitor(const double entryCoef)
MCEntryCoefVisitor constructor.
AbsErrorVisitor(const double absError)
AbsErrorVisitor constructor.
MonteCarloVisitor activates or deactivates Monte Carlo for a given KDEType.
KDEMode
KDEMode represents the ways in which KDE algorithm can be executed.
DualBiKDE(arma::mat &&querySet, arma::vec &estimations)
DualBiKDE constructor. Takes ownership of the given querySet.
static constexpr double mcProb
Probability of a Monte Carlo estimation to be bounded by the relative error tolerance.
MonteCarloVisitor(const bool monteCarlo)
MonteCarloVisitor constructor.
MCProbabilityVisitor(const double probability)
MCProbabilityVisitor constructor.
static constexpr double relError
Relative error tolerance.
KDEModel(const double bandwidth=1.0, const double relError=KDEDefaultParams::relError, const double absError=KDEDefaultParams::absError, const KernelTypes kernelType=KernelTypes::GAUSSIAN_KERNEL, const TreeTypes treeType=TreeTypes::KD_TREE, const bool monteCarlo=KDEDefaultParams::mode, const double mcProb=KDEDefaultParams::mcProb, const size_t initialSampleSize=KDEDefaultParams::initialSampleSize, const double mcEntryCoef=KDEDefaultParams::mcEntryCoef, const double mcBreakCoef=KDEDefaultParams::mcBreakCoef)
Initialize KDEModel.
void Evaluate(arma::mat &&querySet, arma::vec &estimations)
Perform kernel density estimation on the given query set.
Extra data for each node in the tree for the task of kernel density estimation.
TrainVisitor(arma::mat &&referenceSet)
TrainVisitor constructor. Takes ownership of the given referenceSet.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
ModeVisitor exposes the Mode() method of the KDEType.
double RelativeError() const
Get the relative error tolerance.
MCSampleSizeVisitor sets the Monte Carlo intial sample size for a given KDEType.
MCProbabilityVisitor sets the Monte Carlo probability for a given KDEType.
TreeTypes & TreeType()
Modify the tree type of the model.
KDEModel(KDEModel &&other)
Move constructor of the given model. Takes ownership of the model.
static constexpr size_t initialSampleSize
Initial sample size for Monte Carlo estimations.
BandwidthVisitor modifies the bandwidth of a KDEType kernel.
DualMonoKDE(arma::vec &estimations)
DualMonoKDE constructor.