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

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

Public Types

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

 

Public Member Functions

 KDE (const double relError=0.05, const double absError=0, KernelType kernel=KernelType(), const KDEMode mode=DUAL_TREE_MODE, MetricType metric=MetricType())
 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...

 
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...

 
KDEoperator= (KDE other)
 Copy 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 unsigned int)
 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 59 of file kde.hpp.

Member Typedef Documentation

◆ Tree

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

Convenience typedef.

Definition at line 63 of file kde.hpp.

Constructor & Destructor Documentation

◆ KDE() [1/3]

KDE ( const double  relError = 0.05,
const double  absError = 0,
KernelType  kernel = KernelType(),
const KDEMode  mode = DUAL_TREE_MODE,
MetricType  metric = MetricType() 
)

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.

◆ 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 200 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 209 of file kde.hpp.

◆ Kernel() [1/2]

const KernelType& Kernel ( ) const
inline

Get the kernel.

Definition at line 179 of file kde.hpp.

◆ Kernel() [2/2]

KernelType& Kernel ( )
inline

Modify the kernel.

Definition at line 182 of file kde.hpp.

◆ Metric() [1/2]

const MetricType& Metric ( ) const
inline

Get the metric.

Definition at line 185 of file kde.hpp.

◆ Metric() [2/2]

MetricType& Metric ( )
inline

Modify the metric.

Definition at line 188 of file kde.hpp.

◆ Mode() [1/2]

KDEMode Mode ( ) const
inline

Get the mode of KDE.

Definition at line 212 of file kde.hpp.

◆ Mode() [2/2]

◆ operator=()

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

Copy a KDE model.

Use std::move if the object to copy is no longer needed.

Parameters
otherKDE model to copy.

◆ OwnsReferenceTree()

bool OwnsReferenceTree ( ) const
inline

Check whether reference tree is owned by the KDE model.

Definition at line 206 of file kde.hpp.

◆ ReferenceTree()

Tree* ReferenceTree ( )
inline

Get the reference tree.

Definition at line 191 of file kde.hpp.

◆ RelativeError() [1/2]

double RelativeError ( ) const
inline

Get relative error tolerance.

Definition at line 194 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 unsigned  int 
)

◆ 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-3.1.0/src/mlpack/methods/kde/kde.hpp