|
1 |
| -""" |
2 |
| -The probability of getting exactly n heads in m tossing. |
3 | 1 |
|
4 |
| -Algorithm Explanation: |
5 |
| -If you toss 0 time -> 0 head |
6 |
| -Distribution [1] -> Meaning: 1 in the 0-index |
7 | 2 |
|
8 |
| -If you toss 1 time -> 0 or 1 head |
9 |
| -Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes |
| 3 | +import numpy as np |
10 | 4 |
|
11 |
| -If you toss 2 times -> 0 to 2 heads |
12 |
| -Distribution [0.25 0.5 0.25] -> |
13 |
| -Meaning: probability of n heads from the distribution |
14 |
| -{HH, HT, TH, TT} |
15 | 5 |
|
16 |
| -If you toss 3 times -> 0 to 3 heads |
17 |
| -Distribution [0.125 0.375 0.375 0.125] -> |
18 |
| -Meaning: probability of n heads from the distribution |
19 |
| -{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT} |
| 6 | +def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int: |
| 7 | + """ |
| 8 | + The probability of getting exactly n heads in m tossing. |
20 | 9 |
|
21 |
| -Therefore, |
22 |
| -Probability_distribution(N+1) = |
23 |
| - [Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2 |
| 10 | + Algorithm Explanation: |
| 11 | + If you toss 0 time -> 0 head |
| 12 | + Distribution [1] -> Meaning: 1 in the 0-index |
24 | 13 |
|
25 |
| -I used that method in my paper |
26 |
| -Titled: Uncertainty-aware Decisions in Cloud Computing: |
27 |
| -Foundations and Future Directions |
28 |
| -Journal: ACM Computing Surveys (CSUR) |
29 |
| -""" |
| 14 | + If you toss 1 time -> 0 or 1 head |
| 15 | + Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes |
30 | 16 |
|
31 |
| -import numpy as np |
| 17 | + If you toss 2 times -> 0 to 2 heads |
| 18 | + Distribution [0.25 0.5 0.25] -> |
| 19 | + Meaning: probability of n heads from the distribution |
| 20 | + {HH, HT, TH, TT} |
32 | 21 |
|
| 22 | + If you toss 3 times -> 0 to 3 heads |
| 23 | + Distribution [0.125 0.375 0.375 0.125] -> |
| 24 | + Meaning: probability of n heads from the distribution |
| 25 | + {HHH, HHT, HTH, HTT, THH, THT, TTH, TTT} |
33 | 26 |
|
34 |
| -def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int: |
35 |
| - """ |
36 |
| - Calculate the factorial of specified number (n!). |
| 27 | + Therefore, |
| 28 | + Probability_distribution(N+1) = |
| 29 | + [Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2 |
| 30 | +
|
| 31 | + I used that method in my paper |
| 32 | + Titled: Uncertainty-aware Decisions in Cloud Computing: |
| 33 | + Foundations and Future Directions |
| 34 | + Journal: ACM Computing Surveys (CSUR) |
37 | 35 |
|
38 |
| - >>> import math |
39 |
| - >>> all(factorial(i) == math.factorial(i) for i in range(20)) |
40 |
| - True |
| 36 | + >>> import numpy as np |
41 | 37 | >>> Probability_of_n_heads_in_m_tossing(.2,.5)
|
42 | 38 | Traceback (most recent call last):
|
43 | 39 | ...
|
|
0 commit comments