-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatt_one_plus_two.py
50 lines (36 loc) · 1.19 KB
/
att_one_plus_two.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
def att_one_plus_two(cycle, hash_power_list):
result_list = []
theoretical_list = []
for p in hash_power_list:
q = 1 - p
rendement_val = rendement(cycle, p)
result_list.append(rendement_val)
rendement_thq = (3*p**3 + 4*q*p**2) / (q + 3*p**3 + 4*q*p**2 + 2*q**2*p)
theoretical_list.append(rendement_thq)
return result_list, theoretical_list
def rendement(cycle, p):
ER = 0
EH = 0
for _ in range(cycle):
R, H = block_simulation(p)
ER += R
EH += H
return ER/EH
def block_simulation(proba):
block1 = np.random.choice(('A','B'), p=[proba, 1-proba])
if (block1 =='A'): # A..
block2 = np.random.choice(('A','B'), p=[proba, 1-proba])
block3 = np.random.choice(('A','B'), p=[proba, 1-proba])
if(block2 =='A'): # AA.
if(block3 =='A'): # AAA
return 3, 3
else: # AAB
return 2, 2
else: # AB.
if(block3 =='A'): # ABA
return 2, 2
else: # ABB
return 0, 2
else: # B..
return 0, 1