38 std::shared_ptr<kernel::Kernel>
kernel_{
nullptr};
42 std::optional<Eigen::Ref<const Eigen::MatrixXd>>
pData_;
61 KDE(std::shared_ptr<kernel::Bandwidth> bandwidth, std::shared_ptr<kernel::Kernel> kernel);
76 void set(
const std::shared_ptr<kernel::Bandwidth> &bandwidth,
const std::shared_ptr<kernel::Kernel> &kernel);
83 void condition(
const Eigen::Ref<const Eigen::MatrixXd> &data,
bool copyData =
false);
90 double eval(
const Eigen::VectorXd &x)
const;
121void bandwidthOptimizationCrossValidation(
const cmp::statistics::KFold& kf, Eigen::Ref<Eigen::MatrixXd> xObs, std::shared_ptr<cmp::kernel::Kernel> kernel, std::shared_ptr<cmp::kernel::Bandwidth> initialBandwidth,
const double &min,
const double &max, nlopt::algorithm alg,
const double & tol = 1e-4);
Multivariate Kernel Density Estimation (KDE) class.
Definition kde.h:35
void set(const std::shared_ptr< kernel::Bandwidth > &bandwidth, const std::shared_ptr< kernel::Kernel > &kernel)
Set the bandwidth and kernel for the KDE.
Definition kde.cpp:37
std::optional< Eigen::Ref< const Eigen::MatrixXd > > pData_
Non-owning reference wrapper to data.
Definition kde.h:42
double eval(const Eigen::VectorXd &x) const
Evaluate the KDE at a given point.
Definition kde.cpp:59
KDE()
Default constructor for KDE. Creates a KDE with identity bandwidth and Gaussian kernel in 1D.
Definition kde.cpp:3
size_t nPoints_
Number of data points.
Definition kde.h:47
size_t dim_
Dimension of the dataset.
Definition kde.h:46
void condition(const Eigen::Ref< const Eigen::MatrixXd > &data, bool copyData=false)
Condition the KDE on the provided data.
Definition kde.cpp:43
BandWidthSelectionMethod
Definition kde.h:93
Eigen::MatrixXd data_
Owning data storage.
Definition kde.h:41
std::shared_ptr< kernel::Bandwidth > bandwidth_
Bandwidth matrix of the kernel.
Definition kde.h:37
std::shared_ptr< kernel::Kernel > kernel_
The density kernel function.
Definition kde.h:38
KDE & operator=(const KDE &other)
Definition kde.cpp:21
bool isOwning_
Flag indicating whether the KDE owns the data.
Definition kde.h:43
K-Fold cross-validation partition generator.
Definition statistics.h:44
void bandwidthOptimizationCrossValidation(const cmp::statistics::KFold &kf, Eigen::Ref< Eigen::MatrixXd > xObs, std::shared_ptr< cmp::kernel::Kernel > kernel, std::shared_ptr< cmp::kernel::Bandwidth > initialBandwidth, const double &min, const double &max, nlopt::algorithm alg, const double &tol=1e-4)
Optimizes the bandwidth matrix using K-Fold cross-validation over the observations.
Definition kde.cpp:115
Eigen::MatrixXd bandwidthSelectionRule(const KDE::BandWidthSelectionMethod &method, Eigen::Ref< Eigen::MatrixXd > xObs)
Computes the bandwidth matrix using standard rules of thumb.
Definition kde.cpp:72
Functor wrapper for NLopt with automatic, transparent log-scaling.
Header file for statistical functions and classes.