Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. """ Main Codes """
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5.  
  6. lamb = 0.0005 # the rate
  7. pi = np.pi # pi = 3.14...
  8. r = 200 # the radius of the circle C
  9. mean = lamb * pi * r ** 2 # the mean of the Poisson random variable n
  10. n = np.random.poisson(mean) # the Poisson random variable (i.e., the number of points inside C)
  11. u_1 = np.random.uniform(0.0, 1.0, n) # generate n uniformly distributed points
  12. radii = np.zeros(n) # the radial coordinate of the points
  13. for i in range(n):
  14. radii[i] = r * (np.sqrt(u_1[i]))
  15. u_2 = np.random.uniform(0.0, 1.0, n) # generate another n uniformly distributed points
  16. angle = np.zeros(n) # the angular coordinate of the points
  17. for i in range(n):
  18. angle[i] = 2 * pi * u_2[i]
  19.  
  20. """ Plots """
  21. fig = plt.gcf()
  22. ax = fig.gca()
  23. plt.xlim(-300, 300)
  24. plt.ylim(-300, 300)
  25. circ = plt.Circle((0, 0), radius=200, color='r', linewidth=2, fill=False)
  26. plt.polar(angle, radii, 'bo')
  27. ax.add_artist(circ)
  28. plt.show()
  29.  
  30. # Cartesian Coordinates
  31. x = np.zeros(n)
  32. y = np.zeros(n)
  33. for i in range(n):
  34. x[i] = radii[i] * np.cos(angle[i])
  35. y[i] = radii[i] * np.sin(angle[i])
  36.  
  37. plt.plot(x,y,'bo')
  38.  
  39. import numpy as np
  40. import scipy.stats
  41. import matplotlib.pyplot as plt
  42.  
  43. #Simulation window parameters
  44. r=1;
  45. xx0=0; yy0=0; #centre of disk
  46.  
  47. areaTotal=np.pi*r**2; #area of disk
  48.  
  49. #Point process parameters
  50. lambda0=100; #intensity (ie mean density) of the Poisson process
  51.  
  52. #Simulate Poisson point process
  53. numbPoints = scipy.stats.poisson( lambda0*areaTotal ).rvs()#Poisson number of points
  54. theta = 2*np.pi*scipy.stats.uniform.rvs(0,1,((numbPoints,1)))#angular coordinates of Poisson points
  55. rho = r*np.sqrt(scipy.stats.uniform.rvs(0,1,((numbPoints,1))))#radial coordinates of Poisson points
  56.  
  57. #Convert from polar to Cartesian coordinates
  58. xx = rho * np.cos(theta)
  59. yy = rho * np.sin(theta)
  60.  
  61. #Shift centre of disk to (xx0,yy0)
  62. xx=xx+xx0; yy=yy+yy0;
  63.  
  64. #Plotting
  65. plt.scatter(xx,yy, edgecolor='b', facecolor='none', alpha=0.5 )
  66. plt.xlabel("x"); plt.ylabel("y")
  67. plt.axis('equal')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement