org.strbio.math
Class Bin

java.lang.Object
  extended by org.strbio.math.IVector
      extended by org.strbio.math.Bin
Direct Known Subclasses:
Bin2D, Sampler

public class Bin
extends IVector

a class which does 1-D histogram-bins. If you're sampling some (double) data and want stats like average, stdev on the ensemble, but don't want to bother keeping track of every point, this should be useful. If you do want to keep track of every point, try using a DVector or DMatrix, which have similar stats functions.

 Version 1.3, 10/5/00 - added stdevp, zScore
 Version 1.2, 6/24/99 - added main() to sample from a file.
 Version 1.1, 9/29/98 - made extendable by Bin2D; sample()
   is no longer final, and PrintfStream changed to Printf.
   Fixed average and stdev to return NaN when not enough samples.
   Sample() now returns an int, indicating the bin it was put
   into.
 Version 1.0, 3/31/98 - original version.
 

Version:
1.3, 10/5/00
Author:
JMC
See Also:
Bin2D

Field Summary
protected  double binsize
           
protected  double min_v
           
protected  long nsamples
           
protected  double sum_x
           
protected  double sum_x2
           
 
Fields inherited from class org.strbio.math.IVector
data
 
Constructor Summary
Bin(int nbins, double minv, double maxv)
          to set up the histogram-bin, you need to know the number of bins you want, the minimum possible value, and the maximum possible value of the data.
 
Method Summary
 double average()
          Return the average of all values sampled.
 void print(Printf outfile)
          print out bins to an open Printf.
 void print(java.lang.String filename)
          print out bins to a new file.
 int sample(double r)
          Sample a value.
 long samples()
          how many values have I sampled?
 double stdev()
          Return the standard deviation of all values sampled.
 double stdevp()
          Returns the standard deviation of all values sampled.
 double zScore(double x)
          Shows how many standard deviations a given double is below the average.
 
Methods inherited from class org.strbio.math.IVector
add, add, cross, cross, dimension, dot, dot, eliminate, equals, length, load, load, max, min, multiply, multiply, multiply, reverse, reverse, save, save, setValue, setValueAt, sort, subtract, subtract, valueAt
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

min_v

protected double min_v

binsize

protected double binsize

sum_x

protected double sum_x

sum_x2

protected double sum_x2

nsamples

protected long nsamples
Constructor Detail

Bin

public Bin(int nbins,
           double minv,
           double maxv)
to set up the histogram-bin, you need to know the number of bins you want, the minimum possible value, and the maximum possible value of the data. Sorry, but dynamically expanding bins would be a pain in the ass to write.

Parameters:
nbins - the number of bins to sort data into. You don't need any bins at all if you just want stats like average, stdev.
minv - the minimum data you might sample
maxv - the maximum data you might sample
Method Detail

sample

public int sample(double r)
Sample a value. If the value is lower than the minimum value you specified in setting up the bin, the sample goes into the lowest bin. Same thing goes for the high end. This 'rounding off' does not affect statistics like the average.


average

public final double average()
Return the average of all values sampled.


stdev

public final double stdev()
Return the standard deviation of all values sampled. This is the 'sample' standard deviation.


stdevp

public final double stdevp()
Returns the standard deviation of all values sampled. This is the 'population' standard deviation.


zScore

public final double zScore(double x)
Shows how many standard deviations a given double is below the average.


samples

public final long samples()
how many values have I sampled?


print

public void print(Printf outfile)
           throws java.io.IOException
print out bins to an open Printf. For each bin, this prints the min, center, and maximum bounds of the bin, and the number of values that were sampled in it.

Overrides:
print in class IVector
Throws:
java.io.IOException
See Also:
IVector.save(org.strbio.io.Printf)

print

public final void print(java.lang.String filename)
                 throws java.io.IOException
print out bins to a new file. For each bin, this prints the min, center, and maximum bounds of the bin, and the number of values that were sampled in it.

Parameters:
filename - the file name. Overwrites existing files.
Throws:
java.io.IOException