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 1-dimensional Kernel Density Estimates:

Modules

 Kernels for 1-dimensional Histograms
 

Functions

template<class InputIt >
double jkqtpstatEstimateKDEBandwidth (InputIt first, InputIt last)
 estimates a bandwidth for a Kernel Density Estimator (KDE) of the given data first ... last
 
template<class InputIt >
double jkqtpstatEvaluateKernelSum (double t, InputIt first, InputIt last, const std::function< double(double)> &kernel, double bandwidth)
 evaluates the Kernel Density Estimator (KDE) at a given position
 
template<class InputIt , class BinsInputIt , class OutputIt >
void jkqtpstatKDE1D (InputIt first, InputIt last, BinsInputIt binsFirst, BinsInputIt binsLast, OutputIt KDEXOut, OutputIt KDEYOut, const std::function< double(double)> &kernel=std::function< double(double)>(&jkqtpstatKernel1DGaussian), double bandwidth=1.0, bool cummulative=false)
 calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined the range binsFirst ... binsLast
 
template<class InputIt , class OutputIt >
void jkqtpstatKDE1D (InputIt first, InputIt last, double binXLeft, double binXDelta, double binXRight, OutputIt KDEXOut, OutputIt KDEYOut, const std::function< double(double)> &kernel=std::function< double(double)>(&jkqtpstatKernel1DGaussian), double bandwidth=1.0, bool cummulative=false)
 calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, evaluation positions are given by the range binXLeft ... binXRight (in steps of binxDelta )
 
template<class InputIt , class OutputIt >
void jkqtpstatKDE1DAutoranged (InputIt first, InputIt last, OutputIt KDEXOut, OutputIt KDEYOut, double binWidth, const std::function< double(double)> &kernel=std::function< double(double)>(&jkqtpstatKernel1DGaussian), double bandwidth=1.0, bool cummulative=false)
 calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined by their number
 
template<class InputIt , class OutputIt >
void jkqtpstatKDE1DAutoranged (InputIt first, InputIt last, OutputIt KDEXOut, OutputIt KDEYOut, int Nout=100, const std::function< double(double)> &kernel=std::function< double(double)>(&jkqtpstatKernel1DGaussian), double bandwidth=1.0, bool cummulative=false)
 calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined by their number
 

Detailed Description

Function Documentation

◆ jkqtpstatEstimateKDEBandwidth()

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

estimates a bandwidth for a Kernel Density Estimator (KDE) of the given data first ... last

evaluates

\[ h = \left(\frac{4\hat{\sigma}^5}{3n}\right)^{\frac{1}{5}} \approx 1.06 \hat{\sigma} n^{-1/5} \]

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

◆ jkqtpstatEvaluateKernelSum()

template<class InputIt >
double jkqtpstatEvaluateKernelSum ( double  t,
InputIt  first,
InputIt  last,
const std::function< double(double)> &  kernel,
double  bandwidth 
)
inline

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

evaluates

\[ \tilde{f}(t):=\frac{1}{N\cdot\text{bandwidth}}\cdot\sum\limits_{i=0}^{N-1}K\left(\frac{t-x_i}{\text{bandwidth}}\right) \]

Template Parameters
InputItstandard iterator type of first and last.
Parameters
twhere to evaluate the kernel sum
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 $
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthbandwidth used for the KDE

◆ jkqtpstatKDE1D() [1/2]

template<class InputIt , class BinsInputIt , class OutputIt >
void jkqtpstatKDE1D ( InputIt  first,
InputIt  last,
BinsInputIt  binsFirst,
BinsInputIt  binsLast,
OutputIt  KDEXOut,
OutputIt  KDEYOut,
const std::function< double(double)> &  kernel = std::function<double(double)>(&jkqtpstatKernel1DGaussian),
double  bandwidth = 1.0,
bool  cummulative = false 
)
inline

calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined the range binsFirst ... binsLast

Template Parameters
InputItstandard iterator type of first and last.
BinsInputItstandard iterator type of binsFirst and binsLast.
OutputItstandard output iterator type used for the outliers output KDEXOut and KDEYOut, use e.g. std::back_inserter
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 $
binsFirstiterator pointing to the first item in the set of KDE bins
binsLastiterator pointing behind the last item in the set of KDE bins
[out]KDEXOutoutput iterator that receives x-positions of the KDE bins. Location of this value inside the bin range is defined by binXMode
[out]KDEYOutoutput iterator that receives counts/frequencies of the KDE bins
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthbandwidth used for the KDE
cummulativeif true, a cummulative KDE is calculated
See also
https://en.wikipedia.org/wiki/Kernel_density_estimation, Tutorial (JKQTPDatastore): Advanced 1-Dimensional Statistics with JKQTPDatastore

◆ jkqtpstatKDE1D() [2/2]

template<class InputIt , class OutputIt >
void jkqtpstatKDE1D ( InputIt  first,
InputIt  last,
double  binXLeft,
double  binXDelta,
double  binXRight,
OutputIt  KDEXOut,
OutputIt  KDEYOut,
const std::function< double(double)> &  kernel = std::function<double(double)>(&jkqtpstatKernel1DGaussian),
double  bandwidth = 1.0,
bool  cummulative = false 
)
inline

calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, evaluation positions are given by the range binXLeft ... binXRight (in steps of binxDelta )

Template Parameters
InputItstandard iterator type of first and last.
OutputItstandard output iterator type used for the outliers output KDEXOut and KDEYOut, use e.g. std::back_inserter
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 $
binXLeftfirst x-position, where to evaluate the KDE
binXDeltadistance between two x-positions at which the KDE is evaluated
binXRightlast x-position, where to evaluate the KDE
[out]KDEXOutoutput iterator that receives x-positions of the KDE bins. Location of this value inside the bin range is defined by binXMode
[out]KDEYOutoutput iterator that receives counts/frequencies of the KDE bins
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthbandwidth used for the KDE
cummulativeif true, a cummulative KDE is calculated
See also
https://en.wikipedia.org/wiki/Kernel_density_estimation, Tutorial (JKQTPDatastore): Advanced 1-Dimensional Statistics with JKQTPDatastore

◆ jkqtpstatKDE1DAutoranged() [1/2]

template<class InputIt , class OutputIt >
void jkqtpstatKDE1DAutoranged ( InputIt  first,
InputIt  last,
OutputIt  KDEXOut,
OutputIt  KDEYOut,
double  binWidth,
const std::function< double(double)> &  kernel = std::function<double(double)>(&jkqtpstatKernel1DGaussian),
double  bandwidth = 1.0,
bool  cummulative = false 
)
inline

calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined by their number

Template Parameters
InputItstandard iterator type of first and last.
OutputItstandard output iterator type used for the outliers output KDEXOut and KDEYOut, use e.g. std::back_inserter
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 $
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthbandwidth used for the KDE
[out]KDEXOutoutput iterator that receives x-positions of the KDE bins. Location of this value inside the bin range is defined by binXMode
[out]KDEYOutoutput iterator that receives counts/frequencies of the KDE bins
binWidthwidth of the bins
cummulativeif true, a cummulative KDE is calculated

This function performs Kernel Density Estimation for a given data array. Then the resulting density is evaluated on a regular grid spanning [min(X)...max(X)] with bins datapoints in between.

Warning
this functions is getting very slow for large dataset, as for each point in the resulting histogram N kernel functions have to be evaluated.
See also
https://en.wikipedia.org/wiki/Kernel_density_estimation, Tutorial (JKQTPDatastore): Advanced 1-Dimensional Statistics with JKQTPDatastore

◆ jkqtpstatKDE1DAutoranged() [2/2]

template<class InputIt , class OutputIt >
void jkqtpstatKDE1DAutoranged ( InputIt  first,
InputIt  last,
OutputIt  KDEXOut,
OutputIt  KDEYOut,
int  Nout = 100,
const std::function< double(double)> &  kernel = std::function<double(double)>(&jkqtpstatKernel1DGaussian),
double  bandwidth = 1.0,
bool  cummulative = false 
)
inline

calculate an autoranged 1-dimensional Kernel Density Estimation (KDE) from the given data range first ... last, bins defined by their number

Template Parameters
InputItstandard iterator type of first and last.
OutputItstandard output iterator type used for the outliers output KDEXOut and KDEYOut, use e.g. std::back_inserter
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 $
kernelthe kernel function to use (e.g. jkqtpstatKernel1DGaussian() )
bandwidthbandwidth used for the KDE
[out]KDEXOutoutput iterator that receives x-positions of the KDE bins. Location of this value inside the bin range is defined by binXMode
[out]KDEYOutoutput iterator that receives counts/frequencies of the KDE bins
Noutnumber datapoints in the output KDE
cummulativeif true, a cummulative KDE is calculated

This function performs Kernel Density Estimation for a given data array. Then the resulting density is evaluated on a regular grid spanning [min(X)...max(X)] with bins datapoints in between.

Warning
this functions is getting very slow for large dataset, as for each point in the resulting histogram N kernel functions have to be evaluated.
See also
https://en.wikipedia.org/wiki/Kernel_density_estimation, Tutorial (JKQTPDatastore): Advanced 1-Dimensional Statistics with JKQTPDatastore