1/*2* Licensed to the Apache Software Foundation (ASF) under one or more3* contributor license agreements. See the NOTICE file distributed with4* this work for additional information regarding copyright ownership.5* The ASF licenses this file to You under the Apache License, Version 2.06* (the "License"); you may not use this file except in compliance with7* the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* 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 and15* limitations under the License.16*/17packageorg.apache.commons.math3.distribution; 18 19importorg.apache.commons.math3.exception.NumberIsTooLargeException; 20importorg.apache.commons.math3.exception.OutOfRangeException; 21 22/**23* Interface for distributions on the integers.24*25*/26publicinterfaceIntegerDistribution { 27/**28* For a random variable {@code X} whose values are distributed according29* to this distribution, this method returns {@code P(X = x)}. In other30* words, this method represents the probability mass function (PMF)31* for the distribution.32*33* @param x the point at which the PMF is evaluated34* @return the value of the probability mass function at {@code x}35*/36doubleprobability(intx); 37 38/**39* For a random variable {@code X} whose values are distributed according40* to this distribution, this method returns {@code P(X <= x)}. In other41* words, this method represents the (cumulative) distribution function42* (CDF) for this distribution.43*44* @param x the point at which the CDF is evaluated45* @return the probability that a random variable with this46* distribution takes a value less than or equal to {@code x}47*/48doublecumulativeProbability(intx); 49 50/**51* For a random variable {@code X} whose values are distributed according52* to this distribution, this method returns {@code P(x0 < X <= x1)}.53*54* @param x0 the exclusive lower bound55* @param x1 the inclusive upper bound56* @return the probability that a random variable with this distribution57* will take a value between {@code x0} and {@code x1},58* excluding the lower and including the upper endpoint59* @throws NumberIsTooLargeException if {@code x0 > x1}60*/61doublecumulativeProbability(intx0,intx1)throwsNumberIsTooLargeException; 62 63/**64* Computes the quantile function of this distribution.65* For a random variable {@code X} distributed according to this distribution,66* the returned value is67* <ul>68* <li><code>inf{x in Z | P(X<=x) >= p}</code> for {@code 0 < p <= 1},</li>69* <li><code>inf{x in Z | P(X<=x) > 0}</code> for {@code p = 0}.</li>70* </ul>71* If the result exceeds the range of the data type {@code int},72* then {@code Integer.MIN_VALUE} or {@code Integer.MAX_VALUE} is returned.73*74* @param p the cumulative probability75* @return the smallest {@code p}-quantile of this distribution76* (largest 0-quantile for {@code p = 0})77* @throws OutOfRangeException if {@code p < 0} or {@code p > 1}78*/79intinverseCumulativeProbability(doublep)throwsOutOfRangeException; 80 81/**82* Use this method to get the numerical value of the mean of this83* distribution.84*85* @return the mean or {@code Double.NaN} if it is not defined86*/87doublegetNumericalMean(); 88 89/**90* Use this method to get the numerical value of the variance of this91* distribution.92*93* @return the variance (possibly {@code Double.POSITIVE_INFINITY} or94* {@code Double.NaN} if it is not defined)95*/96doublegetNumericalVariance(); 97 98/**99* Access the lower bound of the support. This method must return the same100* value as {@code inverseCumulativeProbability(0)}. In other words, this101* method must return102* <p><code>inf {x in Z | P(X <= x) > 0}</code>.</p>103*104* @return lower bound of the support ({@code Integer.MIN_VALUE}105* for negative infinity)106*/107intgetSupportLowerBound(); 108 109/**110* Access the upper bound of the support. This method must return the same111* value as {@code inverseCumulativeProbability(1)}. In other words, this112* method must return113* <p><code>inf {x in R | P(X <= x) = 1}</code>.</p>114*115* @return upper bound of the support ({@code Integer.MAX_VALUE}116* for positive infinity)117*/118intgetSupportUpperBound(); 119 120/**121* Use this method to get information about whether the support is122* connected, i.e. whether all integers between the lower and upper bound of123* the support are included in the support.124*125* @return whether the support is connected or not126*/127booleanisSupportConnected(); 128 129/**130* Reseed the random generator used to generate samples.131*132* @param seed the new seed133* @since 3.0134*/135voidreseedRandomGenerator(longseed); 136 137/**138* Generate a random value sampled from this distribution.139*140* @return a random value141* @since 3.0142*/143intsample(); 144 145/**146* Generate a random sample from the distribution.147*148* @param sampleSize the number of random values to generate149* @return an array representing the random sample150* @throws org.apache.commons.math3.exception.NotStrictlyPositiveException151* if {@code sampleSize} is not positive152* @since 3.0153*/154int[] sample(intsampleSize); 155 }