CMP++: Uncertainty Quantification & Bayesian Calibration
Loading...
Searching...
No Matches
cmp::density::KDE Class Reference

Multivariate Kernel Density Estimation (KDE) class. More...

#include <kde.h>

Public Types

enum class  BandWidthSelectionMethod { SCOTT , SILVERMAN }
 

Public Member Functions

 KDE ()
 Default constructor for KDE. Creates a KDE with identity bandwidth and Gaussian kernel in 1D.
 
 KDE (std::shared_ptr< kernel::Bandwidth > bandwidth, std::shared_ptr< kernel::Kernel > kernel)
 Constructor for KDE with specified bandwidth and kernel.
 
 KDE (const KDE &other)
 
 KDE (KDE &&other) noexcept
 
KDEoperator= (const KDE &other)
 
KDEoperator= (KDE &&other) noexcept
 
void set (const std::shared_ptr< kernel::Bandwidth > &bandwidth, const std::shared_ptr< kernel::Kernel > &kernel)
 Set the bandwidth and kernel for the KDE.
 
void condition (const Eigen::Ref< const Eigen::MatrixXd > &data, bool copyData=false)
 Condition the KDE on the provided data.
 
double eval (const Eigen::VectorXd &x) const
 Evaluate the KDE at a given point.
 

Private Attributes

std::shared_ptr< kernel::Bandwidthbandwidth_ {nullptr}
 Bandwidth matrix of the kernel.
 
std::shared_ptr< kernel::Kernelkernel_ {nullptr}
 The density kernel function.
 
Eigen::MatrixXd data_ {0, 0}
 Owning data storage.
 
std::optional< Eigen::Ref< const Eigen::MatrixXd > > pData_
 Non-owning reference wrapper to data.
 
bool isOwning_ {false}
 Flag indicating whether the KDE owns the data.
 
size_t dim_ {0}
 Dimension of the dataset.
 
size_t nPoints_ {0}
 Number of data points.
 

Detailed Description

Multivariate Kernel Density Estimation (KDE) class.

Mathematical Formulation Evaluates the multivariate probability density function estimate of a random vector \(\mathbf{x} \in \mathbb{R}^D\) based on observations \(\{\mathbf{x}_i\}_{i=1}^N\):

\[ \hat{f}(\mathbf{x}) = \frac{1}{N} \sum_{i=1}^N \frac{1}{\det(\mathbf{H})} K\left( \mathbf{H}^{-1} (\mathbf{x} - \mathbf{x}_i) \right) \]

where \(\mathbf{H}\) is the bandwidth matrix and \(K\) is the multi-dimensional kernel function.

  • Scott's Rule: \(H_{dd} = N^{-1/(D+4)} \hat{\sigma}_d\)
  • Silverman's Rule: \(H_{dd} = \left(\frac{4}{D+2}\right)^{1/(D+4)} N^{-1/(D+4)} \hat{\sigma}_d\) where \(\hat{\sigma}_d\) is the standard deviation of coordinate \(d\).

    Implementation Algorithm

  1. condition() registers the dataset references.
  2. eval() averages kernel evaluations over all conditioning observation points, scaled by the determinant of the bandwidth matrix.

Member Enumeration Documentation

◆ BandWidthSelectionMethod

Enumerator
SCOTT 
SILVERMAN 

Constructor & Destructor Documentation

◆ KDE() [1/4]

cmp::density::KDE::KDE ( )

Default constructor for KDE. Creates a KDE with identity bandwidth and Gaussian kernel in 1D.

◆ KDE() [2/4]

cmp::density::KDE::KDE ( std::shared_ptr< kernel::Bandwidth bandwidth,
std::shared_ptr< kernel::Kernel kernel 
)

Constructor for KDE with specified bandwidth and kernel.

Parameters
bandwidthShared pointer to the bandwidth object.
kernelShared pointer to the kernel object.

◆ KDE() [3/4]

cmp::density::KDE::KDE ( const KDE other)

◆ KDE() [4/4]

cmp::density::KDE::KDE ( KDE &&  other)
noexcept

Member Function Documentation

◆ condition()

void cmp::density::KDE::condition ( const Eigen::Ref< const Eigen::MatrixXd > &  data,
bool  copyData = false 
)

Condition the KDE on the provided data.

Parameters
dataThe data matrix where each row is a data point.
copyDataIf true, the data is copied into the KDE object; if false, a reference is kept.

◆ eval()

double cmp::density::KDE::eval ( const Eigen::VectorXd &  x) const

Evaluate the KDE at a given point.

Parameters
xThe point at which to evaluate the density estimate.
Returns
The estimated density at point x.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ set()

void cmp::density::KDE::set ( const std::shared_ptr< kernel::Bandwidth > &  bandwidth,
const std::shared_ptr< kernel::Kernel > &  kernel 
)

Set the bandwidth and kernel for the KDE.

Parameters
bandwidthShared pointer to the bandwidth object.
kernelShared pointer to the kernel object.

Member Data Documentation

◆ bandwidth_

std::shared_ptr<kernel::Bandwidth> cmp::density::KDE::bandwidth_ {nullptr}
private

Bandwidth matrix of the kernel.

◆ data_

Eigen::MatrixXd cmp::density::KDE::data_ {0, 0}
private

Owning data storage.

◆ dim_

size_t cmp::density::KDE::dim_ {0}
private

Dimension of the dataset.

◆ isOwning_

bool cmp::density::KDE::isOwning_ {false}
private

Flag indicating whether the KDE owns the data.

◆ kernel_

std::shared_ptr<kernel::Kernel> cmp::density::KDE::kernel_ {nullptr}
private

The density kernel function.

◆ nPoints_

size_t cmp::density::KDE::nPoints_ {0}
private

Number of data points.

◆ pData_

std::optional<Eigen::Ref<const Eigen::MatrixXd> > cmp::density::KDE::pData_
private

Non-owning reference wrapper to data.


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