|
CMP++: Uncertainty Quantification & Bayesian Calibration
|
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 | |
| KDE & | operator= (const KDE &other) |
| KDE & | operator= (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::Bandwidth > | bandwidth_ {nullptr} |
| Bandwidth matrix of the kernel. | |
| std::shared_ptr< kernel::Kernel > | kernel_ {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. | |
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.
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
condition() registers the dataset references.eval() averages kernel evaluations over all conditioning observation points, scaled by the determinant of the bandwidth matrix. | cmp::density::KDE::KDE | ( | ) |
| cmp::density::KDE::KDE | ( | std::shared_ptr< kernel::Bandwidth > | bandwidth, |
| std::shared_ptr< kernel::Kernel > | kernel | ||
| ) |
Constructor for KDE with specified bandwidth and kernel.
| bandwidth | Shared pointer to the bandwidth object. |
| kernel | Shared pointer to the kernel object. |
|
noexcept |
Evaluate the KDE at a given point.
| x | The point at which to evaluate the density estimate. |
| cmp::density::KDE & cmp::density::KDE::operator= | ( | const KDE & | other | ) |
|
noexcept |
| 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.
| bandwidth | Shared pointer to the bandwidth object. |
| kernel | Shared pointer to the kernel object. |
|
private |
Bandwidth matrix of the kernel.
|
private |
Owning data storage.
|
private |
Dimension of the dataset.
|
private |
The density kernel function.
|
private |
Number of data points.
|
private |
Non-owning reference wrapper to data.