12 #ifndef MLPACK_METHODS_KDE_MODEL_HPP 13 #define MLPACK_METHODS_KDE_MODEL_HPP 38 HAS_MEM_FUNC(Normalizer, HasNormalizer);
42 template<
typename KernelType>
47 const typename std::enable_if<
48 !HasNormalizer<KernelType,
double(KernelType::*)(
size_t)>::value>::
53 template<
typename KernelType>
56 const size_t dimension,
57 arma::vec& estimations,
58 const typename std::enable_if<
59 HasNormalizer<KernelType,
double(KernelType::*)(
size_t)>::value>::
62 estimations /= kernel.Normalizer(dimension);
86 virtual void Bandwidth(
const double bw) = 0;
89 virtual void RelativeError(
const double relError) = 0;
92 virtual void AbsoluteError(
const double absError) = 0;
95 virtual bool MonteCarlo()
const = 0;
97 virtual bool& MonteCarlo() = 0;
100 virtual void MCProb(
const double mcProb) = 0;
103 virtual size_t MCInitialSampleSize()
const = 0;
105 virtual size_t& MCInitialSampleSize() = 0;
108 virtual void MCEntryCoef(
const double entryCoef) = 0;
111 virtual void MCBreakCoef(
const double breakCoef) = 0;
114 virtual KDEMode Mode()
const = 0;
119 virtual void Train(arma::mat&& referenceSet) = 0;
122 virtual void Evaluate(arma::mat&& querySet,
123 arma::vec& estimates) = 0;
126 virtual void Evaluate(arma::vec& estimates) = 0;
134 template<
typename KernelType,
135 template<
typename TreeMetricType,
136 typename TreeStatType,
137 typename TreeMatType>
class TreeType>
143 const double absError,
144 const KernelType& kernel) :
145 kde(relError, absError, kernel)
158 virtual void Bandwidth(
const double bw) { kde.Kernel() = KernelType(bw); }
172 virtual void MCProb(
const double mcProb) { kde.MCProb(mcProb); }
177 return kde.MCInitialSampleSize();
182 return kde.MCInitialSampleSize();
197 virtual void Train(arma::mat&& referenceSet);
200 virtual void Evaluate(arma::mat&& querySet,
201 arma::vec& estimates);
204 virtual void Evaluate(arma::vec& estimates);
207 template<
typename Archive>
214 typedef KDE<KernelType,
274 size_t initialSampleSize;
313 KDEModel(
const double bandwidth = 1.0,
316 const KernelTypes kernelType = KernelTypes::GAUSSIAN_KERNEL,
317 const TreeTypes treeType = TreeTypes::KD_TREE,
348 template<
typename Archive>
349 void serialize(Archive& ar,
const uint32_t version);
355 void Bandwidth(
const double newBandwidth);
361 void RelativeError(
const double newRelError);
367 void AbsoluteError(
const double newAbsError);
385 void MonteCarlo(
const bool newMonteCarlo);
391 void MCProbability(
const double newMCProb);
397 void MCInitialSampleSize(
const size_t newSampleSize);
403 void MCEntryCoefficient(
const double newEntryCoef);
409 void MCBreakCoefficient(
const double newBreakCoef);
420 void InitializeModel();
430 void BuildModel(arma::mat&& referenceSet);
443 void Evaluate(arma::mat&& querySet, arma::vec& estimations);
453 void Evaluate(arma::vec& estimations);
464 #include "kde_model_impl.hpp" virtual void MCProb(const double mcProb)
Modify the Monte Carlo probability.
double Bandwidth() const
Get the bandwidth of the kernel.
static constexpr double relError
Relative error tolerance.
virtual void MCEntryCoef(const double e)
Modify the Monte Carlo entry coefficient.
double RelativeError() const
Get the relative error tolerance.
Linear algebra utility functions, generally performed on matrices or vectors.
KDEMode
KDEMode represents the ways in which KDE algorithm can be executed.
KDEType kde
The instantiated KDE object that we are wrapping.
double MCEntryCoefficient() const
Get Monte Carlo entry coefficient.
static constexpr double mcBreakCoef
Monte Carlo break coefficient.
virtual KDEWrapper * Clone() const
Create a new KDEWrapper that is the same as this one.
virtual size_t MCInitialSampleSize() const
Get the Monte Carlo sample size.
virtual KDEMode Mode() const =0
Get the search mode.
virtual ~KDEWrapper()
Destruct the KDEWrapper (nothing to do).
void serialize(Archive &ar, const uint32_t)
Serialize the KDE model.
virtual KDEMode Mode() const
Get the search mode.
virtual size_t & MCInitialSampleSize()
Modify the Monte Carlo sample size.
KernelTypes & KernelType()
Modify the kernel type of the model.
TreeTypes TreeType() const
Get the tree type of the model.
virtual void Bandwidth(const double bw)
Modify the bandwidth of the kernel.
static constexpr KDEMode mode
KDE algorithm mode.
bool MonteCarlo() const
Get whether the model is using Monte Carlo estimations or not.
KDEWrapper is a wrapper class for all KDE types supported by KDEModel.
static constexpr double absError
Absolute error tolerance.
virtual KDEMode & Mode()
Modify the search mode.
KDEMode & Mode()
Modify the mode of the model.
void CleanMemory()
Delete any unique pointers that are held by the IO object.
The KDE class is a template class for performing Kernel Density Estimations.
double MCBreakCoefficient() const
Get Monte Carlo break coefficient.
KDEMode Mode() const
Get the mode of the model.
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.
KDEWrapperBase is a base wrapper class for holding all KDE types supported by KDEModel.
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.
virtual bool MonteCarlo() const
Get whether Monte Carlo search is being used.
The KDEModel provides an abstraction for the KDE class, abstracting away the KernelType and TreeType ...
double AbsoluteError() const
Get the absolute error tolerance.
static constexpr size_t initialSampleSize
Initial sample size for Monte Carlo estimations.
KDE< KernelType, metric::EuclideanDistance, arma::mat, TreeType > KDEType
static constexpr double mcEntryCoef
Monte Carlo entry coefficient.
TreeTypes & TreeType()
Modify the tree type of the model.
virtual void AbsoluteError(const double eps)
Modify the absolute error tolerance.
static constexpr double mcProb
Probability of a Monte Carlo estimation to be bounded by the relative error tolerance.
virtual ~KDEWrapperBase()
Destruct the KDEWrapperBase (nothing to do).
KDEWrapperBase()
Create the KDEWrapperBase object.
KernelNormalizer holds a set of methods to normalize estimations applying in each case the appropiate...
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
KernelTypes KernelType() const
Get the kernel type of the model.
KDEWrapper(const double relError, const double absError, const KernelType &kernel)
Create the KDEWrapper object, initializing the internally-held KDE object.
virtual bool & MonteCarlo()
Modify whether Monte Carlo search is being used.
double MCProbability() const
Get Monte Carlo probability of error being bounded by relative error.
virtual void RelativeError(const double eps)
Modify the relative error tolerance.
size_t MCInitialSampleSize() const
Get the initial sample size for Monte Carlo estimations.
virtual void MCBreakCoef(const double b)
Modify the Monte Carlo break coefficient.