Commit 72b26dbb authored by Tobias Jörg Theodor Kempe's avatar Tobias Jörg Theodor Kempe
Browse files

adds tobi's first approach

parent ddf0eab3
Pipeline #462392 passed with stage
in 13 seconds
import numpy as np
import math
class ObservationStation:
def __init__(self, T):
self.T = T
def set_a(self, a):
self.a = a
def execute(self, phi, r):
c = math.cos(2 * (self.a - phi))
s = math.sin(2 * (self.a - phi))
x = np.sign(c)
t_star = r * self.T * s ** 2
return x, t_star
def generate_phis():
phi1 = np.random.rand() * 2 * np.pi
phi2 = phi1 + np.pi / 2
return phi1, phi2
def simulate():
M = 100
N = int(1e6)
a = np.array([0, 1/4, 1/8, 3/8]) * np.pi
W = 1
T = 1000
station = (ObservationStation(T), ObservationStation(T))
# conducts EPRB experiment M times
for _ in range(M):
results = np.zeros((N, 4, 2), dtype=np.int8)
# iterates through all pairs of settings
for p in range(4):
# selects a unique pair of settings from all possible settings
station[0].set_a(a[int(p/2)])
station[1].set_a(a[2+p%2])
# simulates 10^6 events
for n in range(N):
#if n%1000 == 0:
# print(p, n)
phi = generate_phis()
for s in range(2):
r = np.random.rand()
x, t_star = station[s].execute(phi[s], r)
results[n, p, s] = x
# alternative approach to simulating 10^6 events
# calculates absolute X
products = np.prod(results, axis=2)
products[:, 2] *= -1
sums = np.sum(products, axis=1)
X_abs = np.abs(sums)
if np.any(X_abs >= 2):
print(f'|X| <= 2 is violated with |x| = {X_abs.max()}')
else:
print(f'|X| <= 2 is satisfied with |x| = {X_abs.max()}')
simulate()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment