29 lines
586 B
Python
Executable file
29 lines
586 B
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import numpy as np
|
|
|
|
|
|
p_s = [0.1,0.9]
|
|
P = np.random.rand(N)
|
|
X = [0 for p in P if p > p_s[0] else 1]
|
|
|
|
|
|
def binary(n,b=2,m):
|
|
"""
|
|
Convertie un nombre décimal en sa version binaire tronqué à m bits.
|
|
"""
|
|
return np.ceil(n*b**m)
|
|
|
|
def arithm(X):
|
|
l=[0]
|
|
h= [1]
|
|
for x in X:
|
|
if x == 0:
|
|
h.append(l[-1]+p_s[0]*(h[-1]-l[-1]))
|
|
l.append(l[-1])
|
|
else:
|
|
l.append(l[-1]+p_s[0]*(h[-1]-l[-1]))
|
|
h.append(h[-1])
|
|
|
|
lmb = (l[-1]+h[-1])/2
|
|
mu = int(-np.log2(h[-1]-l[-1]))+1
|