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=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... | |
KDEMode & | Mode () |
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... | |
KDE & | operator= (KDE other) |
Copy a KDE model. More... | |
bool | OwnsReferenceTree () const |
Check whether reference tree is owned by the KDE model. More... | |
Tree * | ReferenceTree () |
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 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... | |
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.
KernelType | Kernel function to use for KDE calculations. |
MetricType | Metric to use for KDE calculations. |
MatType | Type of data to use. |
TreeType | Type of tree to use; must satisfy the TreeType policy API. |
DualTreeTraversalType | Type of dual-tree traversal to use. |
SingleTreeTraversalType | Type of single-tree traversal to use. |
typedef TreeType<MetricType, kde::KDEStat, MatType> Tree |
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.
relError | Relative error tolerance of the model. |
absError | Absolute error tolerance of the model. |
kernel | Instantiated kernel object. |
mode | Mode for the algorithm. |
metric | Instantiated metric object. |
monteCarlo | Whether to use Monte Carlo estimations when possible. |
mcProb | Probability of a Monte Carlo estimation to be bounded by relative error tolerance. |
initialSampleSize | Initial sample size for Monte Carlo estimations. |
mcEntryCoef | Coefficient 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. |
mcBreakCoef | Coefficient to control what fraction of the node's descendants evaluated is the limit before Monte Carlo estimation recurses. |
~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.
|
inline |
Get absolute error tolerance.
Definition at line 245 of file kde.hpp.
References KDEDefaultParams::absError.
void AbsoluteError | ( | const double | newError | ) |
Modify absolute error tolerance (0 <= newError).
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.
querySet | Set of query points to get the density of. |
estimations | Object which will hold the density of each query point. |
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.
queryTree | Tree of query points to get the density of. |
oldFromNewQueries | Mappings of query points to the tree dataset. |
estimations | Object which will hold the density of each query point. |
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.
estimations | Object which will hold the density of each reference point. |
|
inline |
|
inline |
Get Monte Carlo break coefficient.
Definition at line 288 of file kde.hpp.
References KDEDefaultParams::absError, KDEDefaultParams::initialSampleSize, KDEDefaultParams::mcBreakCoef, KDEDefaultParams::mcEntryCoef, KDEDefaultParams::mcProb, KDEDefaultParams::mode, KDEDefaultParams::monteCarlo, and KDEDefaultParams::relError.
void MCBreakCoef | ( | const double | newCoef | ) |
Modify Monte Carlo break coefficient. (0 < newCoef <= 1).
|
inline |
Get Monte Carlo entry coefficient.
Definition at line 282 of file kde.hpp.
References KDEDefaultParams::mcEntryCoef.
void MCEntryCoef | ( | const double | newCoef | ) |
Modify Monte Carlo entry coefficient. (newCoef >= 1).
|
inline |
Get Monte Carlo initial sample size.
Definition at line 276 of file kde.hpp.
References KDEDefaultParams::initialSampleSize.
|
inline |
Modify Monte Carlo initial sample size.
Definition at line 279 of file kde.hpp.
References KDEDefaultParams::initialSampleSize.
|
inline |
Get Monte Carlo probability of error being bounded by relative error.
Definition at line 269 of file kde.hpp.
References KDEDefaultParams::mcProb.
void MCProb | ( | const double | newProb | ) |
Modify Monte Carlo probability of error being bounded by relative error.
(0 <= newProb < 1).
|
inline |
|
inline |
|
inline |
Get whether Monte Carlo estimations are being used or not.
Definition at line 263 of file kde.hpp.
References KDEDefaultParams::monteCarlo.
|
inline |
Modify whether Monte Carlo estimations are being used or not.
Definition at line 266 of file kde.hpp.
References KDEDefaultParams::monteCarlo.
|
inline |
|
inline |
Get relative error tolerance.
Definition at line 239 of file kde.hpp.
References KDEDefaultParams::relError.
void RelativeError | ( | const double | newError | ) |
Modify relative error tolerance (0 <= newError <= 1).
void serialize | ( | Archive & | ar, |
const unsigned int | version | ||
) |
Serialize the model.
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.
referenceSet | Set of reference data. |
void Train | ( | Tree * | referenceTree, |
std::vector< size_t > * | oldFromNewReferences | ||
) |
Trains the KDE model.
Sets the reference tree to an already created tree.
referenceTree | Built reference tree. |
oldFromNewReferences | Permutations of reference points obtained during tree generation. |