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

applies a few fixes

parent 324727cd
Pipeline #466525 passed with stage
in 59 seconds
...@@ -132,15 +132,17 @@ for j in range(n_configs): ...@@ -132,15 +132,17 @@ for j in range(n_configs):
# 1. as expected # 1. as expected
# 2. from simulation results # 2. from simulation results
plot_i = 1
# correlation # correlation
phi = np.linspace(0, 360, n_configs) phi = np.linspace(0, 360/n_configs*(n_configs-1), n_configs)
phi_theory = np.linspace(0, 360, n_configs*100) phi_theory = np.linspace(0, 360/n_configs*(n_configs-1), n_configs*100)
theory = -np.cos(2 * phi_theory * (2 * np.pi / 360)) theory = -np.cos(2 * phi_theory * (2 * np.pi / 360))
plt.figure() plt.figure()
plt.xlabel(r'$\Delta \varphi$') plt.xlabel(r'$\Delta \varphi$')
plt.ylabel(r'$<x_1 x_2>$') plt.ylabel(r'$<x_1 x_2>$')
plt.plot(phi_theory, theory, '.', markersize=1, color='orange') plt.plot(phi_theory, theory, '.', markersize=1, color='orange')
plt.plot(phi, E_12[0, :], 'o', color='blue') plt.plot(phi, E_12[plot_i, :], 'o', color='blue')
plt.savefig('correlation.pdf') plt.savefig('correlation.pdf')
if showPlots: if showPlots:
plt.show() plt.show()
...@@ -154,7 +156,7 @@ plt.ylabel(r'$<x_1><x_2>$') ...@@ -154,7 +156,7 @@ plt.ylabel(r'$<x_1><x_2>$')
plt.ylim([-1, 1]) plt.ylim([-1, 1])
plt.xticks([0, 45, 90, 135, 180, 225, 270, 305, 360]) plt.xticks([0, 45, 90, 135, 180, 225, 270, 305, 360])
plt.plot(phi_theory, line, '.', markersize=1, color='orange') plt.plot(phi_theory, line, '.', markersize=1, color='orange')
plt.plot(phi, E_1[0, :]*E_2[0, :], 'o', color='blue') plt.plot(phi, E_1[plot_i, :]*E_2[plot_i, :], 'o', color='blue')
plt.savefig('expectation_value.pdf') plt.savefig('expectation_value.pdf')
if showPlots: if showPlots:
plt.show() plt.show()
......
...@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt ...@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt
import time import time
# settings # settings
N = int(1e6) N = int(100000)
T_0 = 1000 T_0 = 1000
W = 1 W = 1
showPlots = True showPlots = True
...@@ -16,14 +16,11 @@ def simulate(phi1, phi2): ...@@ -16,14 +16,11 @@ def simulate(phi1, phi2):
thetas[:, 0] = np.random.rand(N) * 2 * np.pi thetas[:, 0] = np.random.rand(N) * 2 * np.pi
thetas[:, 1] = thetas[:, 0] + np.pi / 2 thetas[:, 1] = thetas[:, 0] + np.pi / 2
# generate random number for timestamp
rs = np.random.rand(N)
# calculate outcome of observation station # calculate outcome of observation station
x1 = (np.cos(2 * (phi1 - thetas[:, 0])) >= (2*np.random.rand(N) -1)).reshape(N, 1) x1 = (np.cos(2 * (phi1 - thetas[:, 0])) >= (2*np.random.rand(N) -1)).reshape(N, 1)
t1 = T_0 * rs * np.sin(2 * (phi1 - thetas[:, 0])) ** 2 t1 = T_0 * np.random.rand(N) * np.sin(2 * (phi1 - thetas[:, 0])) ** 4
x2 = (np.cos(2 * (phi2 - thetas[:, 1])) >= (2*np.random.rand(N) -1)).reshape(N, 1) x2 = (np.cos(2 * (phi2 - thetas[:, 1])) >= (2*np.random.rand(N) -1)).reshape(N, 1)
t2 = T_0 * rs * np.sin(2 * (phi2 - thetas[:, 1])) ** 2 t2 = T_0 * np.random.rand(N) * np.sin(2 * (phi2 - thetas[:, 1])) ** 4
# determine which events are conincidences (1) and which not (0) # determine which events are conincidences (1) and which not (0)
coincidences = np.abs(t1 - t2) < W coincidences = np.abs(t1 - t2) < W
...@@ -38,10 +35,10 @@ def simulate(phi1, phi2): ...@@ -38,10 +35,10 @@ def simulate(phi1, phi2):
counts[0, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1), axis=0) counts[0, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1), axis=0)
counts[0, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1), axis=0) counts[0, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1), axis=0)
counts[1, 0] = np.sum(np.all(x1x2 == np.array([0, 0]), axis=1) == coincidences, axis=0) counts[1, 0] = np.sum(np.logical_and(np.all(x1x2 == np.array([0, 0]), axis=1), coincidences), axis=0)
counts[1, 1] = np.sum(np.all(x1x2 == np.array([0, 1]), axis=1) == coincidences, axis=0) counts[1, 1] = np.sum(np.logical_and(np.all(x1x2 == np.array([0, 1]), axis=1), coincidences), axis=0)
counts[1, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1) == coincidences, axis=0) counts[1, 2] = np.sum(np.logical_and(np.all(x1x2 == np.array([1, 0]), axis=1), coincidences), axis=0)
counts[1, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1) == coincidences, axis=0) counts[1, 3] = np.sum(np.logical_and(np.all(x1x2 == np.array([1, 1]), axis=1), coincidences), axis=0)
E_all = np.sum(counts, axis=1).astype(float) E_all = np.sum(counts, axis=1).astype(float)
E_12 = (counts[:, 0] - counts[:, 1] - counts[:, 2] + counts[:, 3]).astype(float) E_12 = (counts[:, 0] - counts[:, 1] - counts[:, 2] + counts[:, 3]).astype(float)
...@@ -70,15 +67,10 @@ def try_all_configs(n_configs): ...@@ -70,15 +67,10 @@ def try_all_configs(n_configs):
E_12[i, :] = E_12_ E_12[i, :] = E_12_
E_1[i, :] = E_1_ E_1[i, :] = E_1_
E_2[i, :] = E_2_ E_2[i, :] = E_2_
x = np.linspace(0, 360, n_configs)
plt.figure()
plt.plot(x, E_12[:, 0])
plt.show()
# correlation # correlation
phi = np.linspace(0, 360, n_configs) phi = np.linspace(0, 360/n_configs*(n_configs-1), n_configs)
phi_theory = np.linspace(0, 360, n_configs*100) phi_theory = np.linspace(0, 360/n_configs*(n_configs-1), n_configs*100)
theory = -np.cos(2 * phi_theory * (2 * np.pi / 360)) theory = -np.cos(2 * phi_theory * (2 * np.pi / 360))
plt.figure() plt.figure()
plt.xlabel(r'$\Delta \varphi$') plt.xlabel(r'$\Delta \varphi$')
...@@ -104,6 +96,34 @@ def try_all_configs(n_configs): ...@@ -104,6 +96,34 @@ def try_all_configs(n_configs):
plt.show() plt.show()
plt.close() plt.close()
# correlation
phi = np.linspace(0, 360/n_configs*(n_configs-1), n_configs)
phi_theory = np.linspace(0, 360/n_configs*(n_configs-1), n_configs*100)
theory = -np.cos(2 * phi_theory * (2 * np.pi / 360))
plt.figure()
plt.xlabel(r'$\Delta \varphi$')
plt.ylabel(r'$<x_1 x_2>$')
plt.plot(phi_theory, theory, '.', markersize=1, color='orange')
plt.plot(phi, E_12[:, 1], 'o', color='blue')
#plt.savefig('correlation.pdf')
if showPlots:
plt.show()
plt.close()
# product of expectation values
line = np.zeros(phi_theory.shape)
plt.figure()
plt.xlabel(r'$\Delta \varphi$')
plt.ylabel(r'$<x_1><x_2>$')
plt.ylim([-1, 1])
plt.xticks([0, 45, 90, 135, 180, 225, 270, 305, 360])
plt.plot(phi_theory, line, '.', markersize=1, color='orange')
plt.plot(phi, E_1[:, 1]*E_2[:, 1], 'o', color='blue')
#plt.savefig('expectation_value.pdf')
if showPlots:
plt.show()
plt.close()
start = time.time() start = time.time()
try_all_configs(32) try_all_configs(32)
duration = time.time() - start duration = time.time() - start
......
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