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,
261 KernelTypes 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);
static constexpr double mcProb
Probability of a Monte Carlo estimation to be bounded by the relative error tolerance.
Definition: kde.hpp:48
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.
Definition: kde_model.hpp:54
bool MonteCarlo() const
Get whether the model is using Monte Carlo estimations or not.
Definition: kde_model.hpp:382
KDEWrapper(const double relError, const double absError, const KernelType &kernel)
Create the KDEWrapper object, initializing the internally-held KDE object.
Definition: kde_model.hpp:142
virtual size_t & MCInitialSampleSize()
Modify the Monte Carlo sample size.
Definition: kde_model.hpp:180
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
KDEMode Mode() const
Get the mode of the model.
Definition: kde_model.hpp:412
virtual KDEMode & Mode()
Modify the search mode.
Definition: kde_model.hpp:194
double Bandwidth() const
Get the bandwidth of the kernel.
Definition: kde_model.hpp:352
virtual void MCEntryCoef(const double e)
Modify the Monte Carlo entry coefficient.
Definition: kde_model.hpp:186
virtual void Bandwidth(const double bw)
Modify the bandwidth of the kernel.
Definition: kde_model.hpp:158
double MCEntryCoefficient() const
Get Monte Carlo entry coefficient.
Definition: kde_model.hpp:400
virtual size_t MCInitialSampleSize() const
Get the Monte Carlo sample size.
Definition: kde_model.hpp:175
static constexpr KDEMode mode
KDE algorithm mode.
Definition: kde.hpp:41
virtual void MCProb(const double mcProb)
Modify the Monte Carlo probability.
Definition: kde_model.hpp:172
virtual KDEMode Mode() const
Get the search mode.
Definition: kde_model.hpp:192
double RelativeError() const
Get the relative error tolerance.
Definition: kde_model.hpp:358
KDEWrapperBase()
Create the KDEWrapperBase object.
Definition: kde_model.hpp:76
static constexpr double relError
Relative error tolerance.
Definition: kde.hpp:35
KDEType kde
The instantiated KDE object that we are wrapping.
Definition: kde_model.hpp:220
virtual bool & MonteCarlo()
Modify whether Monte Carlo search is being used.
Definition: kde_model.hpp:169
size_t MCInitialSampleSize() const
Get the initial sample size for Monte Carlo estimations.
Definition: kde_model.hpp:394
virtual void RelativeError(const double eps)
Modify the relative error tolerance.
Definition: kde_model.hpp:161
TreeTypes TreeType() const
Get the tree type of the model.
Definition: kde_model.hpp:370
KDEWrapper is a wrapper class for all KDE types supported by KDEModel.
Definition: kde_model.hpp:138
virtual ~KDEWrapperBase()
Destruct the KDEWrapperBase (nothing to do).
Definition: kde_model.hpp:83
virtual KDEMode Mode() const =0
Get the search mode.
virtual void MCBreakCoef(const double b)
Modify the Monte Carlo break coefficient.
Definition: kde_model.hpp:189
double MCBreakCoefficient() const
Get Monte Carlo break coefficient.
Definition: kde_model.hpp:406
double AbsoluteError() const
Get the absolute error tolerance.
Definition: kde_model.hpp:364
The KDE class is a template class for performing Kernel Density Estimations.
Definition: kde.hpp:88
static constexpr double mcEntryCoef
Monte Carlo entry coefficient.
Definition: kde.hpp:54
static constexpr double absError
Absolute error tolerance.
Definition: kde.hpp:38
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
KernelTypes & KernelType()
Modify the kernel type of the model.
Definition: kde_model.hpp:379
KDEWrapperBase is a base wrapper class for holding all KDE types supported by KDEModel.
Definition: kde_model.hpp:71
Definition: hmm_train_main.cpp:300
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:63
virtual bool MonteCarlo() const
Get whether Monte Carlo search is being used.
Definition: kde_model.hpp:167
The KDEModel provides an abstraction for the KDE class, abstracting away the KernelType and TreeType ...
Definition: kde_model.hpp:229
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.
Definition: kde_model.hpp:43
static constexpr double mcBreakCoef
Monte Carlo break coefficient.
Definition: kde.hpp:57
TreeTypes & TreeType()
Modify the tree type of the model.
Definition: kde_model.hpp:373
virtual void AbsoluteError(const double eps)
Modify the absolute error tolerance.
Definition: kde_model.hpp:164
KDEMode
KDEMode represents the ways in which KDE algorithm can be executed.
Definition: kde.hpp:25
virtual KDEWrapper * Clone() const
Create a new KDEWrapper that is the same as this one.
Definition: kde_model.hpp:152
virtual ~KDEWrapper()
Destruct the KDEWrapper (nothing to do).
Definition: kde_model.hpp:155
double MCProbability() const
Get Monte Carlo probability of error being bounded by relative error.
Definition: kde_model.hpp:388
KDEMode & Mode()
Modify the mode of the model.
Definition: kde_model.hpp:415
KernelNormalizer holds a set of methods to normalize estimations applying in each case the appropiate...
Definition: kde_model.hpp:34
void serialize(Archive &ar, const uint32_t)
Serialize the KDE model.
Definition: kde_model.hpp:208
static constexpr size_t initialSampleSize
Initial sample size for Monte Carlo estimations.
Definition: kde.hpp:51
KernelTypes KernelType() const
Get the kernel type of the model.
Definition: kde_model.hpp:376