-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW4 Python.txt
149 lines (111 loc) · 3.33 KB
/
HW4 Python.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# In this exercise we shall simulate the two-dimensional Poisson process (Poisson Point Process
# in the plane and its subsets such as a square and a disc).
# (a) In the setup of the above Problem (1) simulate the two-dimensional Poisson process in the
# rectangle region [-1, 1] x [-1, 1] . Choose Lambda appropriately.
# (b) Simulate the two-dimensional Poisson process in a circular region (disc) of radius 1 and
# of center at the origin (0, 0) .
# Simulate once again the two-dimensional Poisson process now on the whole plane, and
# let Ri denote the distance between the origin (0, 0) and its i -th nearest Poisson point for i = 1, 2, . . .
# (c) Estimate the cumulative distribution function F(x) := P(R1 <= x) of R1 for every
# 0 <= x <= c1 (cf. section 11.5.2) and plot the function F(.) for 0 <= x <- c1 , where c1 is
# chosen large enough to represent the whole shape of the function F(.) .
# (d) Estimate the tail probability Gn(x) := P(Rn > x) for x > 0 , 0 <= x <= c2 , where c2 is
# chosen large enough to represent the whole shape of function Gn(.) for n = 1, 2, 3, 4 . Plot
# the function Gn(.) for n = 1, 2, 3, 4 in the same graph.
import numpy
### PART A ###
n = numpy.random.poisson(120)
pointList = []
for i in range(0,n):
x = numpy.random.uniform(-1,1)
y = numpy.random.uniform(-1,1)
pointList.append([x,y])
print("Part A:")
print("")
for i in pointList:
print(i[0], ", ", i[1])
print("")
### PART B ###
n = numpy.random.poisson(120)
pointList = []
for i in range(0,n):
radius = numpy.random.uniform(0,1)
angle = numpy.random.uniform(0,2*numpy.pi)
pointList.append([radius*numpy.cos(angle), radius*numpy.sin(angle)])
print("Part B:")
print("")
for i in pointList:
print(i[0], ", ", i[1])
print("")
### PART C ###
n = numpy.random.poisson(480)
print(n)
pointList = []
for i in range(0,n):
x = numpy.random.uniform(-2,2)
y = numpy.random.uniform(-2,2)
pointList.append((x**2 + y**2)**.5)
pointList.sort()
print("Part C:")
print("")
for x in range(0,100):
lowest = 0
for i in pointList:
if(i <= x/35):
lowest += 1
print(x/35, ", ", lowest/len(pointList))
print("")
### PART D ###
low1List = []
low2List = []
low3List = []
low4List = []
for i in range(0,100):
n = numpy.random.poisson(480)
pointList = []
for j in range(0,n):
x = numpy.random.uniform(-2,2)
y = numpy.random.uniform(-2,2)
pointList.append((x**2 + y**2)**.5)
pointList.sort()
low1List.append(pointList[0])
low2List.append(pointList[1])
low3List.append(pointList[2])
low4List.append(pointList[3])
print("Part D:")
print("")
print("G_1:")
print("")
for x in range(0,100):
s_1 = 0
for i in low1List:
if(i > x/300):
s_1 += 1
print(x/300, ", ", s_1/100)
print("")
print("G_2:")
print("")
for x in range(0,100):
s_1 = 0
for i in low2List:
if(i > x/300):
s_1 += 1
print(x/300, ", ", s_1/100)
print("")
print("G_3:")
print("")
for x in range(0,100):
s_1 = 0
for i in low3List:
if(i > x/300):
s_1 += 1
print(x/300, ", ", s_1/100)
print("")
print("G_4:")
print("")
for x in range(0,100):
s_1 = 0
for i in low4List:
if(i > x/300):
s_1 += 1
print(x/300, ", ", s_1/100)