KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > Class Template Reference

The KDE class is a template class for performing Kernel Density Estimations. More...

Inheritance diagram for KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >:

Public Types

typedef TreeType< MetricType, kde::KDEStat, MatType > Tree
 Convenience typedef. More...

 

Public Member Functions

 KDE (const double relError=KDEDefaultParams::relError, const double absError=KDEDefaultParams::absError, KernelType kernel=KernelType(), const KDEMode mode=KDEDefaultParams::mode, MetricType metric=MetricType(), const bool monteCarlo=KDEDefaultParams::monteCarlo, const double mcProb=KDEDefaultParams::mcProb, const size_t initialSampleSize=KDEDefaultParams::initialSampleSize, const double mcEntryCoef=KDEDefaultParams::mcEntryCoef, const double mcBreakCoef=KDEDefaultParams::mcBreakCoef)
 Initialize KDE object using custom instantiated Metric and Kernel objects. More...

 
 KDE (const KDE &other)
 Construct KDE object as a copy of the given model. More...

 
 KDE (KDE &&other)
 Construct KDE object taking ownership of the given model. More...

 
 ~KDE ()
 Destroy the KDE object. More...

 
double AbsoluteError () const
 Get absolute error tolerance. More...

 
void AbsoluteError (const double newError)
 Modify absolute error tolerance (0 <= newError). More...

 
void Evaluate (MatType querySet, arma::vec &estimations)
 Estimate density of each point in the query set given the data of the reference set. More...

 
void Evaluate (Tree *queryTree, const std::vector< size_t > &oldFromNewQueries, arma::vec &estimations)
 Estimate density of each point in the query set given the data of an already created query tree. More...

 
void Evaluate (arma::vec &estimations)
 Estimate density of each point in the reference set given the data of the reference set. More...

 
bool IsTrained () const
 Check whether KDE model is trained or not. More...

 
const KernelType & Kernel () const
 Get the kernel. More...

 
KernelType & Kernel ()
 Modify the kernel. More...

 
double MCBreakCoef () const
 Get Monte Carlo break coefficient. More...

 
void MCBreakCoef (const double newCoef)
 Modify Monte Carlo break coefficient. (0 < newCoef <= 1). More...

 
double MCEntryCoef () const
 Get Monte Carlo entry coefficient. More...

 
void MCEntryCoef (const double newCoef)
 Modify Monte Carlo entry coefficient. (newCoef >= 1). More...

 
size_t MCInitialSampleSize () const
 Get Monte Carlo initial sample size. More...

 
size_t & MCInitialSampleSize ()
 Modify Monte Carlo initial sample size. More...

 
double MCProb () const
 Get Monte Carlo probability of error being bounded by relative error. More...

 
void MCProb (const double newProb)
 Modify Monte Carlo probability of error being bounded by relative error. More...

 
const MetricType & Metric () const
 Get the metric. More...

 
MetricType & Metric ()
 Modify the metric. More...

 
KDEMode Mode () const
 Get the mode of KDE. More...

 
KDEModeMode ()
 Modify the mode of KDE. More...

 
bool MonteCarlo () const
 Get whether Monte Carlo estimations are being used or not. More...

 
bool & MonteCarlo ()
 Modify whether Monte Carlo estimations are being used or not. More...

 
KDEoperator= (const KDE &other)
 Copy a KDE model. More...

 
KDEoperator= (KDE &&other)
 Move a KDE model. More...

 
bool OwnsReferenceTree () const
 Check whether reference tree is owned by the KDE model. More...

 
TreeReferenceTree ()
 Get the reference tree. More...

 
double RelativeError () const
 Get relative error tolerance. More...

 
void RelativeError (const double newError)
 Modify relative error tolerance (0 <= newError <= 1). More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t version)
 Serialize the model. More...

 
void Train (MatType referenceSet)
 Trains the KDE model. More...

 
void Train (Tree *referenceTree, std::vector< size_t > *oldFromNewReferences)
 Trains the KDE model. More...

 

Detailed Description


template<typename KernelType = kernel::GaussianKernel, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, kde::KDEStat, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, kde::KDEStat, MatType>::template SingleTreeTraverser>
class mlpack::kde::KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >

The KDE class is a template class for performing Kernel Density Estimations.

In statistics, kernel density estimation is a way to estimate the probability density function of a variable in a non parametric way. This implementation performs this estimation using a tree-independent dual-tree algorithm. Details about this algorithm are available in KDERules.

Template Parameters
KernelTypeKernel function to use for KDE calculations.
MetricTypeMetric to use for KDE calculations.
MatTypeType of data to use.
TreeTypeType of tree to use; must satisfy the TreeType policy API.
DualTreeTraversalTypeType of dual-tree traversal to use.
SingleTreeTraversalTypeType of single-tree traversal to use.

Definition at line 88 of file kde.hpp.

Member Typedef Documentation

◆ Tree

typedef TreeType<MetricType, kde::KDEStat, MatType> Tree

Convenience typedef.

Definition at line 92 of file kde.hpp.

Constructor & Destructor Documentation

◆ KDE() [1/3]

KDE ( const double  relError = KDEDefaultParams::relError,
const double  absError = KDEDefaultParams::absError,
KernelType  kernel = KernelType(),
const KDEMode  mode = KDEDefaultParams::mode,
MetricType  metric = MetricType(),
const bool  monteCarlo = KDEDefaultParams::monteCarlo,
const double  mcProb = KDEDefaultParams::mcProb,
const size_t  initialSampleSize = KDEDefaultParams::initialSampleSize,
const double  mcEntryCoef = KDEDefaultParams::mcEntryCoef,
const double  mcBreakCoef = KDEDefaultParams::mcBreakCoef 
)

Initialize KDE object using custom instantiated Metric and Kernel objects.

Parameters
relErrorRelative error tolerance of the model.
absErrorAbsolute error tolerance of the model.
kernelInstantiated kernel object.
modeMode for the algorithm.
metricInstantiated metric object.
monteCarloWhether to use Monte Carlo estimations when possible.
mcProbProbability of 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.

◆ KDE() [2/3]

KDE ( const KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &  other)

Construct KDE object as a copy of the given model.

This may be computationally intensive!

Parameters
otherKDE object to copy.

◆ KDE() [3/3]

KDE ( KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &&  other)

Construct KDE object taking ownership of the given model.

Parameters
otherKDE object to take ownership of.

◆ ~KDE()

~KDE ( )

Destroy the KDE object.

If this object created any trees, they will be deleted. If you created the trees then you have to delete them yourself.

Member Function Documentation

◆ AbsoluteError() [1/2]

double AbsoluteError ( ) const
inline

Get absolute error tolerance.

Definition at line 250 of file kde.hpp.

◆ AbsoluteError() [2/2]

void AbsoluteError ( const double  newError)

Modify absolute error tolerance (0 <= newError).

◆ Evaluate() [1/3]

void Evaluate ( MatType  querySet,
arma::vec &  estimations 
)

Estimate density of each point in the query set given the data of the reference set.

The result is stored in an estimations vector. Estimations might not be normalized.

  • Dimension of each point in the query set must match the dimension of each point in the reference set.
  • Use std::move if the query set is no longer needed.
Precondition
The model has to be previously trained.
Parameters
querySetSet of query points to get the density of.
estimationsObject which will hold the density of each query point.

◆ Evaluate() [2/3]

void Evaluate ( Tree queryTree,
const std::vector< size_t > &  oldFromNewQueries,
arma::vec &  estimations 
)

Estimate density of each point in the query set given the data of an already created query tree.

The result is stored in an estimations vector. Estimations might not be normalized.

  • Dimension of each point in the queryTree dataset must match the dimension of each point in the reference set.
  • Use std::move if the query tree is no longer needed.
Precondition
The model has to be previously trained and mode has to be dual-tree.
Parameters
queryTreeTree of query points to get the density of.
oldFromNewQueriesMappings of query points to the tree dataset.
estimationsObject which will hold the density of each query point.

◆ Evaluate() [3/3]

void Evaluate ( arma::vec &  estimations)

Estimate density of each point in the reference set given the data of the reference set.

It does not compute the estimation of a point with itself. The result is stored in an estimations vector. Estimations might not be normalized.

Precondition
The model has to be previously trained.
Parameters
estimationsObject which will hold the density of each reference point.

◆ IsTrained()

bool IsTrained ( ) const
inline

Check whether KDE model is trained or not.

Definition at line 259 of file kde.hpp.

◆ Kernel() [1/2]

const KernelType& Kernel ( ) const
inline

Get the kernel.

Definition at line 229 of file kde.hpp.

◆ Kernel() [2/2]

KernelType& Kernel ( )
inline

Modify the kernel.

Definition at line 232 of file kde.hpp.

◆ MCBreakCoef() [1/2]

double MCBreakCoef ( ) const
inline

Get Monte Carlo break coefficient.

Definition at line 293 of file kde.hpp.

◆ MCBreakCoef() [2/2]

void MCBreakCoef ( const double  newCoef)

Modify Monte Carlo break coefficient. (0 < newCoef <= 1).

◆ MCEntryCoef() [1/2]

double MCEntryCoef ( ) const
inline

Get Monte Carlo entry coefficient.

Definition at line 287 of file kde.hpp.

◆ MCEntryCoef() [2/2]

void MCEntryCoef ( const double  newCoef)

Modify Monte Carlo entry coefficient. (newCoef >= 1).

◆ MCInitialSampleSize() [1/2]

size_t MCInitialSampleSize ( ) const
inline

Get Monte Carlo initial sample size.

Definition at line 281 of file kde.hpp.

◆ MCInitialSampleSize() [2/2]

size_t& MCInitialSampleSize ( )
inline

Modify Monte Carlo initial sample size.

Definition at line 284 of file kde.hpp.

◆ MCProb() [1/2]

double MCProb ( ) const
inline

Get Monte Carlo probability of error being bounded by relative error.

Definition at line 274 of file kde.hpp.

◆ MCProb() [2/2]

void MCProb ( const double  newProb)

Modify Monte Carlo probability of error being bounded by relative error.

(0 <= newProb < 1).

◆ Metric() [1/2]

const MetricType& Metric ( ) const
inline

Get the metric.

Definition at line 235 of file kde.hpp.

◆ Metric() [2/2]

MetricType& Metric ( )
inline

Modify the metric.

Definition at line 238 of file kde.hpp.

◆ Mode() [1/2]

KDEMode Mode ( ) const
inline

Get the mode of KDE.

Definition at line 262 of file kde.hpp.

◆ Mode() [2/2]

KDEMode& Mode ( )
inline

Modify the mode of KDE.

Definition at line 265 of file kde.hpp.

◆ MonteCarlo() [1/2]

bool MonteCarlo ( ) const
inline

Get whether Monte Carlo estimations are being used or not.

Definition at line 268 of file kde.hpp.

◆ MonteCarlo() [2/2]

bool& MonteCarlo ( )
inline

Modify whether Monte Carlo estimations are being used or not.

Definition at line 271 of file kde.hpp.

◆ operator=() [1/2]

KDE& operator= ( const KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &  other)

Copy a KDE model.

Parameters
otherKDE model to copy.

◆ operator=() [2/2]

KDE& operator= ( KDE< KernelType, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &&  other)

Move a KDE model.

Parameters
otherKDE model to copy.

◆ OwnsReferenceTree()

bool OwnsReferenceTree ( ) const
inline

Check whether reference tree is owned by the KDE model.

Definition at line 256 of file kde.hpp.

◆ ReferenceTree()

Tree* ReferenceTree ( )
inline

Get the reference tree.

Definition at line 241 of file kde.hpp.

◆ RelativeError() [1/2]

double RelativeError ( ) const
inline

Get relative error tolerance.

Definition at line 244 of file kde.hpp.

◆ RelativeError() [2/2]

void RelativeError ( const double  newError)

Modify relative error tolerance (0 <= newError <= 1).

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t  version 
)

Serialize the model.

◆ Train() [1/2]

void Train ( MatType  referenceSet)

Trains the KDE model.

It builds a tree using a reference set.

Use std::move if the reference set is no longer needed.

Parameters
referenceSetSet of reference data.

◆ Train() [2/2]

void Train ( Tree referenceTree,
std::vector< size_t > *  oldFromNewReferences 
)

Trains the KDE model.

Sets the reference tree to an already created tree.

  • If TreeTraits<TreeType>::RearrangesDataset is false then it is possible to use an empty oldFromNewReferences vector.
Parameters
referenceTreeBuilt reference tree.
oldFromNewReferencesPermutations of reference points obtained during tree generation.

The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/methods/kde/kde.hpp