~ubuntu-branches/ubuntu/quantal/libpal-java/quantal

« back to all changes in this revision

Viewing changes to src/pal/statistics/ParetoDistribution.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2012-01-27 13:57:54 UTC
  • Revision ID: package-import@ubuntu.com-20120127135754-d63l3581f65fw9pk
Tags: upstream-1.5.1
ImportĀ upstreamĀ versionĀ 1.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ParetoDistribution.java
 
2
//
 
3
// (c) 1999-2001 PAL Development Core Team
 
4
//
 
5
// This package may be distributed under the
 
6
// terms of the Lesser GNU General Public License (LGPL)
 
7
 
 
8
 
 
9
package pal.statistics;
 
10
 
 
11
import pal.math.*;
 
12
 
 
13
 
 
14
/**
 
15
 * Pareto distribution
 
16
 * (scale-free distribution without characteristic length scale).
 
17
 *
 
18
 * Parameters: shape parameter k>0, scale parameter m>0 ("minimum income")
 
19
 *
 
20
 * @version $Id: ParetoDistribution.java,v 1.2 2001/07/13 14:39:13 korbinian Exp $
 
21
 *
 
22
 * @author Korbinian Strimmer
 
23
 */
 
24
public class ParetoDistribution
 
25
{
 
26
        //
 
27
        // Public stuff
 
28
        //
 
29
 
 
30
        /**
 
31
         * probability density function of the Pareto distribution
 
32
         * 
 
33
         * @param x argument (>=m)
 
34
         * @param k shape parameter (>0)
 
35
         * @param m scale parameter (>0, "minimum income")
 
36
         *
 
37
         * @return pdf value
 
38
         */
 
39
        public static double pdf(double x, double k, double m)
 
40
        {
 
41
                return k*Math.pow(m,k)*Math.pow(x,-(k+1));
 
42
        }
 
43
 
 
44
        /**
 
45
         * cumulative density function of the Pareto distribution
 
46
         * 
 
47
         * @param x argument (>=m)
 
48
         * @param k shape parameter (>0)
 
49
         * @param m scale parameter (>0, "minimum income")
 
50
         *
 
51
         * @return cdf value
 
52
         */
 
53
        public static double cdf(double x, double k, double m)
 
54
        {
 
55
                return 1.0-Math.pow(m/x, k);
 
56
        }
 
57
 
 
58
 
 
59
        /**
 
60
         * quantile (inverse cumulative density function) of the Pareto distribution
 
61
         * 
 
62
         * @param p argument (0 < p < 1)
 
63
         * @param k shape parameter (>0)
 
64
         * @param m scale parameter (>0, "minimum income")
 
65
         *
 
66
         * @return icdf value
 
67
         */
 
68
        public static double quantile(double p, double k, double m)
 
69
        {
 
70
                return m/Math.pow(1.0-p,1.0/k);
 
71
        }
 
72
        
 
73
        /**
 
74
         * mean of the Pareto distribution
 
75
         * 
 
76
         * @param k shape parameter (>0)
 
77
         * @param m scale parameter (>0, "minimum income")
 
78
         *
 
79
         * @return mean
 
80
         */
 
81
        public static double mean(double k, double m)
 
82
        {
 
83
                if (k > 1.0)
 
84
                        return m*k/(k-1.0);
 
85
                else
 
86
                        return Double.POSITIVE_INFINITY;
 
87
        }
 
88
 
 
89
        /**
 
90
         * variance of the Pareto distribution
 
91
         * 
 
92
         * @param k shape parameter (>0)
 
93
         * @param m scale parameter (>0, "minimum income")
 
94
         *
 
95
         * @return variance
 
96
         */
 
97
        public static double variance(double k, double m)
 
98
        {
 
99
                if (k > 2.0)
 
100
                        return m*m*k/((k-1.0)*(k-1.0)*(k-2.0));
 
101
                else
 
102
                        return Double.POSITIVE_INFINITY;
 
103
        }
 
104
        
 
105
        /**
 
106
         * moments E(X^n) of the Pareto distribution
 
107
         * 
 
108
         * @param n moment
 
109
         * @param k shape parameter (>0)
 
110
         * @param m scale parameter (>0, "minimum income")
 
111
         *
 
112
         * @return variance
 
113
         */
 
114
        public static double moment(int n, double k, double m)
 
115
        {
 
116
                if (k > n)
 
117
                        return Math.pow(m,n)*k/(k-n);
 
118
                else
 
119
                        return Double.POSITIVE_INFINITY;
 
120
        }
 
121
}