Java Reference
In-Depth Information
int underflows;
int overflows;
double lo;
double hi;
double range;
/** The constructor will create an array of a given
* number of bins. The range of the histogram is given
*bythe upper and lower limit values.
**/
public BasicHist (int numBins, double lo, double hi)
{
this.numBins = numBins;
bins = new int[numBins];
this.lo = lo;
this.hi = hi;
range = hi lo;
}
/** Add an entry to a bin. Include if value is in the
* range lo <= x < hi
**/
public void add (double x) {
if (x >= hi) overflows++;
else if (x < lo) underflows++;
else {
double val = x lo;
// Casting to int will round off to lower integer
// value.
int bin = (int) (numBins * (val/range));
// Increment the corresponding bin.
bins[bin]++;
}
}
/** Clear the histogram bins. **/
public void clear () {
for (int i = 0; i < numBins; i++) {
bins[i] = 0;
}
overflows = 0;
underflows = 0;
}
 
Search WWH ::




Custom Search