01: package JSci.maths.statistics;
02:
03: /**
04: * The ExponentialDistribution class provides an object for encapsulating exponential distributions.
05: * @version 0.2
06: * @author Mark Hale
07: */
08: public final class ExponentialDistribution extends
09: ProbabilityDistribution {
10: private double lambda;
11:
12: /**
13: * Constructs the standard exponential distribution.
14: */
15: public ExponentialDistribution() {
16: this (1.0);
17: }
18:
19: /**
20: * Constructs an exponential distribution.
21: * @param decay the scale parameter.
22: */
23: public ExponentialDistribution(double decay) {
24: if (decay < 0.0)
25: throw new OutOfRangeException(
26: "The scale parameter should be positive.");
27: lambda = decay;
28: }
29:
30: /**
31: * Constructs an exponential distribution from a data set.
32: * @param array a sample.
33: */
34: public ExponentialDistribution(double array[]) {
35: double sumX = array[0];
36: for (int i = 1; i < array.length; i++)
37: sumX += array[i];
38: lambda = sumX / array.length;
39: }
40:
41: /**
42: * Returns the scale parameter.
43: */
44: public double getScaleParameter() {
45: return lambda;
46: }
47:
48: /**
49: * Returns the mean.
50: */
51: public double getMean() {
52: return lambda;
53: }
54:
55: /**
56: * Returns the variance.
57: */
58: public double getVariance() {
59: return lambda * lambda;
60: }
61:
62: /**
63: * Probability density function of an exponential distribution.
64: * P(X) = <img border=0 alt="lambda" src="../doc-files/lambda.gif">e<sup>-<img border=0 alt="lambda" src="../doc-files/lambda.gif">X</sup>.
65: * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
66: */
67: public double probability(double X) {
68: checkRange(X, 0.0, Double.MAX_VALUE);
69: return lambda * Math.exp(-lambda * X);
70: }
71:
72: /**
73: * Cumulative exponential distribution function.
74: * @return the probability that a stochastic variable x is less then X, i.e. P(x<X).
75: */
76: public double cumulative(double X) {
77: checkRange(X, 0.0, Double.MAX_VALUE);
78: return 1.0 - Math.exp(-lambda * X);
79: }
80:
81: /**
82: * Inverse of the cumulative exponential distribution function.
83: * @return the value X for which P(x<X).
84: */
85: public double inverse(double probability) {
86: checkRange(probability);
87: return -Math.log(1.0 - probability) / lambda;
88: }
89: }
|