1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.math.distribution;
17
18 import java.io.Serializable;
19
20 import org.apache.commons.math.MathException;
21
22 /**
23 * Base class for probability distributions.
24 *
25 * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
26 */
27 public abstract class AbstractDistribution
28 implements Distribution, Serializable {
29
30 /** Serializable version identifier */
31 private static final long serialVersionUID = -38038050983108802L;
32
33 /**
34 * Default constructor.
35 */
36 protected AbstractDistribution() {
37 super();
38 }
39
40 /**
41 * For a random variable X whose values are distributed according
42 * to this distribution, this method returns P(x0 ≤ X ≤ x1).
43 * <p>
44 * The default implementation uses the identity
45 * <p>
46 * P(x0 ≤ X ≤ x1) = P(X ≤ x1) - P(X ≤ x0)
47 *
48 * @param x0 the (inclusive) lower bound
49 * @param x1 the (inclusive) upper bound
50 * @return the probability that a random variable with this distribution
51 * will take a value between <code>x0</code> and <code>x1</code>,
52 * including the endpoints.
53 * @throws MathException if the cumulative probability can not be
54 * computed due to convergence or other numerical errors.
55 * @throws IllegalArgumentException if <code>x0 > x1</code>
56 */
57 public double cumulativeProbability(double x0, double x1)
58 throws MathException {
59 if (x0 > x1) {
60 throw new IllegalArgumentException
61 ("lower endpoint must be less than or equal to upper endpoint");
62 }
63 return cumulativeProbability(x1) - cumulativeProbability(x0);
64 }
65 }