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

Histogram density estimator for a univariate density. More...

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

Public Member Functions

 DEHistogram (double a, double b, int numBins)
 Constructs a histogram estimator over the interval \([a,b]\) with numBins number of bins.
 DEHistogram (double[] data, double a, double b, int numBins)
 Constructs a histogram over the interval \([a,b]\) with numBins number of bins from the observations passed in data.
 DEHistogram (TallyHistogram tallyHist)
 Constructs a histogram from a umontreal.ssj.stat.TallyHistogram tallyHist.
 DEHistogram (ScaledHistogram scaledHist)
 Constructs a histogram from a umontreal.ssj.stat.ScaledHistogram scaledHist.
void setData (double[] data)
 Takes the observations in data and constructs and redefines the histogram with these observations.
ScaledHistogram getScaledHistogram ()
 Returns the underlying ScaledHistogram.
int getNumBins ()
 Gives the number of bins \(s\).
double getH ()
 Gives the bin width \(h\).
double getA ()
 Gives the left boundary \(a\) of the histogram.
double getB ()
 Gives the right boundary \(b\) of the histogram.
String toString ()
 Gives a short description of the estimator.
Returns
a short description.

double evalDensity (double x)
 Evaluates the density estimator at x.
Parameters
xthe evaluation point.
Returns
the density estimator evaluated at \(x\).

double[] evalDensity (double[] evalPoints)
 Evaluates the histogram estimator at the points in evalPoints.
double[] evalDensity ()
 Evaluates the histogram density estimator at one point in each bin.
void setH (double h)
 Sets the number of bins according to the provided binwidth \(h\) via \(\lfloor (b-a)/h \rfloor\).
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, double[] data, double a, double b, int numBins)
 Evaluates the histogram with numBins bins over \([a,b]\) which is defined by the observations data at the evaluation point x.
static double[] evalDensity (double[] evalPoints, double[] data, double a, double b, int numBins)
 Evaluates the histogram with numBins bins over \([a,b]\) 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[] data, double a, double b, int numBins)
 Evaluates the histogram with numBins bins over \([a,b]\) which is defined by the observations data once in each bin and returns the results in an array.
static double[][] evalDensity (double[][] data, double a, double b, int numBins)
 Same as evalDensity(double[], double[][], double, double, int) but here, the density is evaluated once in each bin instead of at a given array of evaluation points.
static double[][] evalDensity (double evalPoints[], double[][] data, double a, double b, int numBins)
 Assume that we have \(m\) independent realizations of the underlying model.
static double evalDensity (double x, TallyHistogram tallyHist)
 Evaluates a histogram estimator defined by tallylist at x.
static double[] evalDensity (double[] evalPoints, TallyHistogram tallyHist)
 Evaluates a histogram estimator defined by tallyHist at the evaluation points evalPoints.
static double[] evalDensity (TallyHistogram tallyHist)
 Evaluates a histogram estimator defined by tallyHist once in each bin.
static double[][] evalDensity (double[] evalPoints, TallyHistogram[] tallyHistArray)
 This method considers a histogram for each of the \(m\) umontreal.ssj.stat.TallyHistogram from tallyHistArray and evaluates it at \(k\) evaluation points evalPoints.
static double[][] evalDensity (TallyHistogram[] tallyHistArray)
 Same as evalDensity(double[], TallyHistogram[]) but this method evaluates each histogram only once in each bin.
static double evalDensity (double x, ScaledHistogram scaledHist)
 Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at x.
static double[] evalDensity (double[] evalPoints, ScaledHistogram scaledHist)
 Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at each evaluation point in evalPoints.
static double[] evalDensity (ScaledHistogram scaledHist)
 Same as evalDensity(double[], ScaledHistogram) but evaluation is done once in each bin.
static double[][] evalDensity (double[] evalPoints, ScaledHistogram[] scaledHistArray)
 This method considers a histogram for each of the \(m\) umontreal.ssj.stat.ScaledHistogram from scaledHistArray and evaluates it at \(k\) evaluation points evalPoints.
static double[][] evalDensity (ScaledHistogram[] scaledHistArray)
 Same as evalDensity(double[], ScaledHistogram[]) but the histograms are evaluated once in each bin.
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

Histogram density estimator for a univariate density.

This class provides methods to construct, manipulate, and evaluate a histogram from a set of \(n\) real-valued observations \(x_0,\dots, x_{n-1}\). The constructor of a DEHistogram object takes the data, a finite interval \([a,b]\) over which we want the histogram, and the number of bins (intervals), and it constructs the histogram as a density estimator over this interval. For that, it computes the number of observations in each bin and rescales the heights of the bins so that the total area of the histogram is equal to the proportion of the observations that fall into the interval \([a,b]\). When all the observations are in \([a,b]\), then this area should be 1. The density estimator is represented internally as a umontreal.ssj.stat.ScaledHistogram, which can be recovered by the getScaledHistogram() method.

More specifically, if we ask for \(s\) bins over the interval \([a,b]\), then the interval is partitioned over \(s\) intervals of equal lengths \(h=(b-a)/s\), and the density estimator is defined by

\[ \hat{f}_{n}(x) = \hat{f}_{n,h}(x) = \frac{n_j}{nh}, \quad\text{ for } x\in[a+(j-1)h, a+jh), \qquad j=1,\dots,s. \]

where \(n_j\) denotes the number of observations that fall in interval \(j\). Observe that changing \([a,b]\), \(h\), or \(s\) changes the structure of the histogram completely. Thus, after altering any of these parameters the histogram needs to be constructed afresh.

The constructor can take as input an array that contains the raw data, together with the parameters \(a, b, s\). It can also take a umontreal.ssj.stat.TallyHistogram or a umontreal.ssj.stat.ScaledHistogram instead.

This class also offers several static methods so that the user can simply evaluate the density based on a set of observations, a TallyHistogram or a ScaledHistogram without having to construct a histogram object.

Since histograms are constant within one bin, it is sometimes sufficient to evaluate them only once per bin. To this end, this class provides methods to evaluate the density estimator once in each bin, without having to explicitly specify an array of evaluation points.

It needs to be added that, due to the fact that the partition into \(s\) bins relies on half-open intervals, the boundary \(b\) is not included in any of these intervals. Since the probability of an observation being exactly equal to \(b\) is zero, we can effectively ignore this subtlety.

This class also offers static methods so that the user can simply evaluate the density based on a set of observations, a umontreal.ssj.stat.TallyHistogram or a umontreal.ssj.stat.ScaledHistogram without having to construct a histogram.

Definition at line 62 of file DEHistogram.java.

Constructor & Destructor Documentation

◆ DEHistogram() [1/4]

umontreal.ssj.stat.density.DEHistogram.DEHistogram ( double a,
double b,
int numBins )

Constructs a histogram estimator over the interval \([a,b]\) with numBins number of bins.

Parameters
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.

Definition at line 75 of file DEHistogram.java.

◆ DEHistogram() [2/4]

umontreal.ssj.stat.density.DEHistogram.DEHistogram ( double[] data,
double a,
double b,
int numBins )

Constructs a histogram over the interval \([a,b]\) with numBins number of bins from the observations passed in data.

Parameters
datathe observations from the underlying model.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.

Definition at line 89 of file DEHistogram.java.

◆ DEHistogram() [3/4]

umontreal.ssj.stat.density.DEHistogram.DEHistogram ( TallyHistogram tallyHist)

Constructs a histogram from a umontreal.ssj.stat.TallyHistogram tallyHist.

Parameters
tallyHista umontreal.ssj.stat.TallyHistogram from which the estimator is constructed.

Definition at line 103 of file DEHistogram.java.

◆ DEHistogram() [4/4]

umontreal.ssj.stat.density.DEHistogram.DEHistogram ( ScaledHistogram scaledHist)

Constructs a histogram from a umontreal.ssj.stat.ScaledHistogram scaledHist.

Parameters
scaledHista umontreal.ssj.stat.ScaledHistogram from which the estimator is constructed.

Definition at line 115 of file DEHistogram.java.

Member Function Documentation

◆ evalDensity() [1/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( )

Evaluates the histogram density estimator at one point in each bin.

Since the histogram is constant within its bins, it is of no concern for this method, which evaluation point is actually selected in each bin.

Returns
the histogram density estimator evaluated at one point in each bin.

Definition at line 221 of file DEHistogram.java.

◆ evalDensity() [2/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double evalPoints[],
double data[][],
double a,
double b,
int numBins )
static

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

For each such realization this method evaluates a histogram with numBins bins over \([a,b]\) once in each bin. 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 histogram was evaluated.

Parameters
evalPointsthe evaluation points.
datathe two-dimensional array of observations.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.
Returns
the histogram for each realization evaluated at evalPoints.

Definition at line 344 of file DEHistogram.java.

◆ evalDensity() [3/18]

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

Evaluates the density estimator at x.

Parameters
xthe evaluation point.
Returns
the density estimator evaluated at \(x\).

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

Definition at line 190 of file DEHistogram.java.

◆ evalDensity() [4/18]

double umontreal.ssj.stat.density.DEHistogram.evalDensity ( double x,
double[] data,
double a,
double b,
int numBins )
static

Evaluates the histogram with numBins bins over \([a,b]\) which is defined by the observations data at the evaluation point x.

Parameters
xthe evaluation point.
datathe observations.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.
Returns
the histogram defined be the above parameters evaluated at x.

Definition at line 253 of file DEHistogram.java.

◆ evalDensity() [5/18]

double umontreal.ssj.stat.density.DEHistogram.evalDensity ( double x,
ScaledHistogram scaledHist )
static

Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at x.

Parameters
xthe evaluation point.
scaledHistthe umontreal.ssj.stat.ScaledHistogram which defines the histogram.
Returns
the histogram density estimator evaluated at x.

Definition at line 453 of file DEHistogram.java.

◆ evalDensity() [6/18]

double umontreal.ssj.stat.density.DEHistogram.evalDensity ( double x,
TallyHistogram tallyHist )
static

Evaluates a histogram estimator defined by tallylist at x.

Parameters
xthe evaluation point.
tallyHistthe umontreal.ssj.stat.TallyHistogram which defines the histogram
Returns
the histogram density estimator evaluated at x.

Definition at line 363 of file DEHistogram.java.

◆ evalDensity() [7/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] data,
double a,
double b,
int numBins )
static

Evaluates the histogram with numBins bins over \([a,b]\) which is defined by the observations data once in each bin and returns the results in an array.

Parameters
datathe observations.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.
Returns
the histogram defined by the above parameters evaluated once in each bin.

Definition at line 291 of file DEHistogram.java.

◆ evalDensity() [8/18]

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

Evaluates the histogram estimator at the points in evalPoints.

Parameters
evalPointsthe evaluation points.
Returns
the histogram density estimator evaluated at the points x.

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

Definition at line 202 of file DEHistogram.java.

◆ evalDensity() [9/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] evalPoints,
double[] data,
double a,
double b,
int numBins )
static

Evaluates the histogram with numBins bins over \([a,b]\) which is defined by the observations data at each of the evaluation points evalPoints and returns the results in an array.

Parameters
evalPointsthe evaluation points.
datathe observations.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.
Returns
the histogram defined by the above parameters evaluated at the points in evalPoints

Definition at line 272 of file DEHistogram.java.

◆ evalDensity() [10/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] evalPoints,
ScaledHistogram scaledHist )
static

Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at each evaluation point in evalPoints.

Parameters
evalPointsthe evaluation points.
scaledHistthe umontreal.ssj.stat.ScaledHistogram which defines the histogram.
Returns
the histogram density estimator evaluated at each point in evalPoints.

Definition at line 468 of file DEHistogram.java.

◆ evalDensity() [11/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] evalPoints,
ScaledHistogram[] scaledHistArray )
static

This method considers a histogram for each of the \(m\) umontreal.ssj.stat.ScaledHistogram from scaledHistArray and evaluates it at \(k\) evaluation points evalPoints.

The result is returned in a \(m\times k\) array.

Parameters
evalPointsthe evaluation points.
scaledHistArraythe array of the umontreal.ssj.stat.ScaledHistogram which define the histograms.
Returns
the histogram for each element of scaledHistArray evaluated at each point of evalPoints.

Definition at line 503 of file DEHistogram.java.

◆ evalDensity() [12/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] evalPoints,
TallyHistogram tallyHist )
static

Evaluates a histogram estimator defined by tallyHist at the evaluation points evalPoints.

Parameters
evalPointsthe evaluation points.
tallyHistthe umontreal.ssj.stat.TallyHistogram which defines the histogram.
Returns
the histogram estimator defined by tallyHist evaluated at each point in evalPoints.

Definition at line 379 of file DEHistogram.java.

◆ evalDensity() [13/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double[] evalPoints,
TallyHistogram[] tallyHistArray )
static

This method considers a histogram for each of the \(m\) umontreal.ssj.stat.TallyHistogram from tallyHistArray and evaluates it at \(k\) evaluation points evalPoints.

The result is returned in a \(m\times k\) array.

Parameters
evalPointsthe evaluation points.
tallyHistArraythe array of the umontreal.ssj.stat.TallyHistogram which define the histograms.
Returns
the histogram for each element of tallyHistArray evaluated at each point of evalPoints.

Definition at line 416 of file DEHistogram.java.

◆ evalDensity() [14/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( double data[][],
double a,
double b,
int numBins )
static

Same as evalDensity(double[], double[][], double, double, int) but here, the density is evaluated once in each bin instead of at a given array of evaluation points.

Parameters
datathe observations.
athe left boundary of the histogram.
bthe right boundary of the histogram.
numBinsthe number of bins.
Returns
the histogram defined by the above parameters evaluated once in each bin.
the histogram for each realization evaluated once in each bin.

Definition at line 310 of file DEHistogram.java.

◆ evalDensity() [15/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( ScaledHistogram scaledHist)
static

Same as evalDensity(double[], ScaledHistogram) but evaluation is done once in each bin.

Parameters
scaledHistumontreal.ssj.stat.ScaledHistogram which defines the histogram.
Returns
the histogram density estimator evaluated at each point in evalPoints.

Definition at line 486 of file DEHistogram.java.

◆ evalDensity() [16/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( ScaledHistogram[] scaledHistArray)
static

Same as evalDensity(double[], ScaledHistogram[]) but the histograms are evaluated once in each bin.

Parameters
scaledHistArraythe array of the umontreal.ssj.stat.ScaledHistogram which define the histograms.
Returns
the histogram for each element of scaledHistArray evaluated once in each bin.

Definition at line 523 of file DEHistogram.java.

◆ evalDensity() [17/18]

double[] umontreal.ssj.stat.density.DEHistogram.evalDensity ( TallyHistogram tallyHist)
static

Evaluates a histogram estimator defined by tallyHist once in each bin.

Parameters
tallyHistthe umontreal.ssj.stat.TallyHistogram which defines the histogram.
Returns
the histogram density estimator defined by tallyHist evaluated once in each bin.

Definition at line 399 of file DEHistogram.java.

◆ evalDensity() [18/18]

double[][] umontreal.ssj.stat.density.DEHistogram.evalDensity ( TallyHistogram[] tallyHistArray)
static

Same as evalDensity(double[], TallyHistogram[]) but this method evaluates each histogram only once in each bin.

Parameters
tallyHistArraythe array of the umontreal.ssj.stat.TallyHistogram which define the histograms.
Returns
the histogram for each element of tallyHistArray evaluated once in each bin.

Definition at line 435 of file DEHistogram.java.

◆ getA()

double umontreal.ssj.stat.density.DEHistogram.getA ( )

Gives the left boundary \(a\) of the histogram.

Returns
the left boundary of the histogram.

Definition at line 165 of file DEHistogram.java.

◆ getB()

double umontreal.ssj.stat.density.DEHistogram.getB ( )

Gives the right boundary \(b\) of the histogram.

Returns
the right boundary of the histogram.

Definition at line 174 of file DEHistogram.java.

◆ getH()

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

Gives the bin width \(h\).

Returns
the bin width.

Definition at line 156 of file DEHistogram.java.

◆ getNumBins()

int umontreal.ssj.stat.density.DEHistogram.getNumBins ( )

Gives the number of bins \(s\).

Returns
the number of bins.

Definition at line 147 of file DEHistogram.java.

◆ getScaledHistogram()

ScaledHistogram umontreal.ssj.stat.density.DEHistogram.getScaledHistogram ( )

Returns the underlying ScaledHistogram.

Returns
underlying ScaledHistogram object.

Definition at line 138 of file DEHistogram.java.

◆ setData()

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

Takes the observations in data and constructs and redefines the histogram with these observations.

Parameters
datathe observations to define the histogram.

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

Definition at line 127 of file DEHistogram.java.

◆ setH()

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

Sets the number of bins according to the provided binwidth \(h\) via \(\lfloor (b-a)/h \rfloor\).

Note that the actual binwidth might differ from the provided \(h\) due to the floor-function.

Parameters
hThe desired binwidth.

Definition at line 232 of file DEHistogram.java.

◆ toString()

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

Gives a short description of the estimator.

Returns
a short description.

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

Definition at line 182 of file DEHistogram.java.


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