SSJ  3.3.1
Stochastic Simulation in Java
Public Member Functions | Static Public Member Functions | List of all members
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 DEKernelDensity:
[legend]
Collaboration diagram for DEKernelDensity:
[legend]

Public Member Functions

 DEKernelDensity (double[] data)
 Constructs a KDE from the observations data. More...
 
 DEKernelDensity (ContinuousDistribution kernel)
 Constructs a KDE with the kernel function kernel. More...
 
 DEKernelDensity (ContinuousDistribution kernel, double[] data)
 Constructs a KDE with the kernel function kernel from the observations in data. More...
 
 DEKernelDensity (double h)
 Constructs a KDE with bandwidth \(h\). More...
 
 DEKernelDensity (double h, double[] data)
 Constructs a KDE with bandwidth h from the observations data. More...
 
 DEKernelDensity (ContinuousDistribution kernel, double h)
 Constructs a KDE with the kernel function kernel and bandwidth h. More...
 
 DEKernelDensity (ContinuousDistribution kernel, double h, double[] data)
 Constructs a KDE with the kernel function kernel and bandwidth h from the observations data. More...
 
void setData (double[] data)
 Sets a new set of observations. More...
 
void setH (double h)
 Sets the bandwidth to h. More...
 
double getH ()
 Gives the bandwidth \(h\). More...
 
ContinuousDistribution getKernel ()
 Gives the kernel density function \(K\). More...
 
void setKernel (ContinuousDistribution kernel)
 Sets the kernel density function to kernel. More...
 
double getEps ()
 Gives the threshold-level \(\varepsilon\) for the evaluation of the density. More...
 
void setEps (double eps)
 Sets the threshold-level \(\varepsilon\) for the evaluation of the density to eps. More...
 
double evalDensity (double x)
 Evaluates the KDE at the evaluation point x. More...
 
double [] evalDensity (double[] evalPoints)
 Evaluates the KDE at each of the evaluation points evalPoints and returns the results in an array. More...
 
String toString ()
 
- Public Member Functions inherited from DensityEstimator
abstract void setData (double[] data)
 Sets the observations for the density estimator do data. More...
 
double [] getData ()
 Gives the observations for this density estimator, if any. More...
 
abstract double evalDensity (double x)
 Evaluates the density estimator at x. More...
 
double [] evalDensity (double[] evalPoints)
 Evaluates the density estimator at the points in evalPoints. More...
 
double [] evalDensity (double[] evalPoints, double[] data)
 Sets the observations for the density estimator to data and evaluates the density at each point in evalPoints. More...
 
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. More...
 
abstract String toString ()
 Gives a short description of the estimator. More...
 

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. More...
 
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. More...
 
static double [][] evalDensity (double[] evalPoints, ContinuousDistribution kernel, double h, double[][] data, double eps)
 Assume that we have \(m\) independent realizations of the underlying model. More...
 
- Static Public Member Functions inherited from 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. More...
 
static double [] computeVariance (double[][] density)
 This method computes the empirical variance based on the values given in data. More...
 
static double computeIV (double[][] density, double a, double b, double[] variance)
 This method estimates the empirical IV over the interval \([a,b]\). More...
 
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. More...
 
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]\). More...
 
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. More...
 
static String plotDensity (double[] evalPoints, double[] density, String plotTitle, String[] axisTitles)
 Gives a plot of the estimated density. More...
 
static double roughnessFunctional (double[] density, double a, double b)
 Estimates the roughness functional. More...
 

Additional Inherited Members

- Protected Attributes inherited from 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.

Constructor & Destructor Documentation

◆ DEKernelDensity() [1/7]

DEKernelDensity ( double []  data)

Constructs a KDE from the observations data.

Parameters
datathe observations.

◆ DEKernelDensity() [2/7]

Constructs a KDE with the kernel function kernel.

Parameters
kernelthe kernel density function.

◆ DEKernelDensity() [3/7]

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.

◆ DEKernelDensity() [4/7]

DEKernelDensity ( double  h)

Constructs a KDE with bandwidth \(h\).

Parameters
hthe bandwidth.

◆ DEKernelDensity() [5/7]

DEKernelDensity ( double  h,
double []  data 
)

Constructs a KDE with bandwidth h from the observations data.

Parameters
hthe bandwidth
datathe observations

◆ DEKernelDensity() [6/7]

DEKernelDensity ( ContinuousDistribution  kernel,
double  h 
)

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

Parameters
kernelthe kernel density function
hthe bandwidth

◆ DEKernelDensity() [7/7]

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

Member Function Documentation

◆ evalDensity() [1/5]

double 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.

◆ evalDensity() [2/5]

double [] 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.

◆ evalDensity() [3/5]

static double 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.

◆ evalDensity() [4/5]

static double [] 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.

◆ evalDensity() [5/5]

static double [][] 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.

◆ getEps()

double 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.

◆ getH()

double getH ( )

Gives the bandwidth \(h\).

Returns
the bandwidth.

◆ getKernel()

ContinuousDistribution getKernel ( )

Gives the kernel density function \(K\).

Returns
the kernel density function.

◆ setData()

void setData ( double []  data)

Sets a new set of observations.

Parameters
datathe desired observations.

◆ setEps()

void 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.

◆ setH()

void setH ( double  h)

Sets the bandwidth to h.

Parameters
hthe desired bandwidth.

◆ setKernel()

void setKernel ( ContinuousDistribution  kernel)

Sets the kernel density function to kernel.

Parameters
kernelthe kernel density function to be used.

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