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(
util::Timers& timers, arma::mat&& referenceSet) = 0;
   123                         arma::mat&& querySet,
   124                         arma::vec& estimates) = 0;
   127   virtual void Evaluate(
util::Timers& timers, arma::vec& estimates) = 0;
   135 template<
typename KernelType,
   136          template<
typename TreeMetricType,
   137                   typename TreeStatType,
   138                   typename TreeMatType> 
class TreeType>
   144              const double absError,
   145              const KernelType& kernel) :
   146       kde(relError, absError, kernel)
   159   virtual void Bandwidth(
const double bw) { kde.Kernel() = KernelType(bw); }
   173   virtual void MCProb(
const double mcProb) { kde.MCProb(mcProb); }
   178     return kde.MCInitialSampleSize();
   183     return kde.MCInitialSampleSize();
   198   virtual void Train(
util::Timers& timers, arma::mat&& referenceSet);
   202                         arma::mat&& querySet,
   203                         arma::vec& estimates);
   206   virtual void Evaluate(
util::Timers& timers, arma::vec& estimates);
   209   template<
typename Archive>
   216   typedef KDE<KernelType,
   276   size_t initialSampleSize;
   315   KDEModel(
const double bandwidth = 1.0,
   318            const KernelTypes kernelType = KernelTypes::GAUSSIAN_KERNEL,
   319            const TreeTypes treeType = TreeTypes::KD_TREE,
   350   template<
typename Archive>
   351   void serialize(Archive& ar, 
const uint32_t version);
   357   void Bandwidth(
const double newBandwidth);
   363   void RelativeError(
const double newRelError);
   369   void AbsoluteError(
const double newAbsError);
   387   void MonteCarlo(
const bool newMonteCarlo);
   393   void MCProbability(
const double newMCProb);
   399   void MCInitialSampleSize(
const size_t newSampleSize);
   405   void MCEntryCoefficient(
const double newEntryCoef);
   411   void MCBreakCoefficient(
const double newBreakCoef);
   422   void InitializeModel();
   433   void BuildModel(
util::Timers& timers, arma::mat&& referenceSet);
   448                 arma::mat&& querySet,
   449                 arma::vec& estimations);
   460   void Evaluate(
util::Timers& timers, arma::vec& estimations);
   471 #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. 
 
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. 
 
void CleanMemory(util::Params ¶ms)
Delete any unique pointers that are held by the IO 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.