SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DEHistogram.java
1package umontreal.ssj.stat.density;
2
3import umontreal.ssj.stat.ScaledHistogram;
4import umontreal.ssj.stat.TallyHistogram;
5
61
62public class DEHistogram extends DensityEstimator {
63
65 private ScaledHistogram histDensity;
66
75 public DEHistogram(double a, double b, int numBins) {
76 histDensity = new ScaledHistogram(a, b, numBins);
77 }
78
89 public DEHistogram(double[] data, double a, double b, int numBins) {
90 // this.data = data;
91 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
92 tallyHist.fillFromArray(data);
93 histDensity = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
94 }
95
103 public DEHistogram(TallyHistogram tallyHist) {
104
105 histDensity = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
106 }
107
115 public DEHistogram(ScaledHistogram scaledHist) {
116 histDensity = scaledHist;
117 }
118
126 @Override
127 public void setData(double[] data) {
128 TallyHistogram tallyHist = new TallyHistogram(histDensity.getA(), histDensity.getB(), histDensity.getNumBins());
129 tallyHist.fillFromArray(data);
130 histDensity = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
131 }
132
139 return histDensity;
140 }
141
147 public int getNumBins() {
148 return histDensity.getNumBins();
149 }
150
156 public double getH() {
157 return (getB() - getA()) / getNumBins();
158 }
159
165 public double getA() {
166 return histDensity.getA();
167 }
168
174 public double getB() {
175 return histDensity.getB();
176 }
177
181 @Override
182 public String toString() {
183 return "Histogram estimator with " + getNumBins() + " bins.";
184 }
185
189 @Override
190 public double evalDensity(double x) {
191 return histDensity.getHeights()[(int) ((x - getA()) / getH())];
192 }
193
201 @Override
202 public double[] evalDensity(double[] evalPoints) {
203 int k = evalPoints.length;
204 double[] density = new double[k];
205
206 for (int j = 0; j < k; j++)
207 density[j] = histDensity.getHeights()[(int) ((evalPoints[j] - getA()) / getH())];
208
209 return density;
210
211 }
212
221 public double[] evalDensity() {
222 return histDensity.getHeights();
223 }
224
232 public void setH(double h) {
233 int numBins = (int) ((getB() - getA()) / h);
234 TallyHistogram tallyHist = new TallyHistogram(histDensity.getA(), histDensity.getB(), numBins);
235 tallyHist.fillFromArray(data);
236 histDensity = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
237
238 }
239
240 // STATIC METHODS
241
253 public static double evalDensity(double x, double[] data, double a, double b, int numBins) {
254 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
255 tallyHist.fillFromArray(data);
256 return evalDensity(x, tallyHist);
257 }
258
272 public static double[] evalDensity(double[] evalPoints, double[] data, double a, double b, int numBins) {
273 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
274 tallyHist.fillFromArray(data);
275 return evalDensity(evalPoints, tallyHist);
276 }
277
290
291 public static double[] evalDensity(double[] data, double a, double b, int numBins) {
292 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
293 tallyHist.fillFromArray(data);
294 return evalDensity(tallyHist);
295 }
296
310 public static double[][] evalDensity(double[][] data, double a, double b, int numBins) {
311 int m = data.length;
312 double[][] dens = new double[m][numBins];
313 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
314 for (int r = 0; r < m; r++) {
315 tallyHist.fillFromArray(data[r]);
316 dens[r] = evalDensity(tallyHist);
317 }
318 return dens;
319 }
320
344 public static double[][] evalDensity(double evalPoints[], double[][] data, double a, double b, int numBins) {
345 int m = data.length;
346 double[][] dens = new double[m][numBins];
347 TallyHistogram tallyHist = new TallyHistogram(a, b, numBins);
348 for (int r = 0; r < m; r++) {
349 tallyHist.fillFromArray(data[r]);
350 dens[r] = evalDensity(evalPoints, tallyHist);
351 }
352 return dens;
353 }
354
363 public static double evalDensity(double x, TallyHistogram tallyHist) {
364 ScaledHistogram hist = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
365 double h = (hist.getB() - hist.getA()) / (double) hist.getNumBins();
366 return hist.getHeights()[(int) ((x - hist.getA()) / h)];
367 }
368
379 public static double[] evalDensity(double[] evalPoints, TallyHistogram tallyHist) {
380
381 ScaledHistogram hist = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
382 int k = evalPoints.length;
383 double[] density = new double[k];
384 double h = (hist.getB() - hist.getA()) / (double) hist.getNumBins();
385 for (int j = 0; j < k; j++) {
386 density[j] = hist.getHeights()[(int) ((evalPoints[j] - hist.getA()) / h)];
387 }
388 return density;
389 }
390
399 public static double[] evalDensity(TallyHistogram tallyHist) {
400 ScaledHistogram hist = new ScaledHistogram(tallyHist, tallyHist.getProportionInBoundaries());
401 return hist.getHeights();
402 }
403
416 public static double[][] evalDensity(double[] evalPoints, TallyHistogram[] tallyHistArray) {
417 int m = tallyHistArray.length;
418 int k = evalPoints.length;
419 double[][] density = new double[m][k];
420 for (int r = 0; r < m; r++)
421 density[r] = evalDensity(evalPoints, tallyHistArray[r]);
422 return density;
423 }
424
435 public static double[][] evalDensity(TallyHistogram[] tallyHistArray) {
436 int m = tallyHistArray.length;
437 double[][] dens = new double[m][];
438 for (int r = 0; r < m; r++)
439 dens[r] = evalDensity(tallyHistArray[r]);
440 return dens;
441 }
442
452
453 public static double evalDensity(double x, ScaledHistogram scaledHist) {
454 double h = (scaledHist.getB() - scaledHist.getA()) / (double) scaledHist.getNumBins();
455 return scaledHist.getHeights()[(int) ((x - scaledHist.getA()) / h)];
456 }
457
468 public static double[] evalDensity(double[] evalPoints, ScaledHistogram scaledHist) {
469 int k = evalPoints.length;
470 double[] density = new double[k];
471 double h = (scaledHist.getB() - scaledHist.getA()) / (double) scaledHist.getNumBins();
472 for (int j = 0; j < k; j++)
473 density[k] = scaledHist.getHeights()[(int) ((evalPoints[j] - scaledHist.getA()) / h)];
474 return density;
475 }
476
486 public static double[] evalDensity(ScaledHistogram scaledHist) {
487 return scaledHist.getHeights();
488 }
489
503 public static double[][] evalDensity(double[] evalPoints, ScaledHistogram[] scaledHistArray) {
504 int m = scaledHistArray.length;
505 double[][] density = new double[m][];
506
507 for (int r = 0; r < m; r++)
508 density[m] = evalDensity(evalPoints, scaledHistArray[r]);
509
510 return density;
511 }
512
523 public static double[][] evalDensity(ScaledHistogram[] scaledHistArray) {
524 int m = scaledHistArray.length;
525 double[][] density = new double[m][];
526 for (int r = 0; r < m; r++)
527 density[r] = evalDensity(scaledHistArray[r]);
528
529 return density;
530 }
531
532}
This class provides histograms for which the bin counts (heights of rectangles) are replaced by real-...
double[] getHeights()
return the array counts of the histogram.
double getB()
Returns the right boundary of interval .
int getNumBins()
Returns the number of bins dividing the interval.
double getA()
Returns the left boundary of interval .
double getProportionInBoundaries()
Returns the proportion of the collected observations that lie within the boundaries.
void fillFromArray(double[] obs, int numObs)
Fills this object from the first numObs observations in array obs.
static double[] evalDensity(TallyHistogram tallyHist)
Evaluates a histogram estimator defined by tallyHist once in each bin.
static double[][] evalDensity(TallyHistogram[] tallyHistArray)
Same as evalDensity(double[], TallyHistogram[]) but this method evaluates each histogram only once in...
DEHistogram(double a, double b, int numBins)
Constructs a histogram estimator over the interval with numBins number of bins.
double getH()
Gives the bin width .
static double[] evalDensity(double[] evalPoints, TallyHistogram tallyHist)
Evaluates a histogram estimator defined by tallyHist at the evaluation points evalPoints.
void setData(double[] data)
Takes the observations in data and constructs and redefines the histogram with these observations.
DEHistogram(double[] data, double a, double b, int numBins)
Constructs a histogram over the interval with numBins number of bins from the observations passed in...
static double[][] evalDensity(ScaledHistogram[] scaledHistArray)
Same as evalDensity(double[], ScaledHistogram[]) but the histograms are evaluated once in each bin.
static double evalDensity(double x, TallyHistogram tallyHist)
Evaluates a histogram estimator defined by tallylist at x.
double evalDensity(double x)
Evaluates the density estimator at x.the density estimator evaluated at .
int getNumBins()
Gives the number of bins .
static double[] evalDensity(double[] evalPoints, double[] data, double a, double b, int numBins)
Evaluates the histogram with numBins bins over which is defined by the observations data at each of ...
void setH(double h)
Sets the number of bins according to the provided binwidth via .
DEHistogram(TallyHistogram tallyHist)
Constructs a histogram from a umontreal.ssj.stat.TallyHistogram tallyHist.
double getB()
Gives the right boundary of the histogram.
static double[] evalDensity(double[] evalPoints, ScaledHistogram scaledHist)
Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at each evaluation point in...
static double[][] evalDensity(double[] evalPoints, ScaledHistogram[] scaledHistArray)
This method considers a histogram for each of the umontreal.ssj.stat.ScaledHistogram from scaledHist...
static double evalDensity(double x, ScaledHistogram scaledHist)
Evaluates the histogram defined by the umontreal.ssj.stat.ScaledHistogram at x.
static double[] evalDensity(double[] data, double a, double b, int numBins)
Evaluates the histogram with numBins bins over which is defined by the observations data once in eac...
static double evalDensity(double x, double[] data, double a, double b, int numBins)
Evaluates the histogram with numBins bins over which is defined by the observations data at the eval...
ScaledHistogram getScaledHistogram()
Returns the underlying ScaledHistogram.
double[] evalDensity()
Evaluates the histogram density estimator at one point in each bin.
static double[][] evalDensity(double[] evalPoints, TallyHistogram[] tallyHistArray)
This method considers a histogram for each of the umontreal.ssj.stat.TallyHistogram from tallyHistAr...
DEHistogram(ScaledHistogram scaledHist)
Constructs a histogram from a umontreal.ssj.stat.ScaledHistogram scaledHist.
static double[][] evalDensity(double evalPoints[], double[][] data, double a, double b, int numBins)
Assume that we have independent realizations of the underlying model.
double getA()
Gives the left boundary of the histogram.
static double[] evalDensity(ScaledHistogram scaledHist)
Same as evalDensity(double[], ScaledHistogram) but evaluation is done once in each bin.
double[] evalDensity(double[] evalPoints)
Evaluates the histogram estimator at the points in evalPoints.
String toString()
Gives a short description of the estimator.a short description.
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 onc...
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.