mlpack
Public Types | Public Member Functions | List of all members
mlpack::kde::KDEModel Class Reference

The KDEModel provides an abstraction for the KDE class, abstracting away the KernelType and TreeType parameters and allowing those to be specified at runtime. More...

#include <kde_model.hpp>

Public Types

enum  TreeTypes {
  KD_TREE, BALL_TREE, COVER_TREE, OCTREE,
  R_TREE
}
 
enum  KernelTypes {
  GAUSSIAN_KERNEL, EPANECHNIKOV_KERNEL, LAPLACIAN_KERNEL, SPHERICAL_KERNEL,
  TRIANGULAR_KERNEL
}
 

Public Member Functions

 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. More...
 
 KDEModel (const KDEModel &other)
 Copy constructor of the given model.
 
 KDEModel (KDEModel &&other)
 Move constructor of the given model. Takes ownership of the model.
 
KDEModeloperator= (const KDEModel &other)
 Copy the given model. More...
 
KDEModeloperator= (KDEModel &&other)
 Take ownership of the contents of the given model. More...
 
 ~KDEModel ()
 Destroy the KDEModel object.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t version)
 Serialize the KDE model.
 
double Bandwidth () const
 Get the bandwidth of the kernel.
 
void Bandwidth (const double newBandwidth)
 Modify the bandwidth of the kernel.
 
double RelativeError () const
 Get the relative error tolerance.
 
void RelativeError (const double newRelError)
 Modify the relative error tolerance.
 
double AbsoluteError () const
 Get the absolute error tolerance.
 
void AbsoluteError (const double newAbsError)
 Modify the absolute error tolerance.
 
TreeTypes TreeType () const
 Get the tree type of the model.
 
TreeTypes & TreeType ()
 Modify the tree type of the model.
 
KernelTypes KernelType () const
 Get the kernel type of the model.
 
KernelTypes & KernelType ()
 Modify the kernel type of the model.
 
bool MonteCarlo () const
 Get whether the model is using Monte Carlo estimations or not.
 
void MonteCarlo (const bool newMonteCarlo)
 Modify whether the model is using Monte Carlo estimations or not.
 
double MCProbability () const
 Get Monte Carlo probability of error being bounded by relative error.
 
void MCProbability (const double newMCProb)
 Modify Monte Carlo probability of error being bounded by relative error.
 
size_t MCInitialSampleSize () const
 Get the initial sample size for Monte Carlo estimations.
 
void MCInitialSampleSize (const size_t newSampleSize)
 Modify the initial sample size for Monte Carlo estimations.
 
double MCEntryCoefficient () const
 Get Monte Carlo entry coefficient.
 
void MCEntryCoefficient (const double newEntryCoef)
 Modify Monte Carlo entry coefficient.
 
double MCBreakCoefficient () const
 Get Monte Carlo break coefficient.
 
void MCBreakCoefficient (const double newBreakCoef)
 Modify Monte Carlo break coefficient.
 
KDEMode Mode () const
 Get the mode of the model.
 
KDEModeMode ()
 Modify the mode of the model.
 
void InitializeModel ()
 Initialize the KDE model.
 
void BuildModel (arma::mat &&referenceSet)
 Build the KDE model with the given parameters and then trains it with the given reference data. More...
 
void Evaluate (arma::mat &&querySet, arma::vec &estimations)
 Perform kernel density estimation on the given query set. More...
 
void Evaluate (arma::vec &estimations)
 Perform kernel density estimation on the reference set. More...
 

Detailed Description

The KDEModel provides an abstraction for the KDE class, abstracting away the KernelType and TreeType parameters and allowing those to be specified at runtime.

This class is written for the sake of the kde binding, but it is not necessarily restricted to that usage.

Constructor & Destructor Documentation

◆ KDEModel()

mlpack::kde::KDEModel::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.

Initialize the KDEModel with the given parameters.

Parameters
bandwidthBandwidth to use for the kernel.
relErrorMaximum relative error tolerance for each point in the model. For example, 0.05 means that each value must be within 5% of the true KDE value.
absErrorMaximum absolute error tolerance for each point in the model. For example, 0.1 means that for each point the value can have a maximum error of 0.1 units.
kernelTypeType of kernel to use.
treeTypeType of tree to use.
monteCarloWhether to use Monte Carlo estimations when possible.
mcProbof a Monte Carlo estimation to be bounded by relative error tolerance.
initialSampleSizeInitial sample size for Monte Carlo estimations.
mcEntryCoefCoefficient to control how much larger does the amount of node descendants has to be compared to the initial sample size in order for it to be a candidate for Monte Carlo estimations.
mcBreakCoefCoefficient to control what fraction of the node's descendants evaluated is the limit before Monte Carlo estimation recurses.

Member Function Documentation

◆ BuildModel()

void mlpack::kde::KDEModel::BuildModel ( arma::mat &&  referenceSet)

Build the KDE model with the given parameters and then trains it with the given reference data.

Takes possession of the reference set to avoid a copy, so the reference set will not be usable after this.

Parameters
referenceSetSet of reference points.

◆ Evaluate() [1/2]

void mlpack::kde::KDEModel::Evaluate ( arma::mat &&  querySet,
arma::vec &  estimations 
)

Perform kernel density estimation on the given query set.

Takes possession of the query set to avoid a copy, so the query set will not be usable after this. If possible, it returns normalized estimations.

Precondition
The model has to be previously created with BuildModel.
Parameters
querySetSet of query points.
estimationsVector where the results will be stored in the same order as the query points.

◆ Evaluate() [2/2]

void mlpack::kde::KDEModel::Evaluate ( arma::vec &  estimations)

Perform kernel density estimation on the reference set.

If possible, it returns normalized estimations.

Precondition
The model has to be previously created with BuildModel.
Parameters
estimationsVector where the results will be stored in the same order as the query points.

◆ operator=() [1/2]

KDEModel & mlpack::kde::KDEModel::operator= ( const KDEModel other)

Copy the given model.

Parameters
otherKDEModel to copy.

◆ operator=() [2/2]

KDEModel & mlpack::kde::KDEModel::operator= ( KDEModel &&  other)

Take ownership of the contents of the given model.

Parameters
otherKDEModel to take ownership of.

The documentation for this class was generated from the following files: