-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path643.py
More file actions
35 lines (33 loc) · 825 Bytes
/
643.py
File metadata and controls
35 lines (33 loc) · 825 Bytes
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
import math
import numpy as np
T = 1000
N = 10000
P = 0.5
S = 0.1
A = []
R = 0.0
Cn = 0.0
for k in range(0,T):
C = 1.0
X = np.random.binomial(1,P,size=N)
for i in range(3,N):
Pn = np.mean(X[:i])
#In = math.sqrt(math.log(2/S)/(2*i)) #a)
#In = math.sqrt((math.log(i*(i+1))+math.log(2/S))/(2*i)) #b)
In = math.sqrt((math.log(math.log(i))+math.log(2/S))/(2*i)) #c)
Lo = Pn-In
Hi = Pn+In
print(Lo, Hi)
if abs(Pn-P) > In:
C = 0.0
break
Cn = Cn+C
#A.append(C/i)
print "Count: %.4f" % (Cn)
print "Proportion: %.4f" % (Cn/T)
#print "Max.Proportion: %.4f" % (max(A))
#print "Min.Proportion: %.4f" % (min(A))
#print "Avg.Proportion: %.4f" % (sum(A)/len(A))
#print "Len.of A: %.4f" % (len(A))
#print "Number of times (out of %i) all intervals contained P=1/2: %i" % (T,R)
#print "Proportion: %.4f" % (R/T)