Home | History | Annotate | Download | only in distribution
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 package org.apache.commons.math.distribution;
     18 
     19 import org.apache.commons.math.MathException;
     20 
     21 /**
     22  * Interface for discrete distributions of integer-valued random variables.
     23  *
     24  * @version $Revision: 949535 $ $Date: 2010-05-30 19:00:15 +0200 (dim. 30 mai 2010) $
     25  */
     26 public interface IntegerDistribution extends DiscreteDistribution {
     27     /**
     28      * For a random variable X whose values are distributed according
     29      * to this distribution, this method returns P(X = x). In other words, this
     30      * method represents the probability mass function for the distribution.
     31      *
     32      * @param x the value at which the probability density function is evaluated.
     33      * @return the value of the probability density function at x
     34      */
     35     double probability(int x);
     36 
     37     /**
     38      * For a random variable X whose values are distributed according
     39      * to this distribution, this method returns P(X ≤ x).  In other words,
     40      * this method represents the probability distribution function, or PDF
     41      * for the distribution.
     42      *
     43      * @param x the value at which the PDF is evaluated.
     44      * @return PDF for this distribution.
     45      * @throws MathException if the cumulative probability can not be
     46      *            computed due to convergence or other numerical errors.
     47      */
     48     double cumulativeProbability(int x) throws MathException;
     49 
     50     /**
     51      * For this distribution, X, this method returns P(x0 ≤ X ≤ x1).
     52      * @param x0 the inclusive, lower bound
     53      * @param x1 the inclusive, upper bound
     54      * @return the cumulative probability.
     55      * @throws MathException if the cumulative probability can not be
     56      *            computed due to convergence or other numerical errors.
     57      * @throws IllegalArgumentException if x0 > x1
     58      */
     59     double cumulativeProbability(int x0, int x1) throws MathException;
     60 
     61     /**
     62      * For this distribution, X, this method returns the largest x such that
     63      * P(X &le; x) <= p.
     64      * <p>
     65      * Note that this definition implies: <ul>
     66      * <li> If there is a minimum value, <code>m</code>, with positive
     67      * probability under (the density of) X, then <code>m - 1</code> is
     68      * returned by <code>inverseCumulativeProbability(0).</code>  If there is
     69      * no such value <code>m,  Integer.MIN_VALUE</code> is
     70      * returned.</li>
     71      * <li> If there is a maximum value, <code>M</code>, such that
     72      * P(X &le; M) =1, then <code>M</code> is returned by
     73      * <code>inverseCumulativeProbability(1).</code>
     74      * If there is no such value, <code>M, Integer.MAX_VALUE</code> is
     75      * returned.</li></ul></p>
     76      *
     77      * @param p the cumulative probability.
     78      * @return the largest x such that P(X &le; x) <= p
     79      * @throws MathException if the inverse cumulative probability can not be
     80      *            computed due to convergence or other numerical errors.
     81      * @throws IllegalArgumentException if p is not between 0 and 1 (inclusive)
     82      */
     83     int inverseCumulativeProbability(double p) throws MathException;
     84 }
     85