SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BetaDist.java
1/*
2 * Class: BetaDist
3 * Description: beta 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.util.*;
28import optimization.*;
29
54public class BetaDist extends ContinuousDistribution {
55 protected double alpha; // First parameter
56 protected double beta; // Second parameter
57 protected double a, b; // Interval x in [a, b]
58 protected double bminusa;
59 protected double logFactor;
60 protected double Beta; // Function Beta(alpha, beta)
61 protected double logBeta; // Ln(Beta(alpha, beta))
62
63 private static class Optim implements Lmder_fcn {
64 private double a;
65 private double b;
66
67 public Optim(double a, double b) {
68 this.a = a;
69 this.b = b;
70 }
71
72 public void fcn(int m, int n, double[] x, double[] fvec, double[][] fjac, int iflag[]) {
73 if (x[1] <= 0.0 || x[2] <= 0.0) {
74 final double BIG = 1.0e100;
75 fvec[1] = BIG;
76 fvec[2] = BIG;
77 fjac[1][1] = BIG;
78 fjac[1][2] = 0.0;
79 fjac[2][1] = 0.0;
80 fjac[2][2] = BIG;
81 return;
82 }
83
84 double trig;
85 if (iflag[1] == 1) {
86 trig = Num.digamma(x[1] + x[2]);
87 fvec[1] = Num.digamma(x[1]) - trig - a;
88 fvec[2] = Num.digamma(x[2]) - trig - b;
89 } else if (iflag[1] == 2) {
90 trig = Num.trigamma(x[1] + x[2]);
91
92 fjac[1][1] = Num.trigamma(x[1]) - trig;
93 fjac[1][2] = -trig;
94 fjac[2][1] = -trig;
95 fjac[2][2] = Num.trigamma(x[2]) - trig;
96 }
97 }
98 }
99
104 public BetaDist(double alpha, double beta) {
105 setParams(alpha, beta, 0.0, 1.0);
106 }
107
114 public BetaDist(double alpha, double beta, double a, double b) {
115 setParams(alpha, beta, a, b);
116 }
117
118 @Override
119 public double density(double x) {
120 if (x <= a || x >= b)
121 return 0;
122 double temp = (alpha - 1) * Math.log(x - a) + (beta - 1) * Math.log(b - x);
123// return factor*Math.pow (x - a, alpha - 1)*Math.pow (b - x, beta - 1);
124 return Math.exp(logFactor + temp);
125 }
126
127 public double cdf(double x) {
128 return cdf(alpha, beta, (x - a) / bminusa);
129 }
130
131 @Override
132 public double barF(double x) {
133 return barF(alpha, beta, (x - a) / bminusa);
134 }
135
136 @Override
137 public double inverseF(double u) {
138 return a + (b - a) * inverseF(alpha, beta, u);
139 }
140
141 @Override
142 public double getMean() {
143 return BetaDist.getMean(alpha, beta, a, b);
144 }
145
146 @Override
147 public double getVariance() {
148 return BetaDist.getVariance(alpha, beta, a, b);
149 }
150
151 @Override
152 public double getStandardDeviation() {
153 return BetaDist.getStandardDeviation(alpha, beta, a, b);
154 }
155
160 public static double density(double alpha, double beta, double x) {
161 return density(alpha, beta, 0.0, 1.0, x);
162 }
163
167 public static double density(double alpha, double beta, double a, double b, double x) {
168 if (a >= b)
169 throw new IllegalArgumentException("a >= b");
170 if (x <= a || x >= b)
171 return 0;
172
173 double z = -Num.lnBeta(alpha, beta) - (alpha + beta - 1) * Math.log(b - a) + (alpha - 1) * Math.log(x - a)
174 + (beta - 1) * Math.log(b - x);
175 return Math.exp(z);
176 }
177
178 static double beta_g(double x) {
179 /*
180 * Used in the normal approximation of beta. This is the function (1 - x^2 +
181 * 2x*ln(x)) / (1 - x)^2.
182 */
183 if (x > 1.0)
184 return -beta_g(1.0 / x);
185 if (x < 1.0e-200)
186 return 1.0;
187
188 final double y = 1.0 - x;
189 if (x < 0.9)
190 return (1.0 - x * x + 2.0 * x * Math.log(x)) / (y * y);
191 if (x == 1.0)
192 return 0.0;
193
194 // For x near 1, use a series expansion to avoid loss of precision
195 final double EPS = 1.0e-12;
196 double term;
197 double ypow = 1.0;
198 double sum = 0.0;
199 int j = 2;
200 do {
201 ypow *= y;
202 term = ypow / (j * (j + 1));
203 sum += term;
204 j++;
205 } while (Math.abs(term / sum) > EPS);
206
207 return 2.0 * sum;
208 }
209
210 private static double bolshev(double alpha, double beta, int d, double x) {
211 // Bol'shev approximation for large max (alpha, beta)
212 // and small min (alpha, beta)
213 /*
214 * if (x > 0.5) return barF (beta, alpha, 1.0 - x);
215 */
216 boolean flag = false;
217 double u, temp, yd, gam;
218
219 if (alpha < beta) {
220 u = alpha;
221 alpha = beta;
222 beta = u;
223 flag = false;
224 } else
225 flag = true;
226
227 u = alpha + 0.5 * beta - 0.5;
228 if (!flag)
229 temp = x / (2.0 - x);
230 else
231 temp = (1.0 - x) / (1.0 + x);
232 yd = 2.0 * u * temp;
233 gam = (Math.exp(beta * Math.log(yd) - yd - Num.lnGamma(beta))
234 * (2.0 * yd * yd - (beta - 1.0) * yd - (beta * beta - 1.0))) / (24.0 * u * u);
235 if (flag) {
236 yd = GammaDist.barF(beta, d, yd);
237 return Math.max(0, yd - gam);
238 } else {
239 yd = GammaDist.cdf(beta, d, yd);
240 return yd + gam;
241 }
242 }
243
244 private static double peizer(double alpha, double beta, double x) {
245 // Normal approximation of Peizer and Pratt. Reference: @cite tPEI68a
246 double temp, h1, h3, y;
247 h1 = alpha + beta - 1.0;
248 y = 1.0 - x;
249 if (x > 1.0e-15)
250 temp = 1.0 + y * beta_g((alpha - 0.5) / (h1 * x));
251 else
252 temp = GammaDist.mybelog((alpha - 0.5) / (h1 * x));
253
254 h3 = Math.sqrt((temp + x * beta_g((beta - 0.5) / (h1 * y))) / ((h1 + 1.0 / 6.0) * x * y))
255 * ((h1 + 1.0 / 3.0 + 0.02 * (1.0 / alpha + 1.0 / beta + 1.0 / (alpha + beta))) * x - alpha + 1.0 / 3.0
256 - 0.02 / alpha - 0.01 / (alpha + beta));
257
258 return NormalDist.cdf01(h3);
259 }
260
261 private static double donato(double alpha, double beta, double x) {
262 // Cuyt p. 387, 18.5.20b
263 // distribution Beta avec fractions continues
264 // Il faut choisir MMAX >= sqrt(max(alpha, beta))
265
266 double mid = (alpha + 1.0) / (alpha + beta + 2.0);
267 if (x > mid)
268 return 1.0 - donato(beta, alpha, 1.0 - x);
269
270 final int MMAX = 100; // pour ALPHABETAMAX = 10000
271 double[] Ta = new double[1 + MMAX];
272 double[] Tb = new double[1 + MMAX];
273 int M1 = MMAX;
274 double tem, tem1;
275 int m;
276
277 if ((beta <= MMAX) && (beta % 1.0 < 1.0e-100)) {
278 // if beta is integer, Ta[i0] = 0; it is useless to evaluate
279 // the other Ta[i] for i > i0
280 M1 = (int) beta;
281 }
282
283 Ta[1] = 1;
284 for (m = 1; m < M1; m++) {
285 tem = alpha + 2 * m - 1;
286 Ta[m + 1] = (alpha + m - 1) * (alpha + beta + m - 1) * (beta - m) * m * x * x / (tem * tem);
287 }
288
289 // term m = 0 in the next loop; avoid tem1 = 0/0 for alpha = 1
290 tem = alpha * (alpha + beta) / (alpha + 1);
291 Tb[1] = alpha - tem * x;
292
293 for (m = 1; m < M1; m++) {
294 tem = (alpha + m) * (alpha + beta + m) / (alpha + 2 * m + 1);
295 tem1 = m * (beta - m) / (alpha + 2 * m - 1);
296 Tb[m + 1] = alpha + 2 * m + (tem1 - tem) * x;
297 }
298
299 while (0. == Tb[M1] && M1 > 1) {
300 --M1;
301 }
302
303 // evaluate continuous fraction
304 double con = 0;
305 for (m = M1; m > 0; m--) {
306 con = Ta[m] / (Tb[m] + con);
307 }
308
309 tem = Num.lnBeta(alpha, beta) - alpha * Math.log(x) - beta * Math.log1p(-x);
310 return con * Math.exp(-tem);
311 }
312
317 public static double cdf(double alpha, double beta, double x) {
318 if (alpha <= 0.0)
319 throw new IllegalArgumentException("alpha <= 0");
320 if (beta <= 0.0)
321 throw new IllegalArgumentException("beta <= 0");
322
323 if (x <= 0.0)
324 return 0.0;
325 if (x >= 1.0)
326 return 1.0;
327 if (1.0 == beta)
328 return Math.pow(x, alpha);
329
330 final double ALPHABETAMAX = 10000.0;
331 final double ALPHABETALIM = 30.0;
332
333 if (Math.max(alpha, beta) <= ALPHABETAMAX) {
334 return donato(alpha, beta, x);
335 }
336
337 if ((alpha > ALPHABETAMAX && beta < ALPHABETALIM) || (beta > ALPHABETAMAX && alpha < ALPHABETALIM)) {
338 return bolshev(alpha, beta, 12, x);
339 }
340
341 return peizer(alpha, beta, x);
342 }
343
353 public static double cdf(double alpha, double beta, double a, double b, double x) {
354 return cdf(alpha, beta, (x - a) / (b - a));
355 }
356
361 public static double barF(double alpha, double beta, double x) {
362 return cdf(beta, alpha, 1.0 - x);
363 }
364
368 public static double barF(double alpha, double beta, double a, double b, double x) {
369 if (a >= b)
370 throw new IllegalArgumentException("a >= b");
371 return cdf(beta, alpha, (b - x) / (b - a));
372 }
373
374 @Deprecated
375 public static double inverseF(double alpha, double beta, int d, double u) {
376 if (alpha <= 0.0)
377 throw new IllegalArgumentException("alpha <= 0");
378 if (beta <= 0.0)
379 throw new IllegalArgumentException("beta <= 0");
380 if (d <= 0)
381 throw new IllegalArgumentException("d <= 0");
382 if (u > 1.0 || u < 0.0)
383 throw new IllegalArgumentException("u not in [0,1]");
384 if (u <= 0)
385 return 0;
386 if (u >= 1)
387 return 1;
388 /*
389 * Code taken from Cephes Math Library Release 2.8: June, 2000 Copyright 1984,
390 * 1996, 2000 by Stephen L. Moshier
391 */
392 final double MACHEP = 1.11022302462515654042E-16;
393 final double MAXLOG = 7.09782712893383996843E2;
394 final double MINLOG = -7.08396418532264106224E2;
395 // final double MAXNUM = 1.7976931348623158E308;
396
397 boolean ihalve = false;
398 boolean newt = false;
399
400 double p = 0, q = 0, y0 = 0, z = 0, y = 0, x = 0, x0, x1, lgm = 0, yp = 0, di = 0, dithresh = 0, yl, yh, xt = 0;
401 int i, dir;
402 boolean rflg, nflg;
403 x0 = 0.0;
404 yl = 0.0;
405 x1 = 1.0;
406 yh = 1.0;
407 nflg = false;
408 rflg = false;
409 if (alpha <= 1.0 || beta <= 1.0) {
410 dithresh = 1.0e-6;
411 rflg = false;
412 p = alpha;
413 q = beta;
414 y0 = u;
415 x = p / (p + q);
416 y = cdf(p, q, x);
417 ihalve = true;
418 } else
419 dithresh = 1.0e-4;
420
421 mainloop: while (true) {
422 if (ihalve) {
423 ihalve = false;
424 dir = 0;
425 di = 0.5;
426 for (i = 0; i < 100; i++) {
427 if (i != 0) {
428 x = x0 + di * (x1 - x0);
429 if (x == 1.0)
430 x = 1.0 - MACHEP;
431 if (x == 0.0) {
432 di = 0.5;
433 x = x0 + di * (x1 - x0);
434 if (x == 0.0) {
435 // System.err.println ("BetaDist.inverseF: underflow");
436 return 0;
437 }
438 }
439 y = cdf(p, q, x);
440 yp = (x1 - x0) / (x1 + x0);
441 if (Math.abs(yp) < dithresh) {
442 newt = true;
443 continue mainloop;
444 }
445 yp = (y - y0) / y0;
446 if (Math.abs(yp) < dithresh) {
447 newt = true;
448 continue mainloop;
449 }
450 }
451 if (y < y0) {
452 x0 = x;
453 yl = y;
454 if (dir < 0) {
455 dir = 0;
456 di = 0.5;
457 } else if (dir > 3)
458 di = 1.0 - (1.0 - di) * (1.0 - di);
459 else if (dir > 1)
460 di = 0.5 * di + 0.5;
461 else
462 di = (y0 - y) / (yh - yl);
463 dir += 1;
464 if (x0 > 0.75) {
465 // if (0 == y)
466 // y = EPS;
467 if (rflg) {
468 rflg = false;
469 p = alpha;
470 q = beta;
471 y0 = u;
472 } else {
473 rflg = true;
474 p = beta;
475 q = alpha;
476 y0 = 1.0 - u;
477 }
478 x = 1.0 - x;
479 y = cdf(p, q, x);
480 x0 = 0.0;
481 yl = 0.0;
482 x1 = 1.0;
483 yh = 1.0;
484 ihalve = true;
485 continue mainloop;
486 }
487 } else {
488 x1 = x;
489 if (rflg && x1 < MACHEP) {
490 x = 0.0;
491 break mainloop;
492 }
493 yh = y;
494 if (dir > 0) {
495 dir = 0;
496 di = 0.5;
497 } else if (dir < -3)
498 di = di * di;
499 else if (dir < -1)
500 di = 0.5 * di;
501 else
502 di = (y - y0) / (yh - yl);
503 dir -= 1;
504 }
505 }
506 // PLOSS error
507 if (x0 >= 1.0) {
508 x = 1.0 - MACHEP;
509 break mainloop;
510 }
511 if (x <= 0.0) {
512 // System.err.println ("BetaDist.inverseF: underflow");
513 return 0;
514 }
515 newt = true;
516 }
517 if (newt) {
518 newt = false;
519 if (nflg)
520 break mainloop;
521 nflg = true;
522 lgm = Num.lnGamma(p + q) - Num.lnGamma(p) - Num.lnGamma(q);
523
524 for (i = 0; i < 8; i++) {
525 /* Compute the function at this point. */
526 if (i != 0)
527 y = cdf(p, q, x);
528 if (y < yl) {
529 x = x0;
530 y = yl;
531 } else if (y > yh) {
532 x = x1;
533 y = yh;
534 } else if (y < y0) {
535 x0 = x;
536 yl = y;
537 } else {
538 x1 = x;
539 yh = y;
540 }
541 if (x >= 1.0 || x <= 0.0)
542 break;
543 /* Compute the derivative of the function at this point. */
544 z = (p - 1.0) * Math.log(x) + (q - 1.0) * Math.log1p(-x) + lgm;
545 if (z < MINLOG)
546 break mainloop;
547 if (z > MAXLOG)
548 break;
549 z = Math.exp(z);
550 /* Compute the step to the next approximation of x. */
551 z = (y - y0) / z;
552 xt = x - z;
553 if (xt <= x0) {
554 y = (x - x0) / (x1 - x0);
555 xt = x0 + 0.5 * y * (x - x0);
556 if (xt <= 0.0)
557 break;
558 }
559 if (xt >= x1) {
560 y = (x1 - x) / (x1 - x0);
561 xt = x1 - 0.5 * y * (x1 - x);
562 if (xt >= 1.0)
563 break;
564 }
565 x = xt;
566 if (Math.abs(z / x) < 128.0 * MACHEP)
567 break mainloop;
568 }
569 /* Did not converge. */
570 dithresh = 256.0 * MACHEP;
571 ihalve = true;
572 continue mainloop;
573 }
574
575 yp = -NormalDist.inverseF01(u);
576
577 if (u > 0.5) {
578 rflg = true;
579 p = beta;
580 q = alpha;
581 y0 = 1.0 - u;
582 yp = -yp;
583 } else {
584 rflg = false;
585 p = alpha;
586 q = beta;
587 y0 = u;
588 }
589
590 lgm = (yp * yp - 3.0) / 6.0;
591 x = 2.0 / (1.0 / (2.0 * p - 1.0) + 1.0 / (2.0 * q - 1.0));
592 z = yp * Math.sqrt(x + lgm) / x
593 - (1.0 / (2.0 * q - 1.0) - 1.0 / (2.0 * p - 1.0)) * (lgm + 5.0 / 6.0 - 2.0 / (3.0 * x));
594 z = 2.0 * z;
595 if (z < MINLOG) {
596 x = 1.0;
597 // System.err.println ("BetaDist.inverseF: underflow");
598 return 0;
599 }
600 x = p / (p + q * Math.exp(z));
601 y = cdf(p, q, x);
602 yp = (y - y0) / y0;
603 if (Math.abs(yp) < 0.2) {
604 newt = true;
605 continue mainloop;
606 }
607 ihalve = true;
608 }
609
610 // Done
611 if (rflg) {
612 if (x <= MACHEP)
613 x = 1.0 - MACHEP;
614 else
615 x = 1.0 - x;
616 }
617 return x;
618 }
619
624 public static double inverseF(double alpha, double beta, double u) {
625 return inverseF(alpha, beta, 12, u);
626 }
627
628 @Deprecated
629 public static double inverseF(double alpha, double beta, double a, double b, int d, double u) {
630 if (a >= b)
631 throw new IllegalArgumentException("a >= b");
632 return a + (b - a) * inverseF(alpha, beta, d, u);
633 }
634
640 public static double inverseF(double alpha, double beta, double a, double b, double u) {
641 if (a >= b)
642 throw new IllegalArgumentException("a >= b");
643 return a + (b - a) * inverseF(alpha, beta, u);
644 }
645
665 public static double[] getMLE(double[] x, int n) {
666 if (n <= 0)
667 throw new IllegalArgumentException("n <= 0");
668
669 double sum = 0.0;
670 double a = 0.0;
671 double b = 0.0;
672 for (int i = 0; i < n; i++) {
673 sum += x[i];
674 if (x[i] > 0.0)
675 a += Math.log(x[i]);
676 else
677 a -= 709.0;
678 if (x[i] < 1.0)
679 b += Math.log1p(-x[i]);
680 else
681 b -= 709.0;
682 }
683 double mean = sum / n;
684
685 sum = 0.0;
686 for (int i = 0; i < n; i++)
687 sum += (x[i] - mean) * (x[i] - mean);
688 double var = sum / (n - 1);
689
690 Optim system = new Optim(a, b);
691
692 double[] param = new double[3];
693 param[1] = mean * ((mean * (1.0 - mean) / var) - 1.0);
694 param[2] = (1.0 - mean) * ((mean * (1.0 - mean) / var) - 1.0);
695 double[] fvec = new double[3];
696 double[][] fjac = new double[3][3];
697 int[] info = new int[2];
698 int[] ipvt = new int[3];
699
700 Minpack_f77.lmder1_f77(system, 2, 2, param, fvec, fjac, 1e-5, info, ipvt);
701
702 double parameters[] = new double[2];
703 parameters[0] = param[1];
704 parameters[1] = param[2];
705
706 return parameters;
707 }
708
718 public static BetaDist getInstanceFromMLE(double[] x, int n) {
719 double parameters[] = getMLE(x, n);
720 return new BetaDist(parameters[0], parameters[1]);
721 }
722
730 public static double getMean(double alpha, double beta) {
731 return getMean(alpha, beta, 0.0, 1.0);
732 }
733
741 public static double getMean(double alpha, double beta, double a, double b) {
742 if (alpha <= 0.0)
743 throw new IllegalArgumentException("alpha <= 0");
744 if (beta <= 0.0)
745 throw new IllegalArgumentException("beta <= 0");
746
747 return (alpha * b + beta * a) / (alpha + beta);
748 }
749
759 public static double getVariance(double alpha, double beta) {
760 return getVariance(alpha, beta, 0.0, 1.0);
761 }
762
772 public static double getVariance(double alpha, double beta, double a, double b) {
773 if (alpha <= 0.0)
774 throw new IllegalArgumentException("alpha <= 0");
775 if (beta <= 0.0)
776 throw new IllegalArgumentException("beta <= 0");
777
778 return ((alpha * beta) * (b - a) * (b - a)) / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1));
779 }
780
787 public static double getStandardDeviation(double alpha, double beta) {
788 return Math.sqrt(BetaDist.getVariance(alpha, beta));
789 }
790
797 public static double getStandardDeviation(double alpha, double beta, double a, double b) {
798 return Math.sqrt(BetaDist.getVariance(alpha, beta, a, b));
799 }
800
804 public double getAlpha() {
805 return alpha;
806 }
807
811 public double getBeta() {
812 return beta;
813 }
814
818 public double getA() {
819 return a;
820 }
821
825 public double getB() {
826 return b;
827 }
828
832 public void setParams(double alpha, double beta, double a, double b) {
833 if (alpha <= 0.0)
834 throw new IllegalArgumentException("alpha <= 0");
835 if (beta <= 0.0)
836 throw new IllegalArgumentException("beta <= 0");
837 if (a >= b)
838 throw new IllegalArgumentException("a >= b");
839 this.alpha = alpha;
840 this.beta = beta;
841 supportA = this.a = a;
842 supportB = this.b = b;
843 bminusa = b - a;
844 double temp = Num.lnGamma(alpha);
845 if (alpha == beta)
846 temp *= 2.0;
847 else
848 temp += Num.lnGamma(beta);
849 logBeta = temp - Num.lnGamma(alpha + beta);
850 Beta = Math.exp(logBeta);
851// this.factor = 1.0 / (Beta * Math.pow (bminusa, alpha + beta - 1));
852 this.logFactor = -logBeta - Math.log(bminusa) * (alpha + beta - 1);
853 }
854
859 public double[] getParams() {
860 double[] retour = { alpha, beta, a, b };
861 return retour;
862 }
863
867 @Override
868 public String toString() {
869 return getClass().getSimpleName() + " : alpha = " + alpha + ", beta = " + beta;
870 }
871
872}
static double getVariance(double alpha, double beta, double a, double b)
Computes and returns the variance of the beta distribution with parameters and.
static double density(double alpha, double beta, double x)
Same as density(alpha,beta, 0, 1, x).
static double cdf(double alpha, double beta, double a, double b, double x)
Computes the distribution function.
static double barF(double alpha, double beta, double a, double b, double x)
Computes the complementary distribution function.
double getBeta()
Returns the parameter of this object.
static double getStandardDeviation(double alpha, double beta, double a, double b)
Computes the standard deviation of the beta distribution with parameters and , over the interval .
void setParams(double alpha, double beta, double a, double b)
Sets the parameters of the current distribution.
double inverseF(double u)
Returns the inverse distribution function .
double barF(double x)
Returns the complementary distribution function.
BetaDist(double alpha, double beta, double a, double b)
Constructs a BetaDist object with parameters alpha, beta and domain.
double cdf(double x)
Returns the distribution function .
double getAlpha()
Returns the parameter of this object.
double getB()
Returns the parameter of this object.
double getVariance()
Returns the variance.
static double getStandardDeviation(double alpha, double beta)
Computes the standard deviation of the beta distribution with parameters and , over the interval .
double getA()
Returns the parameter of this object.
static BetaDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a beta distribution with parameters.
double[] getParams()
Return an array containing the parameters of the current distribution as [ , , , ].
static double cdf(double alpha, double beta, double x)
Same as cdf(alpha, beta, 0,1, x).
static double density(double alpha, double beta, double a, double b, double x)
Computes the density function of the beta distribution.
static double inverseF(double alpha, double beta, double u)
Same as inverseF(alpha,beta, 0, 1, u).
String toString()
Returns a String containing information about the current distribution.
double density(double x)
Returns , the density evaluated at .
double getStandardDeviation()
Returns the standard deviation.
static double getVariance(double alpha, double beta)
Computes and returns the variance of the beta distribution with parameters and.
static double getMean(double alpha, double beta)
Computes and returns the mean of the beta distribution with parameters and , over the interval .
static double inverseF(double alpha, double beta, double a, double b, double u)
Returns the inverse beta distribution function using the algorithm implemented in imos00a .
static double barF(double alpha, double beta, double x)
Same as barF(alpha, beta, 0,1, x).
double getMean()
Returns the mean.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the beta distribution over the interval using the maximum likelihood me...
BetaDist(double alpha, double beta)
Constructs a BetaDist object with parameters alpha, beta and default domain .
static double getMean(double alpha, double beta, double a, double b)
Computes and returns the mean of the beta distribution with parameters.
Classes implementing continuous distributions should inherit from this base class.
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static double lnGamma(double x)
Returns the natural logarithm of the gamma function evaluated at x.
Definition Num.java:417
static double trigamma(double x)
Returns the value of the trigamma function , the derivative of the digamma function,...
Definition Num.java:532
static double lnBeta(double lam, double nu)
Computes the natural logarithm of the Beta function .
Definition Num.java:475
static double digamma(double x)
Returns the value of the logarithmic derivative of the Gamma function .
Definition Num.java:487