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.LocalizedCoreFormats;
25 import org.hipparchus.exception.MathIllegalArgumentException;
26 import org.hipparchus.util.FastMath;
27 import org.hipparchus.util.MathUtils;
28
29
30
31
32
33
34
35 public class LogisticDistribution extends AbstractRealDistribution {
36
37
38 private static final long serialVersionUID = 20141003L;
39
40
41 private final double mu;
42
43 private final double s;
44
45
46
47
48
49
50
51
52 public LogisticDistribution(double mu, double s)
53 throws MathIllegalArgumentException {
54 if (s <= 0.0) {
55 throw new MathIllegalArgumentException(LocalizedCoreFormats.NOT_POSITIVE_SCALE,
56 s);
57 }
58
59 this.mu = mu;
60 this.s = s;
61 }
62
63
64
65
66
67
68 public double getLocation() {
69 return mu;
70 }
71
72
73
74
75
76
77 public double getScale() {
78 return s;
79 }
80
81
82 @Override
83 public double density(double x) {
84 double z = (x - mu) / s;
85 double v = FastMath.exp(-z);
86 return 1 / s * v / ((1.0 + v) * (1.0 + v));
87 }
88
89
90 @Override
91 public double cumulativeProbability(double x) {
92 double z = 1 / s * (x - mu);
93 return 1.0 / (1.0 + FastMath.exp(-z));
94 }
95
96
97 @Override
98 public double inverseCumulativeProbability(double p) throws MathIllegalArgumentException {
99 MathUtils.checkRangeInclusive(p, 0, 1);
100
101 if (p == 0) {
102 return 0.0;
103 } else if (p == 1) {
104 return Double.POSITIVE_INFINITY;
105 }
106 return s * Math.log(p / (1.0 - p)) + mu;
107 }
108
109
110 @Override
111 public double getNumericalMean() {
112 return mu;
113 }
114
115
116 @Override
117 public double getNumericalVariance() {
118 return (MathUtils.PI_SQUARED / 3.0) * (1.0 / (s * s));
119 }
120
121
122 @Override
123 public double getSupportLowerBound() {
124 return Double.NEGATIVE_INFINITY;
125 }
126
127
128 @Override
129 public double getSupportUpperBound() {
130 return Double.POSITIVE_INFINITY;
131 }
132
133
134 @Override
135 public boolean isSupportConnected() {
136 return true;
137 }
138
139 }