SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.randvar.KernelDensityGen Class Reference

This class implements random variate generators for distributions obtained via kernel density estimation methods from a set of \(n\) individual observations \(x_1,…,x_n\) [44], [45], [85],. More...

Inheritance diagram for umontreal.ssj.randvar.KernelDensityGen:
umontreal.ssj.randvar.RandomVariateGen umontreal.ssj.randvar.KernelDensityVarCorrectGen

Public Member Functions

 KernelDensityGen (RandomStream s, EmpiricalDist dist, RandomVariateGen kGen, double h)
 Creates a new generator for a kernel density estimated from the observations given by the empirical distribution dist, using stream s to select the observations, generator kGen to generate the added noise from the kernel density, and bandwidth h.
 KernelDensityGen (RandomStream s, EmpiricalDist dist, NormalGen kGen)
 This constructor uses a gaussian kernel and the default bandwidth.
Public Member Functions inherited from umontreal.ssj.randvar.RandomVariateGen
 RandomVariateGen (RandomStream s, Distribution dist)
 Creates a new random variate generator from the distribution dist, using stream s.
void nextArrayOfDouble (double[] v, int start, int n)
 Generates n random numbers from the continuous distribution contained in this object.
double[] nextArrayOfDouble (int n)
 Generates n random numbers from the continuous distribution contained in this object, and returns them in a new array of size n.
RandomStream getStream ()
 Returns the umontreal.ssj.rng.RandomStream used by this generator.
void setStream (RandomStream stream)
 Sets the umontreal.ssj.rng.RandomStream used by this generator to stream.
Distribution getDistribution ()
 Returns the umontreal.ssj.probdist.Distribution used by this generator.
String toString ()
 Returns a String containing information about the current generator.

Kernel selection and parameters @{

void setBandwidth (double h)
 Sets the bandwidth to h.
void setPositiveReflection (boolean reflect)
 After this method is called with true, the generator will produce only positive values, by using the reflection method: replace all negative values by their absolute values.
double nextDouble ()
 Generates a random number from the continuous distribution contained in this object.
static double getBaseBandwidth (EmpiricalDist dist)
 Computes and returns the value of \(h_0\) in ( bandwidth0 ).

Detailed Description

This class implements random variate generators for distributions obtained via kernel density estimation methods from a set of \(n\) individual observations \(x_1,…,x_n\) [44], [45], [85],.

[86], [207] . The basic idea is to center a copy of the same symmetric density at each observation and take an equally weighted mixture of the \(n\) copies as an estimator of the density from which the observations come. The resulting kernel density has the general form

\[ f_n(x) = \frac{1}{nh} \sum_{i=1}^n k((x-x_i)/h), \]

where \(k\) is a fixed pre-selected density called the kernel and \(h\) is a positive constant called the bandwidth or smoothing factor. A difficult practical issue is the selection of \(k\) and \(h\). Several approaches have been proposed for that; see, e.g., [15], [31], [86], [207] .

  The constructor of a generator from a kernel density requires a random
  stream @f$s@f$, the @f$n@f$ observations in the form of an empirical
  distribution, a random variate generator for the kernel
  density @f$k@f$, and the value of the bandwidth @f$h@f$. The random
  variates are then generated as follows: select an observation @f$x_I@f$
  at random, by inversion, using stream @f$s@f$, then generate random
  variate @f$Y@f$ with the generator provided for the density @f$k@f$,
  and return @f$x_I + hY@f$.

  A simple formula for the bandwidth, suggested in @cite tSIL86a,

[86] , is \(h = \alpha_k h_0\), where

\[ h_0 = 1.36374 \min(s_n, q / 1.34) n^{-1/5}, \tag{bandwidth0} \]

\(s_n\) and \(q\) are the empirical standard deviation and the interquartile range of the \(n\) observations, and \(\alpha_k\) is a constant that depends on the type of kernel \(k\). It is defined by

\[ \alpha_k = \left(\sigma_k^{-4} \int_{-\infty}^{\infty}k(x)dx \right)^{1/5} \]

where \(\sigma_k\) is the standard deviation of the density \(k\). The static method getBaseBandwidth permits one to compute \(h_0\) for a given empirical distribution.

Some suggested kernels

nameconstructor\(\alpha_k\)\(\sigma_k^2\)efficiency
EpanechnikovBetaSymmetricalDist(2, -1, 1)1.71881/51.000
triangularTriangularDist(-1, 1, 0)1.88821/60.986
GaussianNormalDist()0.776410.951
boxcarUniformDist(-1, 1)1.35101/30.930
logisticLogisticDist()0.43403.28990.888
Student-t(3)StudentDist(3)0.480230.674

Table  kernels gives the precomputed values of \(\sigma_k\) and \(\alpha_k\) for selected (popular) kernels. The values are taken from [86] . The second column gives the name of a function (in this package) that constructs the corresponding distribution. The efficiency of a kernel is defined as the ratio of its mean integrated square error over that of the Epanechnikov kernel, which has optimal efficiency and corresponds to the beta distribution with parameters \((2,2)\) over the interval \((-1,1)\).

        <div class="SSJ-bigskip"></div>

Definition at line 139 of file KernelDensityGen.java.

Constructor & Destructor Documentation

◆ KernelDensityGen() [1/2]

umontreal.ssj.randvar.KernelDensityGen.KernelDensityGen ( RandomStream s,
EmpiricalDist dist,
RandomVariateGen kGen,
double h )

Creates a new generator for a kernel density estimated from the observations given by the empirical distribution dist, using stream s to select the observations, generator kGen to generate the added noise from the kernel density, and bandwidth h.

Definition at line 151 of file KernelDensityGen.java.

◆ KernelDensityGen() [2/2]

umontreal.ssj.randvar.KernelDensityGen.KernelDensityGen ( RandomStream s,
EmpiricalDist dist,
NormalGen kGen )

This constructor uses a gaussian kernel and the default bandwidth.

\(h = \alpha_k h_0\) with the \(\alpha_k\) suggested in Table  kernels for the gaussian distribution. This kernel has an efficiency of 0.951.

Definition at line 168 of file KernelDensityGen.java.

Member Function Documentation

◆ getBaseBandwidth()

double umontreal.ssj.randvar.KernelDensityGen.getBaseBandwidth ( EmpiricalDist dist)
static

Computes and returns the value of \(h_0\) in ( bandwidth0 ).

Definition at line 180 of file KernelDensityGen.java.

◆ nextDouble()

double umontreal.ssj.randvar.KernelDensityGen.nextDouble ( )

Generates a random number from the continuous distribution contained in this object.

By default, this method uses inversion by calling the umontreal.ssj.probdist.ContinuousDistribution.inverseF method of the distribution object. Alternative generating methods are provided in subclasses.

Returns
the generated value

Reimplemented from umontreal.ssj.randvar.RandomVariateGen.

Reimplemented in umontreal.ssj.randvar.KernelDensityVarCorrectGen.

Definition at line 208 of file KernelDensityGen.java.

◆ setBandwidth()

void umontreal.ssj.randvar.KernelDensityGen.setBandwidth ( double h)

Sets the bandwidth to h.

Reimplemented in umontreal.ssj.randvar.KernelDensityVarCorrectGen.

Definition at line 191 of file KernelDensityGen.java.

◆ setPositiveReflection()

void umontreal.ssj.randvar.KernelDensityGen.setPositiveReflection ( boolean reflect)

After this method is called with true, the generator will produce only positive values, by using the reflection method: replace all negative values by their absolute values.

That is, nextDouble will return \(|x|\) if \(x\) is the generated variate. The mecanism is disabled when the method is called with false.

Definition at line 204 of file KernelDensityGen.java.


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