Skip to content

Instantly share code, notes, and snippets.

@unrealwill
Created May 26, 2021 21:39
Show Gist options
  • Save unrealwill/2a48ea0926deac4011d26842627b69c9 to your computer and use it in GitHub Desktop.
Save unrealwill/2a48ea0926deac4011d26842627b69c9 to your computer and use it in GitHub Desktop.
import numpy as np
def cosd( ang ):
return np.cos(2*np.pi*ang/360.0)
def sind( ang):
return np.sin(2*np.pi*ang/360.0)
def measure3( alpha, phi, r1,r2):
d = 2
Vmax = 10
Vmin = 0
V = -9.99
c = cosd(2*(alpha-phi))
s = sind(2*(alpha-phi))
x = np.sign( 1 + c - 2 *r1)
v = r2 * np.power(np.abs(s) ,d)*(Vmax-Vmin)-Vmax
sel = ( v < V).astype(np.float32)
return x,v,sel
def test3():
nb = 20000000
#We work in degrees
phi = np.random.rand(nb) * 360.0
#phi = np.ones((nb))*90
phi2 = phi + 90.0
ra1 = np.random.rand(nb)
ra2 = np.random.rand(nb)
rb1 = np.random.rand(nb)
rb2 = np.random.rand(nb)
alpha = 0
beta = 90
xa,va,sela = measure3(alpha,phi,ra1,ra2)
xb,vb,selb = measure3(beta,phi2,rb1,rb2)
print(np.mean( (xa+1.0) /2.0))
sidebyside = np.stack( [xa,xb,sela,selb],axis=1)
selected = sidebyside[ np.logical_and( sidebyside[:,2]==1.0,sidebyside[:,3]==1.0) ,0:2]
coincmean = np.mean( selected[:,0] == selected[:,1] )
print(sidebyside)
print(selected)
print( "nbselected : ")
print( selected.shape[0])
print("coincmean ")
print(coincmean)
print("target")
print( 1-cosd(alpha-beta)**2)
if __name__=="__main__":
test3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment