org.apache.commons.math.random
Interface EmpiricalDistribution

All Known Implementing Classes:
EmpiricalDistributionImpl

public interface EmpiricalDistribution

Represents an empirical probability distribution -- a probability distribution derived from observed data without making any assumptions about the functional form of the population distribution that the data come from.

Implementations of this interface maintain data structures, called distribution digests, that describe empirical distributions and support the following operations:

Applications can use EmpiricalDistribution implementations to build grouped frequnecy histograms representing the input data or to generate random values "like" those in the input file -- i.e., the values generated will follow the distribution of the values in the file.

Version:
$Revision: 1.12 $ $Date: 2004/01/15 05:22:08 $

Method Summary
 int getBinCount()
          Returns the number of bins
 ArrayList getBinStats()
          Returns a list of Univariates containing statistics describing the values in each of the bins.
 double getNextValue()
          Generates a random value from this distribution.
 DescriptiveStatistics getSampleStats()
          Returns a DescriptiveStatistics describing this distribution.
 double[] getUpperBounds()
          Returns the array of upper bounds for the bins.
 boolean isLoaded()
          property indicating whether or not the distribution has been loaded
 void load(File file)
          Computes the empirical distribution from the input file.
 void load(String filePath)
          Computes the empirical distribution from the input file.
 void load(URL url)
          Computes the empirical distribution using data read from a URL.
 void loadDistribution(File file)
          Loads a saved distribution from a file.
 void loadDistribution(String filePath)
          Loads a saved distribution from a file.
 void saveDistribution(File file)
          Saves distribution to a file.
 void saveDistribution(String filePath)
          Saves distribution to a file.
 

Method Detail

load

public void load(String filePath)
          throws IOException
Computes the empirical distribution from the input file.

Parameters:
filePath - fully qualified name of a file in the local file system
Throws:
IOException - if an IO error occurs

load

public void load(File file)
          throws IOException
Computes the empirical distribution from the input file.

Parameters:
file - the input file
Throws:
IOException - if an IO error occurs

load

public void load(URL url)
          throws IOException
Computes the empirical distribution using data read from a URL.

Throws:
IOException - if an IO error occurs

getNextValue

public double getNextValue()
                    throws IllegalStateException
Generates a random value from this distribution. Preconditions:

Returns:
the random value.
Throws:
IllegalStateException - if the distribution has not been loaded

getSampleStats

public DescriptiveStatistics getSampleStats()
                                     throws IllegalStateException
Returns a DescriptiveStatistics describing this distribution. Preconditions:

Returns:
the sample statistics
Throws:
IllegalStateException - if the distribution has not been loaded

loadDistribution

public void loadDistribution(File file)
                      throws IOException
Loads a saved distribution from a file.

Parameters:
file - File reference for a file containing a digested distribution
Throws:
IOException - if an error occurs reading the file

loadDistribution

public void loadDistribution(String filePath)
                      throws IOException
Loads a saved distribution from a file.

Parameters:
filePath - fully qualified file path for a file containing a digested distribution
Throws:
IOException - if an error occurs reading the file

saveDistribution

public void saveDistribution(String filePath)
                      throws IOException,
                             IllegalStateException
Saves distribution to a file. Overwrites the file if it exists. Preconditions:

Parameters:
filePath - fully qualified file path for the file to be written
Throws:
IOException - if an error occurs reading the file
IllegalStateException - if the distribution has not been loaded

saveDistribution

public void saveDistribution(File file)
                      throws IOException,
                             IllegalStateException
Saves distribution to a file. Overwrites the file if it exists. Preconditions:

Parameters:
file - File reference for the file to be written
Throws:
IOException - if an error occurs reading the file
IllegalStateException - if the distribution has not been loaded

isLoaded

public boolean isLoaded()
property indicating whether or not the distribution has been loaded

Returns:
true if the distribution has been loaded

getBinCount

public int getBinCount()
Returns the number of bins

Returns:
the number of bins.

getBinStats

public ArrayList getBinStats()
Returns a list of Univariates containing statistics describing the values in each of the bins. The ArrayList is indexed on the bin number.

Returns:
ArrayList of bin statistics.

getUpperBounds

public double[] getUpperBounds()
Returns the array of upper bounds for the bins. Bins are:
[min,upperBounds[0]],(upperBounds[0],upperBounds[1]],..., (upperBounds[binCount-1],max]

Returns:
array of bin upper bounds


Copyright © 2003-2004 Apache Software Foundation. All Rights Reserved.