1package umontreal.ssj.stat;
49public class ScaledHistogram {
50 protected int numBins;
54 protected double[] height;
55 protected double integral;
57 private ScaledHistogram() {
90 public void init(
double a,
double b,
int numBins) {
92 throw new IllegalArgumentException(
" b <= a");
93 this.numBins = numBins;
94 m_h = (b - a) / numBins;
97 height =
new double[numBins];
98 for (
int i = 0; i < numBins; i++)
112 numBins = hist.numBins;
113 height =
new double[numBins];
114 this.integral = integral;
116 double scaleFactor = integral / (hist.
numberObs() * m_h);
117 for (
int i = 0; i < numBins; i++)
118 height[i] = count[i] * scaleFactor;
125 for (
int i = 0; i < numBins; i++)
134 double scaleFactor = integral / this.integral;
135 for (
int i = 0; i < numBins; i++)
136 height[i] *= scaleFactor;
137 this.integral = integral;
149 ScaledHistogram image =
clone();
151 double rscale = 1.0 / (r * r);
153 for (
int k = 0; k < numBins; k++) {
154 heightNew[k] = r * height[k];
155 for (
int ell = 1; ell < r; ell++) {
157 heightNew[k] += (r - ell) * height[k - ell];
158 if (k + ell < numBins)
159 heightNew[k] += (r - ell) * height[k + ell];
161 heightNew[k] *= rscale;
164 image.height = heightNew;
165 image.integral = sum * m_h;
176 ScaledHistogram image =
clone();
180 for (
int k = 0; k < numBins; k++) {
181 heightNew[k] = r * height[k];
183 for (
int ell = 1; ell < r; ell++) {
185 heightNew[k] += (r - ell) * height[k - ell];
188 if (k + ell < numBins) {
189 heightNew[k] += (r - ell) * height[k + ell];
193 heightNew[k] *= 1.0 / (double) weight;
196 image.height = heightNew;
197 image.integral = sum * m_h;
209 ScaledHistogram image =
clone();
211 double weight = w[0];
212 for (
int ell = 1; ell < r; ell++)
213 weight += 2.0 * w[ell];
214 double rscale = 1.0 / weight;
216 for (
int k = 0; k < numBins; k++) {
217 heightNew[k] = w[0] * height[k];
218 for (
int ell = 1; ell < r; ell++) {
220 heightNew[k] += w[ell] * height[k - ell];
222 if (k + ell < numBins) {
223 heightNew[k] += w[ell] * height[k + ell];
226 heightNew[k] *= rscale;
229 image.height = heightNew;
230 image.integral = sum * m_h;
243 ScaledHistogram image =
clone();
247 for (
int k = 0; k < numBins; k++) {
248 heightNew[k] = w[0] * height[k];
249 double weight = w[0];
250 for (
int ell = 1; ell < r; ell++) {
252 heightNew[k] += w[ell] * height[k - ell];
255 if (k + ell < numBins) {
256 heightNew[k] += w[ell] * height[k + ell];
260 heightNew[k] *= 1.0 / weight;
263 image.height = heightNew;
264 image.integral = sum * m_h;
290 ScaledHistogram image =
clone();
292 double rscale = 1.0 / (r * r);
294 double S1[] =
new double[numBins];
295 double S2[] =
new double[numBins];
298 heightNew[0] = r * S1[0];
299 for (
int ell = 1; ell <= Math.min(r, numBins); ell++) {
300 S2[0] += height[ell];
301 heightNew[0] += (r - ell) * height[ell];
303 for (
int k = 2; k <= numBins; k++) {
304 S1[k - 1] = S1[k - 2] + height[k - 1];
306 S1[k - 1] -= height[k - r];
307 S2[k - 1] = S2[k - 2] - height[k - 1];
309 S2[k - 1] += height[k + r - 1];
310 heightNew[k - 1] = heightNew[k - 2] + S2[k - 2] - S1[k - 2];
312 for (
int k = 0; k < numBins; k++) {
313 heightNew[k] *= rscale;
316 image.height = heightNew;
317 image.integral = sum * m_h;
370 for (
int j = 0; j < numBins; ++j)
371 sum += (height[j] - 1.0) * (height[j] - 1.0);
372 return sum / numBins;
382 double w0[] =
new double[numBins];
383 for (
int j = 0; j < numBins; ++j) {
384 w0[j] = height[j] - 1.0;
387 double sum = 0.5 * (w0[0] * w0[0] + w0[numBins - 1] * w0[numBins - 1]);
388 for (
int j = 0; j < numBins - 2; ++j) {
391 sum += 0.3333333333333333333 * (b * b + a * a + a * b);
393 return sum / (double) numBins;
400 ScaledHistogram image =
new ScaledHistogram();
401 image.numBins = numBins;
405 image.height =
new double[numBins];
406 image.integral = integral;
407 for (
int j = 1; j < numBins; ++j)
408 image.height[j] = height[j];
ScaledHistogram averageShiftedHistogram1(int r)
This is supposed to be a faster implementation of averageShiftedHistogram(r).
double[] getHeights()
return the array counts of the histogram.
ScaledHistogram averageShiftedHistogramTrunc(int r, double[] w)
Similar to averageShiftedHistogramTrunc, except that uses a weighted average.
double ISEvsU01()
Computes and returns the integrated square error (ISE) of a histogram w.r.t.
void init(double a, double b, int numBins)
Initializes the ScaledHistogram so it covers the interval , which is divided into numBins bins of equ...
ScaledHistogram averageShiftedHistogram(int r)
Returns an ASH-transformed version of this scaled histogram.
ScaledHistogram averageShiftedHistogramTrunc(int r)
Similar to averageShiftedHistogram, except that it assumes that the density is over a close interval ...
ScaledHistogram(TallyHistogram hist, double integral)
Constructs a ScaledHistogram from hist by normalizing the bin counts so that the integral of the hist...
double getB()
Returns the right boundary of interval .
ScaledHistogram clone()
Clones this object and the array which stores the counters.
double ISEvsU01polygonal()
Computes and returns the ISE of a polygonal density w.r.t.
void init(TallyHistogram hist, double integral)
Initializes this ScaledHistogram using the TallyHistogram hist.
double getIntegral()
return the integral the histogram.
ScaledHistogram averageShiftedHistogram(int r, double[] w)
Similar to averageShiftedHistogram, except that uses a weighted average.
void init()
Initializes all the heights (frequencies) to 0.
ScaledHistogram(double a, double b, int numBins)
Constructs a ScaledHistogram over the interval , which is divided into numBins bins of equal width.
void rescale(double integral)
Rescales the histogram by renormalizing the frequencies so its integral has the value specified by in...
int getNumBins()
Returns the number of bins dividing the interval.
double getA()
Returns the left boundary of interval .
This class extends Tally.
double getH()
Returns the width of the bins.
int[] getCounters()
Returns the array of bin counters.
double getA()
Returns the left boundary of the interval .
double getB()
Returns the right boundary of the interval .
int numberObs()
Returns the number of observations given to this probe since its last initialization.