|
1 |
| - |
2 | 1 | """
|
3 | 2 | Algorithm Explanation:
|
4 | 3 | If you toss 0 time -> 0 head
|
|
8 | 7 | Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
|
9 | 8 |
|
10 | 9 | If you toss 2 times -> 0 to 2 heads
|
11 |
| -Distribution [0.25 0.5 0.25] -> |
12 |
| -Meaning: probability of n heads from the distribution |
| 10 | +Distribution [0.25 0.5 0.25] -> |
| 11 | +Meaning: probability of n heads from the distribution |
13 | 12 | {HH, HT, TH, TT}
|
14 | 13 |
|
15 | 14 | If you toss 3 times -> 0 to 3 heads
|
16 |
| -Distribution [0.125 0.375 0.375 0.125] -> |
17 |
| -Meaning: probability of n heads from the distribution |
| 15 | +Distribution [0.125 0.375 0.375 0.125] -> |
| 16 | +Meaning: probability of n heads from the distribution |
18 | 17 | {HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
|
19 | 18 |
|
20 | 19 | Therefore,
|
21 |
| -Probability_distribution(N+1) = |
| 20 | +Probability_distribution(N+1) = |
22 | 21 | [Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
|
23 | 22 |
|
24 | 23 | I used that method in my paper
|
25 |
| -Titled: Uncertainty-aware Decisions in Cloud Computing: |
| 24 | +Titled: Uncertainty-aware Decisions in Cloud Computing: |
26 | 25 | Foundations and Future Directions
|
27 | 26 | Journal: ACM Computing Surveys (CSUR)
|
28 | 27 | """
|
29 | 28 |
|
30 |
| - |
31 | 29 | import numpy
|
32 | 30 |
|
| 31 | + |
33 | 32 | def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int:
|
34 | 33 | """
|
35 | 34 | Calculate the factorial of specified number (n!).
|
@@ -68,6 +67,6 @@ def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int
|
68 | 67 |
|
69 | 68 | for iter1 in range(toss_count):
|
70 | 69 | value = numpy.append(value, [0], axis=0) + numpy.append([0], value, axis=0)
|
71 |
| - value = value/2 |
| 70 | + value = value / 2 |
72 | 71 |
|
73 | 72 | return value[head_count]
|
0 commit comments