1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.distribution.continuous;
23
24 import org.hipparchus.exception.MathIllegalArgumentException;
25 import org.hipparchus.special.Erf;
26 import org.hipparchus.util.FastMath;
27 import org.hipparchus.util.MathUtils;
28
29
30
31
32
33 public class LevyDistribution extends AbstractRealDistribution {
34
35
36 private static final long serialVersionUID = 20130314L;
37
38
39 private final double mu;
40
41
42 private final double c;
43
44
45 private final double halfC;
46
47
48
49
50
51
52
53 public LevyDistribution(final double mu, final double c) {
54 super();
55 this.mu = mu;
56 this.c = c;
57 this.halfC = 0.5 * c;
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 @Override
76 public double density(final double x) {
77 if (x < mu) {
78 return Double.NaN;
79 }
80
81 final double delta = x - mu;
82 final double f = halfC / delta;
83 return FastMath.sqrt(f / FastMath.PI) * FastMath.exp(-f) /delta;
84 }
85
86
87
88
89
90 @Override
91 public double logDensity(double x) {
92 if (x < mu) {
93 return Double.NaN;
94 }
95
96 final double delta = x - mu;
97 final double f = halfC / delta;
98 return 0.5 * FastMath.log(f / FastMath.PI) - f - FastMath.log(delta);
99 }
100
101
102
103
104
105
106
107
108
109 @Override
110 public double cumulativeProbability(final double x) {
111 if (x < mu) {
112 return Double.NaN;
113 }
114 return Erf.erfc(FastMath.sqrt(halfC / (x - mu)));
115 }
116
117
118 @Override
119 public double inverseCumulativeProbability(final double p) throws MathIllegalArgumentException {
120 MathUtils.checkRangeInclusive(p, 0, 1);
121 final double t = Erf.erfcInv(p);
122 return mu + halfC / (t * t);
123 }
124
125
126
127
128 public double getScale() {
129 return c;
130 }
131
132
133
134
135 public double getLocation() {
136 return mu;
137 }
138
139
140 @Override
141 public double getNumericalMean() {
142 return Double.POSITIVE_INFINITY;
143 }
144
145
146 @Override
147 public double getNumericalVariance() {
148 return Double.POSITIVE_INFINITY;
149 }
150
151
152 @Override
153 public double getSupportLowerBound() {
154 return mu;
155 }
156
157
158 @Override
159 public double getSupportUpperBound() {
160 return Double.POSITIVE_INFINITY;
161 }
162
163
164 @Override
165 public boolean isSupportConnected() {
166 return true;
167 }
168
169 }