marytts.util.math
Class Histogram

java.lang.Object
  extended by marytts.util.math.Histogram

public class Histogram
extends java.lang.Object


Constructor Summary
Histogram(double[] data)
           
Histogram(double[] data, int nbins)
          A simple constructor
Histogram(double[] data, int nbins, double min, double max)
          Constructor which sets name, number of bins, and range.
 
Method Summary
 void changeSettings(int nbins)
           
 int entries()
          Get number of entries in the histogram.
 void fill(double x)
          Enter data into the histogram.
 double getBandWidth()
           
 double[] getDataArray()
           
 boolean getDebug()
          Get debug flag.
 double[] getHistArray()
          This method gives you the bin contents in the form of an array.
 double[] getSampleArray()
           
 double max()
          Get upper end of histogram range
 double mean()
           
 double min()
          Get lower end of histogram range
 java.lang.String name()
          Get the name of the histogram.
 int numberOfBins()
          Get the number of bins in the histogram.
 double overflow()
          Get the height of the overflow bin.
 void setBandWidth()
           
 void setDebug(boolean flag)
          Set debug flag.
 void setHistogram(double[] data, int nbins, double min, double max)
          Settings to Histogram
 double[] setSampleArray()
           
 void show()
          Print the histogram data to the console.
 double stdDev()
           
 double underflow()
          Get the height of the underflow bin.
 double variance()
           
 void writeToFile(java.lang.String fileName)
          Save the histogram data to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Histogram

public Histogram(double[] data)

Histogram

public Histogram(double[] data,
                 int nbins)
A simple constructor

Parameters:
data -
nbins -

Histogram

public Histogram(double[] data,
                 int nbins,
                 double min,
                 double max)
Constructor which sets name, number of bins, and range.

Parameters:
data - samples
nbins - the number of bins the histogram should have. The range specified by min and max will be divided up into this many bins.
min - the minimum of the range covered by the histogram bins
max - the maximum value of the range covered by the histogram bins
Method Detail

setHistogram

public void setHistogram(double[] data,
                         int nbins,
                         double min,
                         double max)
Settings to Histogram

Parameters:
data -
nbins -
min -
max -

changeSettings

public void changeSettings(int nbins)

fill

public void fill(double x)
Enter data into the histogram. The fill method takes the given value, works out which bin this corresponds to, and increments this bin by one.

Parameters:
x - is the value to add in to the histogram

setBandWidth

public void setBandWidth()

getBandWidth

public double getBandWidth()

writeToFile

public void writeToFile(java.lang.String fileName)
                 throws java.io.IOException
Save the histogram data to a file. The file format is very simple, human-readable text so it can be imported into Excel or cut & pasted into other applications.

Parameters:
fileName - name of the file to write the histogram to. Note this must be valid for your operating system, e.g. a unix filename might not work under windows
Throws:
java.io.IOException - if file cannot be opened or written to.

show

public void show()
Print the histogram data to the console. Output is only basic, intended for debugging purposes. A good example of formatted output.


setSampleArray

public double[] setSampleArray()

entries

public int entries()
Get number of entries in the histogram. This should correspond to the number of times the fill method has been used.

Returns:
number of entries

name

public java.lang.String name()
Get the name of the histogram. The name is an arbitrary label for the user, and is set by the constructor.

Returns:
histogram name

numberOfBins

public int numberOfBins()
Get the number of bins in the histogram. The range of the histogram defined by min and max is divided into this many bins.

Returns:
number of bins

min

public double min()
Get lower end of histogram range

Returns:
minimum x value covered by histogram

mean

public double mean()

variance

public double variance()

stdDev

public double stdDev()

max

public double max()
Get upper end of histogram range

Returns:
maximum x value covered by histogram

overflow

public double overflow()
Get the height of the overflow bin. Any value passed to the fill method which falls above the range of the histogram will be counted in the overflow bin.

Returns:
number of overflows

underflow

public double underflow()
Get the height of the underflow bin. Any value passed to the fill method which falls below the range of the histogram will be counted in the underflow bin.

Returns:
number of underflows

getHistArray

public double[] getHistArray()
This method gives you the bin contents in the form of an array. It might be useful for example if you want to use the histogram in some other way, for example to pass to a plotting package.

Returns:
array of bin heights

getSampleArray

public double[] getSampleArray()

getDataArray

public double[] getDataArray()

setDebug

public void setDebug(boolean flag)
Set debug flag.

Parameters:
flag - debug flag (true or false)

getDebug

public boolean getDebug()
Get debug flag.

Returns:
value of debug flag (true or false)