public class EmpiricalDistributionextends AbstractRealDistribution
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.
EmpiricalDistributionmaintains data structures, called distribution digests, that describe empirical distributions and support the following operations:
- loading the distribution from a file of observed data values
- dividing the input data into "bin ranges" and reporting bin frequency counts (data for histogram)
- reporting univariate statistics describing the full set of data values as well as the observations within each bin
- generating random values from the distribution
EmpiricalDistributionto build grouped frequency 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.
The implementation uses what amounts to the Variable Kernel Method with Gaussian smoothing:
Digesting the input file
- Pass the file once to compute min and max.
- Divide the range from min-max into
- Pass the data file again, computing bin counts and univariate statistics (mean, std dev.) for each of the bins
- Divide the interval (0,1) into subintervals associated with the bins, with the length of a bin's subinterval proportional to its count.
- Generate a uniformly distributed value in (0,1)
- Select the subinterval to which the value belongs.
- Generate a random Gaussian value with mean = mean of the associated bin and std dev = std dev of associated bin.
EmpiricalDistribution implements theUSAGE NOTES:
RealDistributioninterface as follows. Given x within the range of values in the dataset, let B be the bin containing x and let K be the within-bin kernel for B. Let P(B-) be the sum of the probabilities of the bins below B and let K(B) be the mass of B under K (i.e., the integral of the kernel density over B). Then set P(X < x) = P(B-) + P(B) * K(x) / K(B) where K(x) is the kernel distribution evaluated at x. This results in a cdf that matches the grouped frequency distribution at the bin endpoints and interpolates within bins using within-bin kernels.
binCountis set by default to 1000. A good rule of thumb is to set the bin count to approximately the length of the input file divided by 10.
- The input file must be a plain text file containing one valid numeric entry per line.
- See Also:
- Serialized Form