JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
Collaboration diagram for 2-dimensional Kernel Density Estimates:

Modules

 Kernels for 2-dimensional Histograms
 

Functions

template<class InputIt >
double jkqtpstatEstimateKDEBandwidth2D (InputIt first, InputIt last)
 estimates a bandwidth for a 2-dimensional Kernel Density Estimator (KDE) of the given data first ... last using Scott's rule
 
template<class InputItX , class InputItY >
double jkqtpstatEvaluateKernelSum2D (double x, double y, InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, const std::function< double(double, double)> &kernel, double bandwidthX, double bandwidthY)
 evaluates the Kernel Density Estimator (KDE) at a given position
 
template<class InputItX , class InputItY , class OutputIt >
void jkqtpstatKDE2D (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, OutputIt histogramImgOut, double xmin, double xmax, double ymin, double ymax, size_t xbins, size_t ybins, const std::function< double(double, double)> &kernel=std::function< double(double, double)>(&jkqtpstatKernel2DGaussian), double bandwidthX=1.0, double bandwidthY=1.0)
 calculate an autoranged 2-dimensional Kernel Density Estimation (KDE) from the given data range firstX / firstY ... lastY / lastY
 
template<class InputItX , class InputItY , class FF >
int jkqtpstatStoreKernelSum2D (FF &&fStore, InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, const std::function< double(double, double)> &kernel, double bandwidthX, double bandwidthY)
 stores a part-result of the Kernel Density Estimator (KDE) at a given position
 

Detailed Description

Function Documentation

◆ jkqtpstatEstimateKDEBandwidth2D()

template<class InputIt >
double jkqtpstatEstimateKDEBandwidth2D ( InputIt  first,
InputIt  last 
)
inline

estimates a bandwidth for a 2-dimensional Kernel Density Estimator (KDE) of the given data first ... last using Scott's rule

evaluates

\[ h =  \hat{\sigma} n^{-1/(d+4)},\ \ \ \ \ d=2 \]

Template Parameters
InputItstandard iterator type of first and last.
Parameters
firstiterator pointing to the first item in the dataset to use $ X_1 $
lastiterator pointing behind the last item in the dataset to use $ X_N $
Returns
the estimated bandwidth
See also
https://en.wikipedia.org/wiki/Multivariate_kernel_density_estimation#Rule_of_thumb

◆ jkqtpstatEvaluateKernelSum2D()

template<class InputItX , class InputItY >
double jkqtpstatEvaluateKernelSum2D ( double  x,
double  y,
InputItX  firstX,
InputItX  lastX,
InputItY  firstY,
InputItY  lastY,
const std::function< double(double, double)> &  kernel,
double  bandwidthX,
double  bandwidthY 
)
inline

evaluates the Kernel Density Estimator (KDE) at a given position

evaluates

\[ \tilde{f}(x,y):=\frac{1}{N\cdot\sqrt{\text{bandwidthx}}\cdot\sqrt{\text{bandwidthy}}}\cdot\sum\limits_{i=0}^{N-1}K\left(\frac{x-x_i}{\text{bandwidthx}},\frac{y-y_i}{\text{bandwidthy}}\right) \]

Template Parameters
InputItXstandard iterator type of firstX and lastX.
InputItYstandard iterator type of firstY and lastY.
Parameters
xwhere to evaluate the kernel sum, x-coordinate
ywhere to evaluate the kernel sum, y-coordinate
firstXiterator pointing to the first x-position item in the dataset to use $ X_1 $
lastXiterator pointing behind the last x-position item in the dataset to use $ X_N $
firstYiterator pointing to the first y-position item in the dataset to use $ Y_1 $
lastYiterator pointing behind the last y-position item in the dataset to use $ Y_N $
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthXx-bandwidth used for the KDE
bandwidthYy-bandwidth used for the KDE

◆ jkqtpstatKDE2D()

template<class InputItX , class InputItY , class OutputIt >
void jkqtpstatKDE2D ( InputItX  firstX,
InputItX  lastX,
InputItY  firstY,
InputItY  lastY,
OutputIt  histogramImgOut,
double  xmin,
double  xmax,
double  ymin,
double  ymax,
size_t  xbins,
size_t  ybins,
const std::function< double(double, double)> &  kernel = std::function<double(double,double)>(&jkqtpstatKernel2DGaussian),
double  bandwidthX = 1.0,
double  bandwidthY = 1.0 
)
inline

calculate an autoranged 2-dimensional Kernel Density Estimation (KDE) from the given data range firstX / firstY ... lastY / lastY

Template Parameters
InputItXstandard iterator type of firstX and lastX.
InputItYstandard iterator type of firstY and lastY.
OutputItstandard output iterator type used for the outliers output histogramXOut and histogramYOut, use e.g. std::back_inserter
Parameters
firstXiterator pointing to the first x-position item in the dataset to use $ X_1 $
lastXiterator pointing behind the last x-position item in the dataset to use $ X_N $
firstYiterator pointing to the first y-position item in the dataset to use $ Y_1 $
lastYiterator pointing behind the last y-position item in the dataset to use $ Y_N $
[out]histogramImgOutoutput iterator that receives counts of the histogram bins in row-major ordering
xminposition of the first histogram bin in x-direction
xmaxposition of the last histogram bin in x-direction
yminposition of the first histogram bin in y-direction
ymaxposition of the last histogram bin in y-direction
xbinsnumber of bins in x-direction (i.e. width of the output histogram histogramImgOut )
ybinsnumber of bins in y-direction (i.e. height of the output histogram histogramImgOut )
kernelthe kernel function to use (e.g. jkqtpstatKernel2DGaussian() )
bandwidthXx-bandwidth used for the KDE
bandwidthYy-bandwidth used for the KDE
See also
https://en.wikipedia.org/wiki/Multivariate_kernel_density_estimation, Tutorial (JKQTPDatastore): Advanced 1-Dimensional Statistics with JKQTPDatastore

◆ jkqtpstatStoreKernelSum2D()

template<class InputItX , class InputItY , class FF >
int jkqtpstatStoreKernelSum2D ( FF &&  fStore,
InputItX  firstX,
InputItX  lastX,
InputItY  firstY,
InputItY  lastY,
const std::function< double(double, double)> &  kernel,
double  bandwidthX,
double  bandwidthY 
)
inline

stores a part-result of the Kernel Density Estimator (KDE) at a given position

Iterates over all datapoints in firstX..lastX and firstY..lastY, for each one determines whether the floating-point values are valid and the calls fStore, which is a functor that is supposed to iterate over the KDE 2D array and over calls sum up the KDE.

This is internally used by jkqtpstatKDE2D(). The construction is not as straight-forward, as iterating over all positions in the 2D-KJDE and the calling jkqtpstatEvaluateKernelSum2D(), bt by reordering the loops it is significatyl faster (~20%)

Template Parameters
InputItXstandard iterator type of firstX and lastX.
InputItYstandard iterator type of firstY and lastY.
FFfunctor
Parameters
xwhere to evaluate the kernel sum, x-coordinate
ywhere to evaluate the kernel sum, y-coordinate
firstXiterator pointing to the first x-position item in the dataset to use $ X_1 $
lastXiterator pointing behind the last x-position item in the dataset to use $ X_N $
firstYiterator pointing to the first y-position item in the dataset to use $ Y_1 $
lastYiterator pointing behind the last y-position item in the dataset to use $ Y_N $
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthXx-bandwidth used for the KDE
bandwidthYy-bandwidth used for the KDE