1package umontreal.ssj.stat.density;
3import umontreal.ssj.probdist.ContinuousDistribution;
45 private double eps = 1.0E-10;
163 this.kernel = kernel;
202 double invh = 1.0 / h;
203 double invhn = invh / (double) n;
210 term = kernel.density((x -
data[imin]) * invh);
211 while ((term < eps) && (imin < n - 1) && (
data[imin] < x))
212 term = kernel.density((x -
data[++imin]) * invh);
214 for (
int i = imin + 1; (i < n) && ((term > eps) || (
data[i] < x)); i++)
217 sum += (term = kernel.density((x -
data[i]) * invh));
240 int k = evalPoints.length;
241 double[]
density =
new double[k];
243 double invh = 1.0 / h;
244 double invhn = invh / (double) n;
251 for (
int j = 0; j < k; j++) {
253 term = kernel.density((y -
data[imin]) * invh);
254 while ((term < eps) && (imin < n - 1) && (
data[imin] < y))
255 term = kernel.density((y -
data[++imin]) * invh);
257 for (
int i = imin + 1; (i < n) && ((term > eps) || (
data[i] < y)); i++)
259 sum += (term = kernel.density((y -
data[i]) * invh));
271 String str =
"KDE [h = " + h +
", Kernel: " + kernel.toString() +
"]";
295 double invh = 1.0 / h;
296 double invhn = invh / (double) n;
303 term = kernel.density((x -
data[imin]) * invh);
304 while ((term < eps) && (imin < n - 1) && (
data[imin] < x))
305 term = kernel.density((x -
data[++imin]) * invh);
309 for (
int i = imin + 1; (i < n) && ((term > eps) || (
data[i] < x)); i++)
312 sum += (term = kernel.density((x -
data[i]) * invh));
341 int k = evalPoints.length;
342 double[]
density =
new double[k];
344 double invh = 1.0 / h;
345 double invhn = invh / (double) n;
352 for (
int j = 0; j < k; j++) {
354 term = kernel.density((y -
data[imin]) * invh);
355 while ((term < eps) && (imin < n - 1) && (
data[imin] < y))
356 term = kernel.density((y -
data[++imin]) * invh);
358 for (
int i = imin + 1; (i < n) && ((term > eps) || (
data[i] < y)); i++)
360 sum += (term = kernel.density((y -
data[i]) * invh));
397 int k = evalPoints.length;
398 double[][]
density =
new double[m][k];
399 for (
int rep = 0; rep < m; rep++)
Classes implementing continuous distributions should inherit from this base class.
static double[][] evalDensity(double[] evalPoints, ContinuousDistribution kernel, double h, double[][] data, double eps)
Assume that we have independent realizations of the underlying model.
void setKernel(ContinuousDistribution kernel)
Sets the kernel density function to kernel.
DEKernelDensity(ContinuousDistribution kernel)
Constructs a KDE with the kernel function kernel.
DEKernelDensity(double h)
Constructs a KDE with bandwidth .
DEKernelDensity(ContinuousDistribution kernel, double h)
Constructs a KDE with the kernel function kernel and bandwidth h.
double getEps()
Gives the threshold-level for the evaluation of the density.
DEKernelDensity(ContinuousDistribution kernel, double h, double[] data)
Constructs a KDE with the kernel function kernel and bandwidth h from the observations data.
void setH(double h)
Sets the bandwidth to h.
static double evalDensity(double x, ContinuousDistribution kernel, double h, double[] data, double eps)
Evaluates the KDE with kernel density functionkernel, bandwidth h which is defined by the observation...
void setEps(double eps)
Sets the threshold-level for the evaluation of the density to eps.
double getH()
Gives the bandwidth .
DEKernelDensity(double[] data)
Constructs a KDE from the observations data.
String toString()
Gives a short description of the estimator.a short description.
void setData(double[] data)
Sets a new set of observations.
double evalDensity(double x)
Evaluates the KDE at the evaluation point x.
double[] evalDensity(double[] evalPoints)
Evaluates the KDE at each of the evaluation points evalPoints and returns the results in an array.
DEKernelDensity(double h, double[] data)
Constructs a KDE with bandwidth h from the observations data.
DEKernelDensity(ContinuousDistribution kernel, double[] data)
Constructs a KDE with the kernel function kernel from the observations in data.
static double[] evalDensity(double[] evalPoints, ContinuousDistribution kernel, double h, double[] data, double eps)
Evaluates the KDE with kernel density functionkernel, bandwidth h which is defined by the observation...
ContinuousDistribution getKernel()
Gives the kernel density function .
This abstract class represents a univariate density estimator (DE).
double[] data
The data associated with this DensityEstimator object, if any.
Tools for univariate density estimation.