001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.math3.distribution; 018 019import org.apache.commons.math3.exception.NumberIsTooLargeException; 020import org.apache.commons.math3.exception.OutOfRangeException; 021 022/** 023 * Interface for distributions on the integers. 024 * 025 */ 026public interface IntegerDistribution { 027 /** 028 * For a random variable {@code X} whose values are distributed according 029 * to this distribution, this method returns {@code P(X = x)}. In other 030 * words, this method represents the probability mass function (PMF) 031 * for the distribution. 032 * 033 * @param x the point at which the PMF is evaluated 034 * @return the value of the probability mass function at {@code x} 035 */ 036 double probability(int x); 037 038 /** 039 * For a random variable {@code X} whose values are distributed according 040 * to this distribution, this method returns {@code P(X <= x)}. In other 041 * words, this method represents the (cumulative) distribution function 042 * (CDF) for this distribution. 043 * 044 * @param x the point at which the CDF is evaluated 045 * @return the probability that a random variable with this 046 * distribution takes a value less than or equal to {@code x} 047 */ 048 double cumulativeProbability(int x); 049 050 /** 051 * For a random variable {@code X} whose values are distributed according 052 * to this distribution, this method returns {@code P(x0 < X <= x1)}. 053 * 054 * @param x0 the exclusive lower bound 055 * @param x1 the inclusive upper bound 056 * @return the probability that a random variable with this distribution 057 * will take a value between {@code x0} and {@code x1}, 058 * excluding the lower and including the upper endpoint 059 * @throws NumberIsTooLargeException if {@code x0 > x1} 060 */ 061 double cumulativeProbability(int x0, int x1) throws NumberIsTooLargeException; 062 063 /** 064 * Computes the quantile function of this distribution. 065 * For a random variable {@code X} distributed according to this distribution, 066 * the returned value is 067 * <ul> 068 * <li><code>inf{x in Z | P(X<=x) >= p}</code> for {@code 0 < p <= 1},</li> 069 * <li><code>inf{x in Z | P(X<=x) > 0}</code> for {@code p = 0}.</li> 070 * </ul> 071 * If the result exceeds the range of the data type {@code int}, 072 * then {@code Integer.MIN_VALUE} or {@code Integer.MAX_VALUE} is returned. 073 * 074 * @param p the cumulative probability 075 * @return the smallest {@code p}-quantile of this distribution 076 * (largest 0-quantile for {@code p = 0}) 077 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1} 078 */ 079 int inverseCumulativeProbability(double p) throws OutOfRangeException; 080 081 /** 082 * Use this method to get the numerical value of the mean of this 083 * distribution. 084 * 085 * @return the mean or {@code Double.NaN} if it is not defined 086 */ 087 double getNumericalMean(); 088 089 /** 090 * Use this method to get the numerical value of the variance of this 091 * distribution. 092 * 093 * @return the variance (possibly {@code Double.POSITIVE_INFINITY} or 094 * {@code Double.NaN} if it is not defined) 095 */ 096 double getNumericalVariance(); 097 098 /** 099 * Access the lower bound of the support. This method must return the same 100 * value as {@code inverseCumulativeProbability(0)}. In other words, this 101 * method must return 102 * <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 */ 107 int getSupportLowerBound(); 108 109 /** 110 * Access the upper bound of the support. This method must return the same 111 * value as {@code inverseCumulativeProbability(1)}. In other words, this 112 * method must return 113 * <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 */ 118 int getSupportUpperBound(); 119 120 /** 121 * Use this method to get information about whether the support is 122 * connected, i.e. whether all integers between the lower and upper bound of 123 * the support are included in the support. 124 * 125 * @return whether the support is connected or not 126 */ 127 boolean isSupportConnected(); 128 129 /** 130 * Reseed the random generator used to generate samples. 131 * 132 * @param seed the new seed 133 * @since 3.0 134 */ 135 void reseedRandomGenerator(long seed); 136 137 /** 138 * Generate a random value sampled from this distribution. 139 * 140 * @return a random value 141 * @since 3.0 142 */ 143 int sample(); 144 145 /** 146 * Generate a random sample from the distribution. 147 * 148 * @param sampleSize the number of random values to generate 149 * @return an array representing the random sample 150 * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException 151 * if {@code sampleSize} is not positive 152 * @since 3.0 153 */ 154 int[] sample(int sampleSize); 155}