01: package JSci.maths.statistics;
02:
03: /**
04: * The CauchyDistribution class provides an object for encapsulating Cauchy distributions.
05: * @version 0.2
06: * @author Mark Hale
07: */
08: public final class CauchyDistribution extends ProbabilityDistribution {
09: private double alpha;
10: private double gamma;
11:
12: /**
13: * Constructs the standard Cauchy distribution.
14: */
15: public CauchyDistribution() {
16: this (0.0, 1.0);
17: }
18:
19: /**
20: * Constructs a Cauchy distribution.
21: * @param location the location parameter.
22: * @param scale the scale parameter.
23: */
24: public CauchyDistribution(double location, double scale) {
25: if (scale < 0.0)
26: throw new OutOfRangeException(
27: "The scale parameter should be positive.");
28: alpha = location;
29: gamma = scale;
30: }
31:
32: /**
33: * Returns the location parameter.
34: */
35: public double getLocationParameter() {
36: return alpha;
37: }
38:
39: /**
40: * Returns the scale parameter.
41: */
42: public double getScaleParameter() {
43: return gamma;
44: }
45:
46: /**
47: * Probability density function of a Cauchy distribution.
48: * P(X) = <img border=0 alt="Gamma" src="../doc-files/ugamma.gif">/(<img border=0 alt="pi" src="../doc-files/pi.gif">(<img border=0 alt="Gamma" src="../doc-files/ugamma.gif"><sup>2</sup>+(X-<img border=0 alt="alpha" src="../doc-files/alpha.gif">)<sup>2</sup>)).
49: * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
50: */
51: public double probability(double X) {
52: final double y = X - alpha;
53: return gamma / (Math.PI * (gamma * gamma + y * y));
54: }
55:
56: /**
57: * Cumulative Cauchy distribution function.
58: * @return the probability that a stochastic variable x is less then X, i.e. P(x<X).
59: */
60: public double cumulative(double X) {
61: return 0.5 + Math.atan((X - alpha) / gamma) / Math.PI;
62: }
63:
64: /**
65: * Inverse of the cumulative Cauchy distribution function.
66: * @return the value X for which P(x<X).
67: */
68: public double inverse(double probability) {
69: checkRange(probability);
70: return alpha - gamma / Math.tan(Math.PI * probability);
71: }
72: }
|