FrediFizzx wrote:So I am still trying to decipher if your Python code is actually verifying the R code. You never answered my question about returning "z". I still don't understand that.
minkwe wrote:FrediFizzx wrote:So I am still trying to decipher if your Python code is actually verifying the R code. You never answered my question about returning "z". I still don't understand that.
First let us agree on what the essential mathematics of the model is, then we can ask the question whether the R/Python/Mathematica code correctly implements it or not. I don't understand how to "verify the R code" any other way. The model as expressed in my previous post is completely agnostic to the way the settings "a" and "b" are chosen. It could be random or sequential and it won't make a difference. If it appears to, then there is an error in the code.
minkwe wrote:Conceptually, it is much better to lay out the mathematics of the model first (independent of any implementation) before trying to implement it in code, rather than try to figure out from a piece of code what the model is. That is why its been difficult for me to follow. So here is my summary of my understanding so far of the goal of the model in http://rpubs.com/jjc/233477:
Source:
- generates a random 3D vector e
- generates a random number f, such that f = -1 + 2/sqrt(1+3s/pi), where s is a uniform random number in the range [0, pi)
Station:
- z = +1 for Alice, -1 for Bob
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate the dot product "a.e"
- calculate q = {|a.e| if |a.e| > f else 0}
- detector output = z*sign("a.e")*sign(q)
Is that your understanding of the model? Forget for a moment about specific implementations and their verification.
FrediFizzx wrote:Station:
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate the dot product "a.e" = c
- calculate polarizer = {+1 if |c|<pi else -1}
- calculate q = {cos(a*polarizer) if |c| > f else 0}
- detector output = sign(q)
Joy Christian wrote:minkwe wrote:FrediFizzx wrote:So I am still trying to decipher if your Python code is actually verifying the R code. You never answered my question about returning "z". I still don't understand that.
First let us agree on what the essential mathematics of the model is, then we can ask the question whether the R/Python/Mathematica code correctly implements it or not. I don't understand how to "verify the R code" any other way. The model as expressed in my previous post is completely agnostic to the way the settings "a" and "b" are chosen. It could be random or sequential and it won't make a difference. If it appears to, then there is an error in the code.
In this R code the function g = the function p x the function q. So it seems to me to be completely equivalent to this R code.
So how can there be an error? At least mathematically there can't be an error if we write g = p x q and use p x q instead of g.
***
p = function(u,v){colSums(u*v)} # polarizer function of Bell
q = function(u,v,s){ifelse(abs(p(u,v)) > f, cos(Angles), 0)}
g = function(u,v,s){p(u,v)*q(u,v,s)} # cf. http://rpubs.com/jjc/84238g = function(u,v,s){ifelse(abs(colSums(u*v)) > f, colSums(u*v), 0)}Station:
- z = +1 for Alice, -1 for Bob
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate the dot product "a.e"
- detector output = z*sign("a.e") if |a.e| > f else 0
Station:
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate the dot product "a.e" = c
- calculate polarizer = {+1 if |c|<pi else -1}
- calculate q = {cos(a*polarizer) if |c| > f else 0}
- detector output = sign(q)
minkwe wrote:FrediFizzx wrote:Station:
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate the dot product "a.e" = c
- calculate polarizer = {+1 if |c|<pi else -1}
- calculate q = {cos(a*polarizer) if |c| > f else 0}
- detector output = sign(q)
This makes no sense to me. What does "polarizer" mean physically? What do you think "a" and "b" represent? "c" is a cosine which means it ranges between -1 and +1. It will always be less than pi, so your "polarizer" will always be +1. In any case, the above is NOT what the code http://rpubs.com/jjc/233477 is doing. The cos(Angles) in the code is problematic. It can't be right.
FrediFizzx wrote:Oops, sorry. Right, c = |a - e| not cos(a - e). Let me try again.
Station:
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate |a - e| = c
- calculate polarizer = {+1 if c<pi else -1}
- calculate q = {cos(a*polarizer) if c > f else 0}
- detector output = sign(q)
IOW, we are just using the angle part of the vectors.
.
minkwe wrote:FrediFizzx wrote:Oops, sorry. Right, c = |a - e| not cos(a - e). Let me try again.
Station:
- setting "a" (or "b") is a 3D vector constrained to the XY plane
- calculate |a - e| = c
- calculate polarizer = {+1 if c<pi else -1}
- calculate q = {cos(a*polarizer) if c > f else 0}
- detector output = sign(q)
IOW, we are just using the angle part of the vectors.
.
This is a completely different model from the original one and not even the same as what Joy is doing in the new R-code. Not to mention that you are mixing 2D and 3D representations. "a" and "b" and "e" are vectors not angles.
minkwe wrote:
Joy, the devil is in the details.
- Code: Select all
p = function(u,v){colSums(u*v)} # polarizer function of Bell
q = function(u,v,s){ifelse(abs(p(u,v)) > f, cos(Angles), 0)}
g = function(u,v,s){p(u,v)*q(u,v,s)} # cf. http://rpubs.com/jjc/84238
vs
- Code: Select all
g = function(u,v,s){ifelse(abs(colSums(u*v)) > f, colSums(u*v), 0)}
Where is the "Angles" in "g"?
g = function(u,v,s){p(u,v)*q(u,v,s)}g = function(u,v,s){ifelse(abs(colSums(u*v)) > f, colSums(u*v), 0)}Angles = seq(from = 0, to = 360, by = 7.2) * 2 * pi/360
K = length(Angles) # The total number of angles between 0 and 2pi
corrs = matrix(nrow = K, ncol = K, data = 0) # Container for correlations
M = 10^4 # Size of the pre-ensemble. Next one can try 10^5, or even 10^6
r = runif(M, 0, 2*pi) # M uniformly distributed numbers between 0 and 2pi
z = runif(M, -1, +1) # M uniformly distributed numbers between -1 and +1
h = sqrt(1 - z^2)
x = h * cos(r)
y = h * sin(r)
e1 = rbind(x, y, z)
e2 = -e1
s = runif(M, 0, pi) # Initial states of the spins are the pairs (e, s) within S^3
f = -1 + (2/sqrt(1 + ((3 * s)/pi))) # For details see the paper arXiv:1405.2355
g1 = function(u1,v1){ifelse(abs(colSums(u1*v1)) > f, cos(Angles), 0)}
g2 = function(u2,v2){ifelse(abs(colSums(u2*v2)) > f, cos(Angles), 0)}
d = function(o,t){ifelse(2*acos(colSums(o*t)) < pi, 1, -1)}
for (i in 1:K) {
# i = 5
alpha = Angles[i]
a = c(cos(alpha), sin(alpha), 0) # Measurement direction 'a'
for (j in 1:K) {
# j = 23
beta = Angles[j]
b = c(cos(beta), sin(beta), 0) # Measurement direction 'b'
A = sign(d(a,e1)*(g1(a,e1))) # Alice's measurement results A(a, e, s) = +/-1
B = sign(d(b,e2)*(g2(b,e2))) # Bob's measurement results B(b, e, s) = -/+1
N = length((A*B)[A & B]) # Number of all possible events observed in S^3
corrs[i,j] = sum(A*B)/N # Product moment correlation coefficient E(a, b)
}
}
par(mar = c(0, 0, 2, 0))
persp(x = Angles, y = Angles, main = "The strong correlations predicted by the 3-sphere model", z = corrs, zlim = c(-1, 1), col = "pink", theta = 135, phi = 30, scale = FALSE, xlab = "alpha", ylab = "beta")minkwe wrote:Let me stick to 2D to see if I understand what this "new" model is:
Station:
- setting "a" (or "b") is a random angle between (0, 2pi), e is also an angle between (0, 2pi)
- calculate |a - e| = c
- calculate polarizer = {+1 if c<pi else -1}
- calculate q = {cos(a*polarizer) if c > f else 0}
- detector output = sign(q)
Is that the model?
Joy Christian wrote:If I use
- Code: Select all
g = function(u,v,s){p(u,v)*q(u,v,s)}
instead of
- Code: Select all
g = function(u,v,s){ifelse(abs(colSums(u*v)) > f, colSums(u*v), 0)}
in the original R code, then it runs just fine and produces the strong correlations.
***
q = function(u,v,s){ifelse(abs(p(u,v)) > f, cos(Angles), 0)}minkwe wrote:minkwe wrote:Let me stick to 2D to see if I understand what this "new" model is:
Station:
- setting "a" (or "b") is a random angle between (0, 2pi), e is also an angle between (0, 2pi)
- calculate |a - e| = c
- calculate polarizer = {+1 if c<pi else -1}
- calculate q = {cos(a*polarizer) if c > f else 0}
- detector output = sign(q)
Is that the model?
Fred could you confirm if the above is correct in 2D? In effect the polarizer calculation is
sign(pi-c)
If the above is correct, then I can do the 2D test of the exact model above in python. I prefer to go from a clear agreement of what the model is, rather than trying to read the R-code.
def particle_emitter():
e = numpy.random.uniform(0, 2*numpy.pi)
s = numpy.random.uniform(1, 4)
f = -1 + 2 / numpy.sqrt(s)
Pr = (e, f, 1) # Right particle
Pl = (e, f, -1) # Left particle
return Pl, Pr
def particle_detector(info):
"""Calculate and return the station outcome for the given `particle` and setting"""
particle, setting = info
a = setting
e, f, z = particle
c = abs(a-e)
pol = numpy.sign(numpy.pi - c)
q = numpy.cos(a*pol) if c > f else 0
out = z*numpy.sign(q)
return [0, setting,out]
minkwe wrote:Joy Christian wrote:If I use
- Code: Select all
g = function(u,v,s){p(u,v)*q(u,v,s)}
instead of
- Code: Select all
g = function(u,v,s){ifelse(abs(colSums(u*v)) > f, colSums(u*v), 0)}
in the original R code, then it runs just fine and produces the strong correlations.
***
The problem is with the q function. What is the meaning of "Angles" in that expression
- Code: Select all
q = function(u,v,s){ifelse(abs(p(u,v)) > f, cos(Angles), 0)}
u and v are unit vectors that change from one iteration to the next. s is a scalar, f is also a scalar. p is the dot product which is also a scalar, Angles is a vector of dimention 51 as defined earlier on the first line. What does cos(Angles) mean then??
(cos(Angles))
## [1] 1.00000000 0.99211470 0.96858316 0.92977649 0.87630668
## [6] 0.80901699 0.72896863 0.63742399 0.53582679 0.42577929
## [11] 0.30901699 0.18738131 0.06279052 -0.06279052 -0.18738131
## [16] -0.30901699 -0.42577929 -0.53582679 -0.63742399 -0.72896863
## [21] -0.80901699 -0.87630668 -0.92977649 -0.96858316 -0.99211470
## [26] -1.00000000 -0.99211470 -0.96858316 -0.92977649 -0.87630668
## [31] -0.80901699 -0.72896863 -0.63742399 -0.53582679 -0.42577929
## [36] -0.30901699 -0.18738131 -0.06279052 0.06279052 0.18738131
## [41] 0.30901699 0.42577929 0.53582679 0.63742399 0.72896863
## [46] 0.80901699 0.87630668 0.92977649 0.96858316 0.99211470
## [51] 1.00000000
minkwe wrote:As I expected, so for each iteration, the q function is returning the exact same thing when p > f. It is returning 51 numbers. So g= p*q will also be 51 numbers in those cases and also sign(q) will be 51 numbers some -1 other +1 and so will sign(p)*sign(q) etc. Do you see now that this cannot be correct?
minkwe wrote:As I expected, so for each iteration, the q function is returning the exact same thing when p > f. It is returning 51 numbers. So g= p*q will also be 51 numbers in those cases and also sign(q) will be 51 numbers some -1 other +1 and so will sign(p)*sign(q) etc. Do you see now that this cannot be correct?
FrediFizzx wrote:minkwe wrote:As I expected, so for each iteration, the q function is returning the exact same thing when p > f. It is returning 51 numbers. So g= p*q will also be 51 numbers in those cases and also sign(q) will be 51 numbers some -1 other +1 and so will sign(p)*sign(q) etc. Do you see now that this cannot be correct?
No it is not returning 51 numbers. It is 51 x 51 because the iterations are nested.
Return to Sci.Physics.Foundations
Users browsing this forum: No registered users and 135 guests
