-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelshrinkage.py
More file actions
135 lines (97 loc) · 3.12 KB
/
modelshrinkage.py
File metadata and controls
135 lines (97 loc) · 3.12 KB
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
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 16 14:12:33 2019
@author: gynjkm
"""
#importing packages and creating list
import random
import math
import operator
import matplotlib.pyplot
agents = []
#Assinging starting point y, x of the first agent as agents[0][0],[0][1]
agents.append([random.randint(0,49), random.randint(0,49)])
#Building an algorithm to randomise the value of y0 one step
if random.random() < 0.5:
agents[0][0] = agents[0][0] + 1
else:
agents[0][0] = agents[0][0] - 1
#Building an algorithm to randomise the value of x0 one step
if random.random() < 0.5:
agents[0][1] = agents[0][1] + 1
else:
agents[0][1] = agents[0][1] - 1
#And a few more steps...
if random.random() < 0.5:
agents[0][0] = agents[0][0] + 1
else:
agents[0][0] = agents[0][0] - 1
if random.random() < 0.5:
agents[0][1] = agents[0][1] + 1
else:
agents[0][1] = agents[0][1] - 1
if random.random() < 0.5:
agents[0][0] = agents[0][0] + 1
else:
agents[0][0] = agents[0][0] - 1
if random.random() < 0.5:
agents[0][1] = agents[0][1] + 1
else:
agents[0][1] = agents[0][1] - 1
if random.random() < 0.5:
agents[0][0] = agents[0][0] + 1
else:
agents[0][0] = agents[0][0] - 1
if random.random() < 0.5:
agents[0][1] = agents[0][1] + 1
else:
agents[0][1] = agents[0][1] - 1
#Assinging starting point y, x of the second agent as agents[1][0],[1][1]
agents.append([random.randint(0,49),random.randint(0,49)])
if random.random() < 0.5:
agents[1][0] = agents[1][0] + 1
else:
agents[1][0] = agents[1][0] - 1
if random.random() < 0.5:
agents[1][1] = agents[1][1] + 1
else:
agents[1][1] = agents[1][1] - 1
if random.random() < 0.5:
agents[1][0] = agents[1][0] + 1
else:
agents[1][0] = agents[1][0] - 1
if random.random() < 0.5:
agents[1][1] = agents[1][1] + 1
else:
agents[1][1] = agents[1][1] - 1
if random.random() < 0.5:
agents[1][0] = agents[1][0] + 1
else:
agents[1][0] = agents[1][0] - 1
if random.random() < 0.5:
agents[1][1] = agents[1][1] + 1
else:
agents[1][1] = agents[1][1] - 1
if random.random() < 0.5:
agents[1][0] = agents[1][0] + 1
else:
agents[1][0] = agents[1][0] - 1
if random.random() < 0.5:
agents[1][1] = agents[1][1] + 1
else:
agents[1][1] = agents[1][1] - 1
#Working out the distance between x0,y0 and x1,y1
distance = math.sqrt( ((agents[1][1] - agents[0][1])**2) + ((agents[1][0]-agents[0][0])**2))
print ("The distance between our two points is", distance, "units")
print ("The coordinates of our agents are", agents)
#Calculating the most easterly (eastmost?) and northerly agents
print ("The most northerly agent is at", max(agents))
print("The most easterly agent is at", max(agents, key=operator.itemgetter(1)))
#Showing our agents on a plot and colouring the most easterly point red
matplotlib.pyplot.ylim(0, 99)
matplotlib.pyplot.xlim(0, 99)
matplotlib.pyplot.scatter(agents[0][1],agents[0][0])
matplotlib.pyplot.scatter(agents[1][1],agents[1][0])
east_point= tuple(max(agents, key=operator.itemgetter(1)))
matplotlib.pyplot.scatter(east_point[1], east_point[0], color = 'red')
matplotlib.pyplot.show()