bpp-core3  3.0.0
AdaptiveKernelDensityEstimation.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_ADAPTIVEKERNELDENSITYESTIMATION_H
6 #define BPP_NUMERIC_ADAPTIVEKERNELDENSITYESTIMATION_H
7 
8 
9 #include "Matrix/Matrix.h"
10 
11 namespace bpp
12 {
24 {
25 private:
26  RowMatrix<double> x_; // The original sample
27  size_t n_;
28  size_t r_;
29  RowMatrix<double> covar_; // The covariance matrix, used for the linear transformation
30  RowMatrix<double> invSqrtCovar_; // The inverse of the square root of the covariance matrix, used for the linear transformation
31  std::vector<double> xMean_;
32  double gamma_; // Tune the effect of the pilot density.
33  double c1_;
34  std::vector<double> c2_;
35  double h_; // The bandwidth.
36  std::vector<double> lambda_; // The local tuning coefficient of the bandwidth.
37  std::vector<double> pilot_; // The pilot density
38 
39 public:
49  AdaptiveKernelDensityEstimation(const Matrix<double>& x, double gamma = 0.5) :
50  x_(x), n_(x.getNumberOfColumns()), r_(x.getNumberOfRows()),
51  covar_(), invSqrtCovar_(), xMean_(), gamma_(gamma),
52  c1_(0), c2_(x.getNumberOfColumns()), h_(0),
53  lambda_(x.getNumberOfColumns()), pilot_(x.getNumberOfColumns())
54  {
55  init_();
56  }
58 
59 public:
64  double kDensity(const std::vector<double>& x);
65 
66 private:
67  void init_();
68 
69  void sampleMean_(const Matrix<double>& x, std::vector<double>& mean);
70 
80  double kernel_(const Matrix<double>& x);
81 };
82 } // End of namespace bpp.
83 #endif // BPP_NUMERIC_ADAPTIVEKERNELDENSITYESTIMATION_H
The matrix template interface.
Definition: Matrix.h:22
AdaptiveKernelDensityEstimation(const Matrix< double > &x, double gamma=0.5)
Build a new AdaptiveKernelDensityEstimation object.
void sampleMean_(const Matrix< double > &x, std::vector< double > &mean)
double kernel_(const Matrix< double > &x)
The kernel function.
double kDensity(const std::vector< double > &x)
Density estimation using the adaptive kernel method.