KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > statistics > CauchyDistribution


1 package JSci.maths.statistics;
2
3 /**
4 * The CauchyDistribution class provides an object for encapsulating Cauchy distributions.
5 * @version 0.2
6 * @author Mark Hale
7 */

8 public final class CauchyDistribution extends ProbabilityDistribution {
9         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         * Constructs a Cauchy distribution.
20         * @param location the location parameter.
21         * @param scale the scale parameter.
22         */

23         public CauchyDistribution(double location,double scale) {
24                 if(scale<0.0)
25                         throw new OutOfRangeException("The scale parameter should be positive.");
26                 alpha=location;
27                 gamma=scale;
28         }
29         /**
30         * Returns the location parameter.
31         */

32         public double getLocationParameter() {
33                 return alpha;
34         }
35         /**
36         * Returns the scale parameter.
37         */

38         public double getScaleParameter() {
39                 return gamma;
40         }
41         /**
42         * Probability density function of a Cauchy distribution.
43         * 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>)).
44         * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
45         */

46         public double probability(double X) {
47                 final double y=X-alpha;
48                 return gamma/(Math.PI*(gamma*gamma+y*y));
49         }
50         /**
51         * Cumulative Cauchy distribution function.
52     * @return the probability that a stochastic variable x is less then X, i.e. P(x&lt;X).
53         */

54         public double cumulative(double X) {
55                 return 0.5+Math.atan((X-alpha)/gamma)/Math.PI;
56         }
57         /**
58     * Inverse of the cumulative Cauchy distribution function.
59         * @return the value X for which P(x&lt;X).
60         */

61         public double inverse(double probability) {
62                 checkRange(probability);
63                 return alpha-gamma/Math.tan(Math.PI*probability);
64         }
65 }
66
67
Popular Tags