mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2025-01-12 08:50:31 +08:00
bugfixed auto-ranged KDE to include the minimum and maximum value in the output
This commit is contained in:
parent
c8395f2ada
commit
56d59b1760
@ -239,11 +239,15 @@ inline void jkqtpstatKDE1DAutoranged(InputIt first, InputIt last, OutputIt KDEXO
|
|||||||
const double binw=range/static_cast<double>(Nout);
|
const double binw=range/static_cast<double>(Nout);
|
||||||
|
|
||||||
// calculate the KDE
|
// calculate the KDE
|
||||||
for (int i=0; i<Nout; i++) {
|
for (double xi=minV; xi<=maxV; xi+=binw) {
|
||||||
const double x=minV+static_cast<double>(i)*binw+binw/2.0;
|
histX.push_back(xi);
|
||||||
histX.push_back(x);
|
histY.push_back(jkqtpstatEvaluateKernelSum(xi, first, last, kernel, bandwidth));
|
||||||
histY.push_back(jkqtpstatEvaluateKernelSum(x, first, last, kernel, bandwidth));
|
|
||||||
}
|
}
|
||||||
|
if (histX.size()>0 && histX[histX.size()-1]<maxV) {
|
||||||
|
histX.push_back(maxV);
|
||||||
|
histY.push_back(jkqtpstatEvaluateKernelSum(maxV, first, last, kernel, bandwidth));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// output the KDE
|
// output the KDE
|
||||||
@ -287,16 +291,17 @@ inline void jkqtpstatKDE1DAutoranged(InputIt first, InputIt last, OutputIt KDEXO
|
|||||||
std::vector<double> histX;
|
std::vector<double> histX;
|
||||||
std::vector<double> histY;
|
std::vector<double> histY;
|
||||||
|
|
||||||
const double range=maxV-minV;
|
|
||||||
const double binw=binWidth;
|
const double binw=binWidth;
|
||||||
const int Nout=static_cast<int>(ceil(range/binWidth));
|
|
||||||
|
|
||||||
// calculate the KDE
|
// calculate the KDE
|
||||||
for (int i=0; i<Nout; i++) {
|
for (double xi=minV; xi<=maxV; xi+=binw) {
|
||||||
const double xi=minV+static_cast<double>(i)*binw+binw/2.0;
|
|
||||||
histX.push_back(xi);
|
histX.push_back(xi);
|
||||||
histY.push_back(jkqtpstatEvaluateKernelSum(xi, first, last, kernel, bandwidth));
|
histY.push_back(jkqtpstatEvaluateKernelSum(xi, first, last, kernel, bandwidth));
|
||||||
}
|
}
|
||||||
|
if (histX.size()>0 && histX[histX.size()-1]<maxV) {
|
||||||
|
histX.push_back(maxV);
|
||||||
|
histY.push_back(jkqtpstatEvaluateKernelSum(maxV, first, last, kernel, bandwidth));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// output the KDE
|
// output the KDE
|
||||||
|
Loading…
Reference in New Issue
Block a user