1package umontreal.ssj.stat;
28import umontreal.ssj.util.PrintfFormat;
45 protected int numBins;
46 protected int[] count;
47 protected int leftCount;
48 protected int rightCount;
89 public void init(
double a,
double b,
int numBins) {
97 throw new IllegalArgumentException(
" b <= a");
98 count =
new int[numBins];
99 this.numBins = numBins;
100 m_h = (b - a) / (
double) numBins;
103 leftCount = rightCount = 0;
104 for (
int i = 0; i < numBins; i++)
115 leftCount = rightCount = 0;
116 for (
int i = 0; i < numBins; i++)
125 for (
int i = 0; i < numObs; i++)
151 public void add(
double x) {
158 int i = (int) ((x - m_a) / m_h);
173 while (count[i] == 0) {
177 while (count[j] == 0) {
181 int[] coco =
new int[numBins - cpL - cpR];
182 System.arraycopy(count, i, coco, 0, j - i + 1);
185 image.m_a = m_a + (cpL * m_h);
186 image.m_b = m_b - (cpR * m_h);
187 image.numBins = numBins - cpL - cpR;
188 image.leftCount = leftCount;
189 image.rightCount = rightCount;
202 if (this.numBins != other.numBins)
203 throw new IllegalArgumentException(
"different number of bin in two histogram to merge");
205 int[] countNew =
new int[numBins];
206 System.arraycopy(count, 0, countNew, 0, numBins);
208 for (
int i = 0; i < countNew.length; i++)
209 countNew[i] = countNew[i] + coOther[i];
210 image.count = countNew;
211 image.leftCount = leftCount + other.leftCount;
212 image.rightCount = rightCount + other.rightCount;
216 image.numBins = numBins;
229 int numBinsNew = (int) Math.ceil((
double) numBins / (
double) g);
230 int[] countNew =
new int[numBinsNew];
232 for (
int j = 0; j < numBinsNew - 1; j++) {
233 for (
int i = b; i < b + g; i++)
234 countNew[j] += count[i];
237 while (b < numBins - 1) {
238 countNew[numBinsNew - 1] += count[b];
241 image.count = countNew;
244 image.m_b = m_h * numBinsNew;
245 image.numBins = numBinsNew;
246 image.leftCount = leftCount;
247 image.rightCount = rightCount;
309 for (
int num : count) {
312 return (
double) total / (double) (total + leftCount + rightCount);
320 int[] coco =
new int[numBins];
321 System.arraycopy(count, 0, coco, 0, numBins);
323 image.leftCount = leftCount;
324 image.rightCount = rightCount;
328 image.numBins = numBins;
336 StringBuffer sb =
new StringBuffer();
343 for (
int i = 0; i < numBins; i++) {
344 double a = m_a + (i - 1) * m_h;
345 double b = m_a + i * m_h;
351 return sb.toString();
TallyHistogram(double a, double b, int numBins)
Constructs a TallyHistogram statistical probe.
double getProportionInBoundaries()
Returns the proportion of the collected observations that lie within the boundaries.
TallyHistogram aggregateBins(int g)
Merges bins by groups of size .
TallyHistogram(String name, double a, double b, int numBins)
Constructs a new TallyHistogram statistical probe with name name.
TallyHistogram trimHistogram()
Remove empty bins in the tails (left and right), without changing the bin size.
int getNumBins()
Returns the number of bins .
double getH()
Returns the width of the bins.
int[] getCounters()
Returns the array of bin counters.
TallyHistogram addHistograms(TallyHistogram other)
Merges this histogram with the other histogram, by adding the bin counts of the two histograms.
void init()
Initializes all the counters and accumulators, including those of the Tally object.
void fillFromTallyStore(TallyStore ts)
Fills this object from the observations in a TallyStore object.
double getA()
Returns the left boundary of the interval .
void add(double x)
Gives a new observation to the statistical probe.
void fillFromArray(double[] obs, int numObs)
Fills this object from the first numObs observations in array obs.
void init(double a, double b, int numBins)
Initializes this object.
double getB()
Returns the right boundary of the interval .
TallyHistogram clone()
Clones this object and the array that stores the counters.
String toString()
Returns the bin counters as a String.
void fillFromArray(double[] obs)
Fills this object from the entire array obs.
This class is a variant of Tally for which the individual observations are stored in a list implement...
double[] getArray()
Returns the observations stored in this probe.
int numberObs()
Returns the number of observations given to this probe since its last initialization.
Tally()
Constructs a new unnamed Tally statistical probe.