KickJava   Java API By Example, From Geeks To Geeks.

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


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

8 public final class ParetoDistribution extends ProbabilityDistribution {
9         private double shape;
10         private double scale;
11
12         /**
13         * Constructs a Pareto distribution.
14         * @param sh the shape.
15         * @param sc the scale.
16         */

17         public ParetoDistribution(double sh,double sc) {
18                 if(sh<0.0)
19                         throw new OutOfRangeException("The shape parameter should be positive.");
20                 shape=sh;
21                 if(sc<0.0)
22                         throw new OutOfRangeException("The scale paremeter should be positive.");
23                 scale=sc;
24         }
25         /**
26         * Returns the shape parameter.
27         */

28         public double getShapeParameter() {
29                 return shape;
30         }
31         /**
32         * Returns the scale parameter.
33         */

34         public double getScaleParameter() {
35                 return scale;
36         }
37         /**
38         * Returns the mean.
39         */

40         public double getMean() {
41                 return shape*scale/(shape-1.0);
42         }
43         /**
44         * Returns the variance.
45         */

46         public double getVariance() {
47                 return shape*scale*scale/((shape-2.0)*(shape-1.0)*(shape-1.0));
48         }
49         /**
50         * Probability density function of a Pareto distribution.
51         * P(X) = (a/X) (s/X)<sup>a</sup>.
52         * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
53         */

54         public double probability(double X) {
55                 if(X<scale)
56                         throw new OutOfRangeException("X should be greater than or equal to the scale.");
57                 return shape*Math.pow(scale/X,shape)/X;
58         }
59         /**
60         * Cumulative Pareto distribution function.
61     * @return the probability that a stochastic variable x is less then X, i.e. P(x&lt;X).
62         */

63         public double cumulative(double X) {
64                 if(X<scale)
65                         throw new OutOfRangeException("X should be greater than or equal to the scale.");
66                 return 1.0-Math.pow(scale/X,shape);
67         }
68         /**
69     * Inverse of the cumulative Pareto distribution function.
70         * @return the value X for which P(x&lt;X).
71         */

72         public double inverse(double probability) {
73                 checkRange(probability);
74                 return scale/Math.pow(1.0-probability,1.0/shape);
75         }
76 }
77
78
Popular Tags