SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.stat.density.DEKernelDensity Class Reference

This class provides methods to construct a kernel density estimator (KDE) for univariate densities from a set of \(n\) individual observations \(x_0,\dots, x_{n-1}\), and to evaluate it at a single point or at a set of selected evaluation points. More...

Inheritance diagram for umontreal.ssj.stat.density.DEKernelDensity:
umontreal.ssj.stat.density.DensityEstimator

Public Member Functions

 DEKernelDensity (double[] data)
 Constructs a KDE from the observations data.
 DEKernelDensity (ContinuousDistribution kernel)
 Constructs a KDE with the kernel function kernel.
 DEKernelDensity (ContinuousDistribution kernel, double[] data)
 Constructs a KDE with the kernel function kernel from the observations in data.
 DEKernelDensity (double h)
 Constructs a KDE with bandwidth \(h\).
 DEKernelDensity (double h, double[] data)
 Constructs a KDE with bandwidth h from the observations data.
 DEKernelDensity (ContinuousDistribution kernel, double h)
 Constructs a KDE with the kernel function kernel and bandwidth h.
 DEKernelDensity (ContinuousDistribution kernel, double h, double[] data)
 Constructs a KDE with the kernel function kernel and bandwidth h from the observations data.
void setData (double[] data)
 Sets a new set of observations.
void setH (double h)
 Sets the bandwidth to h.
double getH ()
 Gives the bandwidth \(h\).
ContinuousDistribution getKernel ()
 Gives the kernel density function \(K\).
void setKernel (ContinuousDistribution kernel)
 Sets the kernel density function to kernel.
double getEps ()
 Gives the threshold-level \(\varepsilon\) for the evaluation of the density.
void setEps (double eps)
 Sets the threshold-level \(\varepsilon\) for the evaluation of the density to eps.
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.
String toString ()
 Gives a short description of the estimator.
Returns
a short description.

Public Member Functions inherited from umontreal.ssj.stat.density.DensityEstimator
double[] getData ()
 Gives the observations for this density estimator, if any.
double[] evalDensity (double[] evalPoints, double[] data)
 Sets the observations for the density estimator to data and evaluates the density at each point in evalPoints.
double[][] evalDensity (double[] evalPoints, double[][] data)
 This method is particularly designed to evaluate the density estimator in such a way that the result can be easily used to estimate the empirical IV and other convergence-related quantities.

Static Public Member Functions

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 observations data at the evaluation point x.
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 observations data at each of the evaluation points evalPoints and returns the results in an array.
static double[][] evalDensity (double[] evalPoints, ContinuousDistribution kernel, double h, double[][] data, double eps)
 Assume that we have \(m\) independent realizations of the underlying model.
Static Public Member Functions inherited from umontreal.ssj.stat.density.DensityEstimator
static void evalDensity (ArrayList< DensityEstimator > listDE, double[] evalPoints, double[][] data, ArrayList< double[][]> listDensity)
 This function is particularly designed for experiments with many different types of density estimators, as it evaluates all of these estimators at the points in evalPoints.
static double[] computeVariance (double[][] density)
 This method computes the empirical variance based on the values given in data.
static double computeIV (double[][] density, double a, double b, double[] variance)
 This method estimates the empirical IV over the interval \([a,b]\).
static void computeIV (ArrayList< double[][]> listDensity, double a, double b, ArrayList< Double > listIV)
 This method estimates the empirical IV over the interval \([a,b]\) for a collection of different estimators.
static double[] computeMISE (ContinuousDistribution dist, double[] evalPoints, double[][] density, double a, double b, double[] variance, double[] sqBias, double[] mse)
 In situations where the true density is known this method can estimate the empirical MISE over the interval \([a,b]\).
static void computeMISE (ContinuousDistribution dist, double[] evalPoints, ArrayList< double[][]> listDensity, double a, double b, ArrayList< double[]> listMISE)
 This method estimates the empirical MISE over the interval \([a,b]\) for a collection of different estimators.
static String plotDensity (double[] evalPoints, double[] density, String plotTitle, String[] axisTitles)
 Gives a plot of the estimated density.
static double roughnessFunctional (double[] density, double a, double b)
 Estimates the roughness functional.

Additional Inherited Members

Protected Attributes inherited from umontreal.ssj.stat.density.DensityEstimator
double[] data
 The data associated with this DensityEstimator object, if any.

Detailed Description

This class provides methods to construct a kernel density estimator (KDE) for univariate densities from a set of \(n\) individual observations \(x_0,\dots, x_{n-1}\), and to evaluate it at a single point or at a set of selected evaluation points.

The observations can be collected data or realizations of a umontreal.ssj.mcqmctools.MonteCarloModelDouble, for instance.

The KDE takes a fixed bandwidth \( h>0\) as well as a kernel function \(k\), which is also referred to as kernel density. The kernel density should be non-negative and integrate to one. For \(x\in[a,b]\), the KDE itself is defined as

\[ \hat{f}_{n}(x) = \hat{f}_{n,h}(x) = \frac{1}{nh} \sum_{i = 0}^{n-1} k\left( \frac{x - x_i}{h} \right). \tag{KDE} \]

This class also offers static methods so that the user can simply evaluate the density based on a set of observations without having to construct a KDE.

Definition at line 28 of file DEKernelDensity.java.

Constructor & Destructor Documentation

◆ DEKernelDensity() [1/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( double[] data)

Constructs a KDE from the observations data.

Parameters
datathe observations.

Definition at line 52 of file DEKernelDensity.java.

◆ DEKernelDensity() [2/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( ContinuousDistribution kernel)

Constructs a KDE with the kernel function kernel.

Parameters
kernelthe kernel density function.

Definition at line 61 of file DEKernelDensity.java.

◆ DEKernelDensity() [3/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( ContinuousDistribution kernel,
double[] data )

Constructs a KDE with the kernel function kernel from the observations in data.

Parameters
kernelthe kernel density function.
datathe observations.

Definition at line 72 of file DEKernelDensity.java.

◆ DEKernelDensity() [4/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( double h)

Constructs a KDE with bandwidth \(h\).

Parameters
hthe bandwidth.

Definition at line 82 of file DEKernelDensity.java.

◆ DEKernelDensity() [5/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( double h,
double[] data )

Constructs a KDE with bandwidth h from the observations data.

Parameters
hthe bandwidth
datathe observations

Definition at line 92 of file DEKernelDensity.java.

◆ DEKernelDensity() [6/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( ContinuousDistribution kernel,
double h )

Constructs a KDE with the kernel function kernel and bandwidth h.

Parameters
kernelthe kernel density function
hthe bandwidth

Definition at line 103 of file DEKernelDensity.java.

◆ DEKernelDensity() [7/7]

umontreal.ssj.stat.density.DEKernelDensity.DEKernelDensity ( ContinuousDistribution kernel,
double h,
double[] data )

Constructs a KDE with the kernel function kernel and bandwidth h from the observations data.

Parameters
kernelthe kernel density function
hthe bandwidth
datathe observations

Definition at line 116 of file DEKernelDensity.java.

Member Function Documentation

◆ evalDensity() [1/5]

double umontreal.ssj.stat.density.DEKernelDensity.evalDensity ( double x)

Evaluates the KDE at the evaluation point x.

Each summand w.r.t. \(i\) in ( KDE ) is only considered if it is larger than \(\varepsilon\) . For this method the kernel function \(K\) is assumed to be unimodal, i.e. increasing and then decreasing.

Parameters
xthe evaluation point.
Returns
the value of the KDE at x.

Reimplemented from umontreal.ssj.stat.density.DensityEstimator.

Definition at line 199 of file DEKernelDensity.java.

◆ evalDensity() [2/5]

double umontreal.ssj.stat.density.DEKernelDensity.evalDensity ( double x,
ContinuousDistribution kernel,
double h,
double[] data,
double eps )
static

Evaluates the KDE with kernel density functionkernel, bandwidth h which is defined by the observations data at the evaluation point x.

Each summand w.r.t. \(i\) in ( KDE ) is only considered if it is larger than eps . For this method the kernel function \(K\) is assumed to be unimodal, i.e. increasing and then decreasing.

Parameters
xthe evaluation point.
kernelthe kernel density function.
hthe bandwidth.
datathe observations.
epsthe threshold level.
Returns
the KDE defined by the above parameters evaluated at x.

Definition at line 292 of file DEKernelDensity.java.

◆ evalDensity() [3/5]

double[] umontreal.ssj.stat.density.DEKernelDensity.evalDensity ( double[] evalPoints)

Evaluates the KDE at each of the evaluation points evalPoints and returns the results in an array.

Each summand w.r.t. \(i\) in ( KDE ) is only considered if it is larger than \(\varepsilon\) .

For this method the kernel function \(K\) is assumed to be unimodal, i.e. increasing and then decreasing, and that the points in evalPoints are sorted in increasing order. This allows this method to avoid looping over all \(i\) for each evaluation point by remembering that some summands have already been deemed too small.

Parameters
evalPointsthe evaluation points.
Returns
the value of the KDE at evalPoints.

Reimplemented from umontreal.ssj.stat.density.DensityEstimator.

Definition at line 239 of file DEKernelDensity.java.

◆ evalDensity() [4/5]

double[] umontreal.ssj.stat.density.DEKernelDensity.evalDensity ( double[] evalPoints,
ContinuousDistribution kernel,
double h,
double[] data,
double eps )
static

Evaluates the KDE with kernel density functionkernel, bandwidth h which is defined by the observations data at each of the evaluation points evalPoints and returns the results in an array.

Each summand w.r.t. \(i\) in ( KDE ) is only considered if it is larger than \(\varepsilon\) .

For this method the kernel function \(K\) is assumed to be unimodal, i.e. increasing and then decreasing, and that the points in evalPoints are sorted in increasing order. This allows this method to avoid looping over all \(i\) for each evaluation point by remembering that some summands have already been deemed too small.

Parameters
evalPointsthe evaluation points.
kernelthe kernel density function.
hthe bandwidth.
datathe observations.
epsthe threshold level.
Returns
the KDE defined by the above parameters evaluated at the evaluation points evalPoints.

Definition at line 339 of file DEKernelDensity.java.

◆ evalDensity() [5/5]

double[][] umontreal.ssj.stat.density.DEKernelDensity.evalDensity ( double[] evalPoints,
ContinuousDistribution kernel,
double h,
double data[][],
double eps )
static

Assume that we have \(m\) independent realizations of the underlying model.

For each such realization this method evaluates a KDE with kernel density functionkernel, bandwidth h at the points from evalPoints. The independent realizations are passed via the 2-dimensional \(m\times n\) array data, where \(n\) denotes the number of observations per realization. Hence, its first index identifies the independent realization while its second index identifies a specific observation of this realization.

The result is returned as a \(m\times k\) matrix, where \(k \) is the number of evaluation points, i.e., the length of evalPoints. The first index, again, identifies the independent realization whereas the second index corresponds to the point of evalPoints at which the KDE was evaluated.

For this method the kernel function \(K\) is assumed to be unimodal, i.e. increasing and then decreasing, and that the points in evalPoints are sorted in increasing order. For a specific observation, this allows this method to avoid looping over all \(i\) for each evaluation point by remembering that some summands have already been deemed too small.

Parameters
evalPointsthe evaluation points.
kernelthe kernel density function.
hthe bandwidth.
datathe two-dimensional array of observations.
epsthe threshold level.
Returns
the KDE for each realization evaluated at evalPoints.

Definition at line 394 of file DEKernelDensity.java.

◆ getEps()

double umontreal.ssj.stat.density.DEKernelDensity.getEps ( )

Gives the threshold-level \(\varepsilon\) for the evaluation of the density.

Summands w.r.t. \(i\) in ( KDE ) smaller than this value are considered negligible.

Returns
the threshold-level for evaluation.

Definition at line 174 of file DEKernelDensity.java.

◆ getH()

double umontreal.ssj.stat.density.DEKernelDensity.getH ( )

Gives the bandwidth \(h\).

Returns
the bandwidth.

Definition at line 144 of file DEKernelDensity.java.

◆ getKernel()

ContinuousDistribution umontreal.ssj.stat.density.DEKernelDensity.getKernel ( )

Gives the kernel density function \(K\).

Returns
the kernel density function.

Definition at line 153 of file DEKernelDensity.java.

◆ setData()

void umontreal.ssj.stat.density.DEKernelDensity.setData ( double[] data)

Sets a new set of observations.

Parameters
datathe desired observations.

Reimplemented from umontreal.ssj.stat.density.DensityEstimator.

Definition at line 126 of file DEKernelDensity.java.

◆ setEps()

void umontreal.ssj.stat.density.DEKernelDensity.setEps ( double eps)

Sets the threshold-level \(\varepsilon\) for the evaluation of the density to eps.

Summands w.r.t. \(i\) in ( KDE ) smaller than this value are considered negligible.

Parameters
epsthe threshold-level for evaluation.

Definition at line 186 of file DEKernelDensity.java.

◆ setH()

void umontreal.ssj.stat.density.DEKernelDensity.setH ( double h)

Sets the bandwidth to h.

Parameters
hthe desired bandwidth.

Definition at line 135 of file DEKernelDensity.java.

◆ setKernel()

void umontreal.ssj.stat.density.DEKernelDensity.setKernel ( ContinuousDistribution kernel)

Sets the kernel density function to kernel.

Parameters
kernelthe kernel density function to be used.

Definition at line 162 of file DEKernelDensity.java.

◆ toString()

String umontreal.ssj.stat.density.DEKernelDensity.toString ( )

Gives a short description of the estimator.

Returns
a short description.

Reimplemented from umontreal.ssj.stat.density.DensityEstimator.

Definition at line 270 of file DEKernelDensity.java.


The documentation for this class was generated from the following file: