SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
FatigueLifeDist.java
1/*
2 * Class: FatigueLifeDist
3 * Description: fatigue life distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.probdist;
26
27import umontreal.ssj.probdist.NormalDist;
28import optimization.*;
29
56 protected double mu;
57 protected double beta;
58 protected double gamma;
59
60 private static class Optim implements Uncmin_methods {
61 private int n;
62 private double[] xi;
63 private double mu;
64
65 public Optim(double[] x, int n, double min) {
66 this.n = n;
67 this.mu = min;
68 this.xi = new double[n];
69 System.arraycopy(x, 0, this.xi, 0, n);
70 }
71
72 public double f_to_minimize(double[] p) {
73 double sum = 0.0;
74
75 if ((p[1] <= 0.0) || (p[2] <= 0.0))
76 return 1e200;
77
78 for (int i = 0; i < n; i++)
79 sum -= Math.log(density(mu, p[1], p[2], xi[i]));
80
81 return sum;
82 }
83
84 public void gradient(double[] x, double[] g) {
85 }
86
87 public void hessian(double[] x, double[][] h) {
88 }
89 }
90
96 public FatigueLifeDist(double mu, double beta, double gamma) {
97 setParams(mu, beta, gamma);
98 }
99
100 public double density(double x) {
101 return FatigueLifeDist.density(mu, beta, gamma, x);
102 }
103
104 public double cdf(double x) {
105 return FatigueLifeDist.cdf(mu, beta, gamma, x);
106 }
107
108 public double barF(double x) {
109 return FatigueLifeDist.barF(mu, beta, gamma, x);
110 }
111
112 public double inverseF(double u) {
113 return FatigueLifeDist.inverseF(mu, beta, gamma, u);
114 }
115
116 public double getMean() {
117 return FatigueLifeDist.getMean(mu, beta, gamma);
118 }
119
120 public double getVariance() {
121 return FatigueLifeDist.getVariance(mu, beta, gamma);
122 }
123
124 public double getStandardDeviation() {
125 return FatigueLifeDist.getStandardDeviation(mu, beta, gamma);
126 }
127
134 public static double density(double mu, double beta, double gamma, double x) {
135 if (beta <= 0.0)
136 throw new IllegalArgumentException("beta <= 0");
137 if (gamma <= 0.0)
138 throw new IllegalArgumentException("gamma <= 0");
139 if (x <= mu)
140 return 0.0;
141 double y;
142 y = (Math.sqrt((x - mu) / beta) - Math.sqrt(beta / (x - mu))) / gamma;
143
144 return (((Math.sqrt((x - mu) / beta) + Math.sqrt(beta / (x - mu))) / (2 * gamma * (x - mu)))
145 * NormalDist.density(0.0, 1.0, y));
146 }
147
153 public static double cdf(double mu, double beta, double gamma, double x) {
154 if (beta <= 0.0)
155 throw new IllegalArgumentException("beta <= 0");
156 if (gamma <= 0.0)
157 throw new IllegalArgumentException("gamma <= 0");
158 if (x <= mu)
159 return 0.0;
160
161 return NormalDist.cdf01((Math.sqrt((x - mu) / beta) - Math.sqrt(beta / (x - mu))) / gamma);
162 }
163
168 public static double barF(double mu, double beta, double gamma, double x) {
169 if (beta <= 0.0)
170 throw new IllegalArgumentException("beta <= 0");
171 if (gamma <= 0.0)
172 throw new IllegalArgumentException("gamma <= 0");
173 if (x <= mu)
174 return 1.0;
175
176 return NormalDist.barF01((Math.sqrt((x - mu) / beta) - Math.sqrt(beta / (x - mu))) / gamma);
177 }
178
183 public static double inverseF(double mu, double beta, double gamma, double u) {
184 if (beta <= 0.0)
185 throw new IllegalArgumentException("beta <= 0");
186 if (gamma <= 0.0)
187 throw new IllegalArgumentException("gamma <= 0");
188 if (u > 1.0 || u < 0.0)
189 throw new IllegalArgumentException("u not in [0,1]");
190 if (u <= 0.0) // if u == 0, in fact
191 return mu;
192 if (u >= 1.0) // if u == 1, in fact
193 return Double.POSITIVE_INFINITY;
194
195 double w = gamma * NormalDist.inverseF01(u);
196 double sqrtZ = 0.5 * (w + Math.sqrt(w * w + 4.0));
197
198 return (mu + sqrtZ * sqrtZ * beta);
199 }
200
217 public static double[] getMLE(double[] x, int n, double mu) {
218 double sum = 0.0;
219
220 if (n <= 0)
221 throw new IllegalArgumentException("n <= 0");
222
223 double[] parameters = new double[3];
224 double[] xpls = new double[3];
225 double[] param = new double[3];
226 double[] fpls = new double[3];
227 double[] gpls = new double[3];
228 int[] itrcmd = new int[2];
229 double[][] h = new double[3][3];
230 double[] udiag = new double[3];
231
232 Optim system = new Optim(x, n, mu);
233
234 double mean = 0.0;
235 for (int i = 0; i < n; i++)
236 mean += x[i];
237 mean /= (double) n;
238
239 double var = 0.0;
240 for (int i = 0; i < n; i++)
241 var += (x[i] - mean) * (x[i] - mean);
242 var /= (double) n;
243
244 double loc2 = (mean - mu) * (mean - mu);
245 double a = 0.25 * (var - 5 * loc2);
246 double b = (var - loc2);
247 double c = var;
248
249 double delta = b * b - 4.0 * a * c;
250
251 double gamma2 = (-b - Math.sqrt(delta)) / (2.0 * a);
252 param[2] = Math.sqrt(gamma2);
253 param[1] = (mean - mu) / (1.0 + gamma2 / 2.0);
254
255 Uncmin_f77.optif0_f77(2, param, system, xpls, fpls, gpls, itrcmd, h, udiag);
256
257 for (int i = 1; i < 3; i++)
258 parameters[i] = xpls[i];
259 parameters[0] = mu;
260 return parameters;
261 }
262
270 public static double getMean(double mu, double beta, double gamma) {
271 if (beta <= 0.0)
272 throw new IllegalArgumentException("beta <= 0");
273 if (gamma <= 0.0)
274 throw new IllegalArgumentException("gamma <= 0");
275
276 return (mu + beta * (1 + 0.5 * gamma * gamma));
277 }
278
286 public static double getVariance(double mu, double beta, double gamma) {
287 if (beta <= 0.0)
288 throw new IllegalArgumentException("beta <= 0");
289 if (gamma <= 0.0)
290 throw new IllegalArgumentException("gamma <= 0");
291
292 return (beta * beta * gamma * gamma * (1.0 + 5.0 / 4.0 * gamma * gamma));
293 }
294
301 public static double getStandardDeviation(double mu, double beta, double gamma) {
302 return Math.sqrt(FatigueLifeDist.getVariance(mu, beta, gamma));
303 }
304
308 public double getBeta() {
309 return beta;
310 }
311
315 public double getGamma() {
316 return gamma;
317 }
318
322 public double getMu() {
323 return mu;
324 }
325
329 public void setParams(double mu, double beta, double gamma) {
330 if (beta <= 0.0)
331 throw new IllegalArgumentException("beta <= 0");
332 if (gamma <= 0.0)
333 throw new IllegalArgumentException("gamma <= 0");
334
335 this.mu = mu;
336 this.beta = beta;
337 this.gamma = gamma;
338 supportA = mu;
339 }
340
345 public double[] getParams() {
346 double[] retour = { mu, beta, gamma };
347 return retour;
348 }
349
353 public String toString() {
354 return getClass().getSimpleName() + " : mu = " + mu + ", beta = " + beta + ", gamma = " + gamma;
355 }
356
357}
Classes implementing continuous distributions should inherit from this base class.
static double getStandardDeviation(double mu, double beta, double gamma)
Computes and returns the standard deviation of the fatigue life distribution with parameters ,...
static double getVariance(double mu, double beta, double gamma)
Computes and returns the variance of the fatigue life distribution with parameters ,...
void setParams(double mu, double beta, double gamma)
Sets the parameters , and of this object.
static double cdf(double mu, double beta, double gamma, double x)
Computes the fatigue life distribution function with parameters.
String toString()
Returns a String containing information about the current distribution.
double getBeta()
Returns the parameter of this object.
static double barF(double mu, double beta, double gamma, double x)
Computes the complementary distribution function of the fatigue life distribution with parameters ,...
double getVariance()
Returns the variance.
double density(double x)
Returns , the density evaluated at .
double getGamma()
Returns the parameter of this object.
static double inverseF(double mu, double beta, double gamma, double u)
Computes the inverse of the fatigue life distribution with parameters , and .
double getStandardDeviation()
Returns the standard deviation.
double inverseF(double u)
Returns the inverse distribution function .
double cdf(double x)
Returns the distribution function .
static double getMean(double mu, double beta, double gamma)
Computes and returns the mean of the fatigue life distribution with parameters.
static double density(double mu, double beta, double gamma, double x)
Computes the density ( fFatigueLife ) for the fatigue life distribution with parameters.
double barF(double x)
Returns the complementary distribution function.
FatigueLifeDist(double mu, double beta, double gamma)
Constructs a fatigue life distribution with parameters ,.
double getMu()
Returns the parameter of this object.
static double[] getMLE(double[] x, int n, double mu)
Estimates the parameters ( , , ) of the fatigue life distribution using the maximum likelihood method...
double[] getParams()
Return a table containing the parameters of the current distribution.
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
double density(double x)
Returns , the density evaluated at .
static double inverseF01(double u)
Same as inverseF(0, 1, u).
static double cdf01(double x)
Same as cdf(0, 1, x).
static double barF01(double x)
Same as barF(0, 1, x).