This repository presents functions in the Python programming language for computing probabilities of finding different numbers as the sum of outcomes for rolling an N-sided dice K times.
There are two functions. One is applicable for a fair dice with a uniform probability distribution. Another is applicable for both fair and unfair dice.
The following function takes the number of sides and the number of rolling as input and returns probabilities with the range of indexes.
The following function takes the probabilities of getting different sides and the number of rolling as input and returns probabilities with the range of indexes.
This function requires an array as the first input. However, this function can compute probabilities for unfair dice. In an unfair dice, the probabilities of getting different sides are different.
I have also submitted a pull request to a repository to share the function with a larger audience. The request: TheAlgorithms/Python#11463
We are applying the digital convolution equation [2].
If
If indexes of
Value at
In this equation,
Shortly,
Suppose we are rolling two N-sided dice simultaneously. The possible outcomes for one dice is 1 to N. Each of one to N outcomes has a probability of 1/N.
Write probabilities as an array: [1/N, 1/N, 1/N.......(N-elements)]
Indexes of probabilities:[1, 2, 3, ...........N]
The possible summation of outcomes can be 2 to 2N. The summation is 2 when the outcomes from both dice are 1. The summation is 2N when the outcomes from both dice are N. Therefore, the range follows the rule of convolution.
The summation of indexes is 2 when both dice receive 1. The (1,1) combination.
The probability of summation of 2 becomes the multiplication of two probabilities: (1/N) and (1/N).
The summation becomes 3 for (1,2) and (2,1) combinations.
Probabilities: (1/N)
Total probability of getting three as summation: 2
The summation becomes 4 for (1,3), (2,2), and (3,1) combinations; when N is greater than or equal to 3.
The probability: 3
The summation becomes 7 for (1,6), (2,5), (3,4), (4,3), (5,2), and (6,1) combinations; when N is greater than or equal to 6.
The probability: 6
If N is 4, the summation becomes 7 for (3,4), and (4,3) combinations.
The probability: 2
The summation becomes 2
The summation becomes 2
Therefore, we can get the probability of getting a sum using the convolution for two dice throwing.
Let's write the probability distribution of getting different summations for two dice throwing as follows:
The array of probability: [p2, p3, p4, ... p2N]
Indexes of probabilities: [2, 3, ..........,2N]
Suppose we are rolling another N-sided dice simultaneously with the previous two dice.
The range of probable summations will be 3 to 3
The summation becomes 3 for (1, 1, 1) combination. Which is equal to the probability of getting as sum 2 in the first two rolls and 1 in the third; the (
That probability is p2
The summation becomes 4 for (
The probability becomes p2
Similarly, for all probable summation values (S), we found the following pattern:
Array1[index] is multiplied by Array2[S-index]
All multiplications are added to compute the probability of getting S as the sum.
Similarly, we can continue convoluting to obtain summation probabilities for more dice rolling.
Let us assume the third dice has M number of sides with non-uniform probability.
Let us assume probabilities are [q1, q2, q3, .... qM]
Indexes of probabilities: [1, 2, 3, ...........,M]
The range of getting different summation values is 3 to 2N+M.
The probability of getting 3 as summation is p2
The probability of getting 4 as summation is p2
Therefore, when dice rolling is mixed with fair and unfair dice, the convolution can still compute the probability distribution.
Similarly, the convolution works with a k-number of unfair dice rolling.
We used this approach to draw figures and write discussions in papers [1, 3].
[1] Kabir, HM Dipu, et al. "Uncertainty-aware decisions in cloud computing: Foundations and future directions." ACM Computing Surveys (CSUR) 54.4 (2021): 1-30.
[2] Smith, S. W. "Convolution." The scientist and engineer's guide to digital signal processing, Chapter 6 (1997): 107-122.
[3] Kabir, HM Dipu, et al. "Partial adversarial training for neural network-based uncertainty quantification." IEEE Transactions on Emerging Topics in Computational Intelligence 5.4 (2019): 595-606.