KickJava   Java API By Example, From Geeks To Geeks.

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


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

8 public final class LognormalDistribution extends ProbabilityDistribution {
9         private NormalDistribution normal;
10
11         /**
12         * Constructs a standard lognormal distribution.
13         */

14         public LognormalDistribution() {
15                 this(0.0,1.0);
16         }
17         /**
18         * Constructs a lognormal distribution.
19         * @param mu the mu parameter.
20         * @param sigma the sigma parameter.
21         */

22         public LognormalDistribution(double mu,double sigma) {
23                 normal=new NormalDistribution(mu,sigma*sigma);
24         }
25         /**
26         * Returns the mu parameter.
27         */

28         public double getMuParameter() {
29                 return normal.getMean();
30         }
31         /**
32         * Returns the sigma parameter.
33         */

34         public double getSigmaParameter() {
35                 return Math.sqrt(normal.getVariance());
36         }
37         /**
38         * Probability density function of a lognormal distribution.
39         * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
40         */

41         public double probability(double X) {
42                 checkRange(X,0.0,Double.MAX_VALUE);
43                 return normal.probability(Math.log(X))/X;
44         }
45         /**
46         * Cumulative lognormal distribution function.
47     * @return the probability that a stochastic variable x is less then X, i.e. P(x<X).
48         */

49         public double cumulative(double X) {
50                 checkRange(X,0.0,Double.MAX_VALUE);
51                 return normal.cumulative(Math.log(X));
52         }
53         /**
54     * Inverse of the cumulative lognormal distribution function.
55         * @return the value X for which P(x<X).
56         */

57         public double inverse(double probability) {
58                 return Math.exp(normal.inverse(probability));
59         }
60 }
61
62
Popular Tags