Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4fd289f
Create Image_Classification_Example_MNIST_CNN.py
dipuk0506 Jun 10, 2024
29671f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
4e3484a
Update and rename Image_Classification_Example_MNIST_CNN.py to image_…
dipuk0506 Jun 11, 2024
7b70f64
Update image_classification_example_mnist_cnn.py
dipuk0506 Jun 11, 2024
a4b7330
Delete computer_vision/image_classification_example_mnist_cnn.py
dipuk0506 Jun 11, 2024
158c1fe
Create probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
d8b68ba
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
c49619c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
b62a774
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
707b446
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
df400a7
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
929301c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
b84ac59
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
b79e0c1
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
205cb87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
c987949
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 12, 2024
366f1ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
ac01ab0
Update probability_of_n_heads_in_m_tossing.py
dipuk0506 Jun 13, 2024
e4129b9
Update and rename probability_of_n_heads_in_m_tossing.py to outcome_o…
dipuk0506 Jun 14, 2024
00e2389
Update outcome_of_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
ce9e835
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
c7d9ea4
Update and rename outcome_of_rolling_n_sided_dice_k_time.py to sum_of…
dipuk0506 Jun 14, 2024
d8f511c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
fcf30bc
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
360ef80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
749499a
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
7bea0d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
164a51d
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
b8cb3bc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
ccf5053
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
5d23214
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
592c685
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
ea842d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
07d07bc
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
9c51e64
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
1dd86bc
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
f2d459a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
1b41f73
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
ca60090
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
cedf450
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
fa6c205
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 14, 2024
45f27b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
db15528
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 15, 2024
84787b5
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 15, 2024
1b7eb1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2024
f618200
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 15, 2024
752ed1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2024
f348aa0
Update sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
dipuk0506 Jun 15, 2024
ea0c141
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2024
c2d9ad3
Merge branch 'master' into master
cclauss Sep 14, 2026
a458148
updating DIRECTORY.md
cclauss Sep 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,17 @@
* [Loss Functions](machine_learning/loss_functions.py)
* Lstm
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
* [Mean Shift](machine_learning/mean_shift.py)
* [Mfcc](machine_learning/mfcc.py)
* [Mini Batch Gradient Descent](machine_learning/mini_batch_gradient_descent.py)
* [Multilayer Perceptron Classifier](machine_learning/multilayer_perceptron_classifier.py)
* [Naive Bayes Text Classification](machine_learning/naive_bayes_text_classification.py)
* [Polynomial Regression](machine_learning/polynomial_regression.py)
* [Principle Component Analysis](machine_learning/principle_component_analysis.py)
* [Q Learning](machine_learning/q_learning.py)
* [Random Forest Classifier](machine_learning/random_forest_classifier.py)
* [Random Forest Regressor](machine_learning/random_forest_regressor.py)
* [Rmsprop](machine_learning/rmsprop.py)
* [Scoring Functions](machine_learning/scoring_functions.py)
* [Self Organizing Map](machine_learning/self_organizing_map.py)
* [Sequential Minimum Optimization](machine_learning/sequential_minimum_optimization.py)
Expand All @@ -736,6 +739,7 @@
* [Arc Length](maths/arc_length.py)
* [Area](maths/area.py)
* [Area Under Curve](maths/area_under_curve.py)
* [Autocorrelation](maths/autocorrelation.py)
* [Average Absolute Deviation](maths/average_absolute_deviation.py)
* [Average Mean](maths/average_mean.py)
* [Average Median](maths/average_median.py)
Expand Down Expand Up @@ -781,6 +785,7 @@
* [Fibonacci](maths/fibonacci.py)
* [Find Max](maths/find_max.py)
* [Find Min](maths/find_min.py)
* [First Fundamental Form](maths/first_fundamental_form.py)
* [Floor](maths/floor.py)
* [Gamma](maths/gamma.py)
* [Gaussian](maths/gaussian.py)
Expand Down Expand Up @@ -843,6 +848,7 @@
* [Square Root](maths/numerical_analysis/square_root.py)
* [Weierstrass Method](maths/numerical_analysis/weierstrass_method.py)
* [Odd Sieve](maths/odd_sieve.py)
* [Padovan Sequence](maths/padovan_sequence.py)
* [Pell Number](maths/pell_number.py)
* [Perfect Cube](maths/perfect_cube.py)
* [Perfect Number](maths/perfect_number.py)
Expand Down Expand Up @@ -872,6 +878,8 @@
* [Reverse Factorial Recursive](maths/reverse_factorial_recursive.py)
* [Segmented Sieve](maths/segmented_sieve.py)
* Series
* [Alternate Harmonic Series](maths/series/alternate_harmonic_series.py)
* [Alternating Harmonic Series](maths/series/alternating_harmonic_series.py)
* [Arithmetic](maths/series/arithmetic.py)
* [Geometric](maths/series/geometric.py)
* [Geometric Series](maths/series/geometric_series.py)
Expand Down Expand Up @@ -911,6 +919,7 @@
* [Polygonal Numbers](maths/special_numbers/polygonal_numbers.py)
* [Pronic Number](maths/special_numbers/pronic_number.py)
* [Proth Number](maths/special_numbers/proth_number.py)
* [Spy Number](maths/special_numbers/spy_number.py)
* [Triangular Numbers](maths/special_numbers/triangular_numbers.py)
* [Trimorphic Number](maths/special_numbers/trimorphic_number.py)
* [Ugly Numbers](maths/special_numbers/ugly_numbers.py)
Expand All @@ -919,6 +928,7 @@
* [Sum Of Digits](maths/sum_of_digits.py)
* [Sum Of Geometric Progression](maths/sum_of_geometric_progression.py)
* [Sum Of Harmonic Series](maths/sum_of_harmonic_series.py)
* [Sum Of Outcomes For Rolling N Sided Dice K Time](maths/sum_of_outcomes_for_rolling_n_sided_dice_k_time.py)
* [Sumset](maths/sumset.py)
* [Sylvester Sequence](maths/sylvester_sequence.py)
* [Tanh](maths/tanh.py)
Expand Down
126 changes: 126 additions & 0 deletions maths/sum_of_outcomes_for_rolling_n_sided_dice_k_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import numpy as np


def outcome_of_rolling_n_sided_dice_k_time(n_side: int, k_time: int) -> float:
"""
The sum of outcomes for rolling an N-sided dice K times.

This function returns a list. The last two elements are the
range of probability distribution.
The range is: 'k_time' to 'k_time*n_side'

Other elements contain probabilities for getting a summation
from 'k_time' to 'k_time*n_side'.

Algorithm Explanation:

1. Explanation of range:
When we are rolling a six-sided dice the range becomes
1 to 6.
While rolling 5 times range becomes 5 to 30.
The sum outcomes become 5 when all rolling finds 1.
30 happens when all rolling finds 6.
1 is the minimum and 6 is the maximum of side values
for a 6 sided dice. Therefore, the range is 5 to 30.
Therefore, the range is k to n*k.

2. Explanation of probability distribution:
Say we are rolling a six-sided dice 2 times.
for 0 roll, the outcome is 0 with probability 1.
For the first roll, the outcome is 1 to 6 equally distributed.

For the second roll, each previous outcome (1-6) will face
an addition from the second rolling (1-6).
If the first outcome is (known) 3, then the probability of
getting each of 4 to 9 will be 1/6.

While rolling 2 dice simultaneously,
the sum becomes 2 for two 1 outcomes. But the sum becomes
3 for two different outcome combinations (1,2) and (2,1).
The probability of getting 2 is 1/6.
The probability of getting 3 is 2/6

Link to rolling two 6-sided dice combinations:
https://www.thoughtco.com/
probabilities-of-rolling-two-dice-3126559
That phenomenon is the same as the convolution.

The algorithm can be used in playing games or solving
problems where the sum of multiple dice throwing is needed.


NB: a) We are assuming a fair dice
b) Bernoulli's theory works with getting the probability of
exactly 3 sixes while rolling 5 times. It does not work directly
with the sum. The same sum can come in many combinations.
Finding all of those combinations and applying Bernoulli
is more computationally extensive.

I used that method in my paper to draw the distribution
Titled: Uncertainty-aware Decisions in Cloud Computing:
Foundations and Future Directions
Journal: ACM Computing Surveys (CSUR)
link: https://dl.acm.org/doi/abs/10.1145/3447583
The PDF version of the paper is available on Google Scholar.


>>> import numpy as np
>>> outcome_of_rolling_n_sided_dice_k_time(.2,.5)
Traceback (most recent call last):
...
ValueError: The function only accepts integer values
>>> outcome_of_rolling_n_sided_dice_k_time(-1,5)
Traceback (most recent call last):
...
ValueError: Side count should be more than 1
>>> outcome_of_rolling_n_sided_dice_k_time(3,-2)
Traceback (most recent call last):
...
ValueError: Roll count should be more than 0

>>> outcome_of_rolling_n_sided_dice_k_time(2,2)
array([0.25, 0.5 , 0.25, 2. , 4. ])
>>> outcome_of_rolling_n_sided_dice_k_time(2,4)
array([0.0625, 0.25 , 0.375 , 0.25 , 0.0625, 4. , 8. ])

"""

if n_side != int(n_side) or k_time != int(k_time):
raise ValueError("The function only accepts integer values")
if n_side < 2:
raise ValueError("Side count should be more than 1")
if k_time < 1:
raise ValueError("Roll count should be more than 0")
if k_time > 100 or n_side > 100:
raise ValueError("Limited to 100 sides or rolling to avoid memory issues")

prob_dist = 1
dist_step = np.ones(n_side, dtype=float) / n_side

iter1 = 0
while iter1 < k_time:
prob_dist = np.convolve(prob_dist, dist_step)
iter1 = iter1 + 1

prob_index = np.concatenate((prob_dist, np.array([k_time, k_time * n_side])))

return prob_index


"""
# Extra code for the verification

dist_index = outcome_of_rolling_n_sided_dice_k_time(6, 3)

the_range = range(int(dist_index[-2]), int(dist_index[-1]+1))
probabilities = dist_index[:-2]
print("Indexes:",the_range)

print("Distribution:",probabilities, "Their summation:",np.sum(probabilities))

import matplotlib.pyplot as plt
plt.bar(the_range, probabilities)
plt.xlabel("Summation of Outcomes")
plt.ylabel("Probabilities")

"""
Loading