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.special.Gamma;
27 import org.hipparchus.util.FastMath;
28
29
30
31
32
33
34 public class NakagamiDistribution extends AbstractRealDistribution {
35
36
37 private static final long serialVersionUID = 20141003;
38
39
40 private final double mu;
41
42 private final double omega;
43
44
45
46
47
48
49
50
51
52 public NakagamiDistribution(double mu, double omega)
53 throws MathIllegalArgumentException {
54 this(mu, omega, DEFAULT_SOLVER_ABSOLUTE_ACCURACY);
55 }
56
57
58
59
60
61
62
63
64
65
66
67 public NakagamiDistribution(double mu,
68 double omega,
69 double inverseAbsoluteAccuracy)
70 throws MathIllegalArgumentException {
71 super(inverseAbsoluteAccuracy);
72
73 if (mu < 0.5) {
74 throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL,
75 mu, 0.5);
76 }
77 if (omega <= 0) {
78 throw new MathIllegalArgumentException(LocalizedCoreFormats.NOT_POSITIVE_SCALE, omega);
79 }
80
81 this.mu = mu;
82 this.omega = omega;
83 }
84
85
86
87
88
89
90 public double getShape() {
91 return mu;
92 }
93
94
95
96
97
98
99 public double getScale() {
100 return omega;
101 }
102
103
104 @Override
105 public double density(double x) {
106 if (x <= 0) {
107 return 0.0;
108 }
109 return 2.0 * FastMath.pow(mu, mu) / (Gamma.gamma(mu) * FastMath.pow(omega, mu)) *
110 FastMath.pow(x, 2 * mu - 1) * FastMath.exp(-mu * x * x / omega);
111 }
112
113
114 @Override
115 public double cumulativeProbability(double x) {
116 return Gamma.regularizedGammaP(mu, mu * x * x / omega);
117 }
118
119
120 @Override
121 public double getNumericalMean() {
122 return Gamma.gamma(mu + 0.5) / Gamma.gamma(mu) * FastMath.sqrt(omega / mu);
123 }
124
125
126 @Override
127 public double getNumericalVariance() {
128 double v = Gamma.gamma(mu + 0.5) / Gamma.gamma(mu);
129 return omega * (1 - 1 / mu * v * v);
130 }
131
132
133 @Override
134 public double getSupportLowerBound() {
135 return 0;
136 }
137
138
139 @Override
140 public double getSupportUpperBound() {
141 return Double.POSITIVE_INFINITY;
142 }
143
144
145 @Override
146 public boolean isSupportConnected() {
147 return true;
148 }
149
150 }