Skip to content

Commit 90f55aa

Browse files
update way population speeds are set and maintained
to make room for reduced interaction scenario and custom speeds
1 parent 4dfe0c7 commit 90f55aa

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def __init__(self, *args, **kwargs):
5353
self.risk_increase = 'quadratic' #whether risk between risk and critical age increases 'linear' or 'quadratic'
5454

5555
#movement variables
56-
mean_speed = 0.01 # the mean speed (defined as heading * speed)
57-
std_speed = 0.01 / 3 #the standard deviation of the speed parameter
56+
#mean_speed = 0.01 # the mean speed (defined as heading * speed)
57+
#std_speed = 0.01 / 3 #the standard deviation of the speed parameter
5858
#the proportion of the population that practices social distancing, simulated
5959
#by them standing still
6060
proportion_distancing = 0
61-
self.speed = 0.01 #TODO: look up wth this is
61+
self.speed = 0.01 #average speed of population
6262
#when people have an active destination, the wander range defines the area
6363
#surrounding the destination they will wander upon arriving
6464
self.wander_range = 0.05
@@ -160,4 +160,4 @@ def set_self_isolation(self, self_isolate_proportion=0.9,
160160
self.x_plot = [0, 1.1]
161161
self.y_plot = [0, 1]
162162
#update whether traveling agents also infect
163-
self.traveling_infects = traveling_infects
163+
self.traveling_infects = traveling_infects

motion.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def out_of_bounds(population, xbounds, ybounds):
8080
return population
8181

8282

83-
def update_randoms(population, pop_size, heading_update_chance=0.02,
83+
def update_randoms(population, Config, heading_update_chance=0.02,
8484
speed_update_chance=0.02, heading_multiplication=1,
85-
speed_multiplication=1, speed=0.01):
85+
speed_multiplication=1):
8686
'''updates random states such as heading and speed
8787
8888
Function that randomized the headings and speeds for population members
@@ -115,22 +115,22 @@ def update_randoms(population, pop_size, heading_update_chance=0.02,
115115

116116
#randomly update heading
117117
#x
118-
update = np.random.random(size=(pop_size,))
118+
update = np.random.random(size=(Config.pop_size,))
119119
shp = update[update <= heading_update_chance].shape
120120
population[:,3][update <= heading_update_chance] = np.random.normal(loc = 0,
121121
scale = 1/3,
122122
size = shp) * heading_multiplication
123123
#y
124-
update = np.random.random(size=(pop_size,))
124+
update = np.random.random(size=(Config.pop_size,))
125125
shp = update[update <= heading_update_chance].shape
126126
population[:,4][update <= heading_update_chance] = np.random.normal(loc = 0,
127127
scale = 1/3,
128128
size = shp) * heading_multiplication
129129
#randomize speeds
130-
update = np.random.random(size=(pop_size,))
130+
update = np.random.random(size=(Config.pop_size,))
131131
shp = update[update <= heading_update_chance].shape
132-
population[:,5][update <= heading_update_chance] = np.random.normal(loc = speed,
133-
scale = speed / 3,
132+
population[:,5][update <= heading_update_chance] = np.random.normal(loc = Config.speed,
133+
scale = Config.speed / 3,
134134
size = shp) * speed_multiplication
135135

136136
population[:,5] = np.clip(population[:,5], a_min=0.0001, a_max=0.05)

population.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
from motion import get_motion_parameters
1212

13-
def initialize_population(pop_size, mean_age=45, max_age=105,
14-
xbounds=[0, 1], ybounds=[0, 1],
15-
speed=0.01):
13+
def initialize_population(Config, mean_age=45, max_age=105,
14+
xbounds=[0, 1], ybounds=[0, 1]):
1615
'''initialized the population for the simulation
1716
1817
the population matrix for this simulation has the following columns:
@@ -52,37 +51,37 @@ def initialize_population(pop_size, mean_age=45, max_age=105,
5251
'''
5352

5453
#initialize population matrix
55-
population = np.zeros((pop_size, 15))
54+
population = np.zeros((Config.pop_size, 15))
5655

5756
#initalize unique IDs
58-
population[:,0] = [x for x in range(pop_size)]
57+
population[:,0] = [x for x in range(Config.pop_size)]
5958

6059
#initialize random coordinates
6160
population[:,1] = np.random.uniform(low = xbounds[0] + 0.05, high = xbounds[1] - 0.05,
62-
size = (pop_size,))
61+
size = (Config.pop_size,))
6362
population[:,2] = np.random.uniform(low = ybounds[0] + 0.05, high = ybounds[1] - 0.05,
64-
size=(pop_size,))
63+
size=(Config.pop_size,))
6564

6665
#initialize random headings -1 to 1
6766
population[:,3] = np.random.normal(loc = 0, scale = 1/3,
68-
size=(pop_size,))
67+
size=(Config.pop_size,))
6968
population[:,4] = np.random.normal(loc = 0, scale = 1/3,
70-
size=(pop_size,))
69+
size=(Config.pop_size,))
7170

7271
#initialize random speeds
73-
population[:,5] = np.random.normal(speed, speed / 3)
72+
population[:,5] = np.random.normal(Config.speed, Config.speed / 3)
7473

7574
#initalize ages
7675
std_age = (max_age - mean_age) / 3
7776
population[:,7] = np.int32(np.random.normal(loc = mean_age,
7877
scale = std_age,
79-
size=(pop_size,)))
78+
size=(Config.pop_size,)))
8079

8180
population[:,7] = np.clip(population[:,7], a_min = 0,
8281
a_max = max_age) #clip those younger than 0 years
8382

8483
#build recovery_vector
85-
population[:,9] = np.random.normal(loc = 0.5, scale = 0.5 / 3, size=(pop_size,))
84+
population[:,9] = np.random.normal(loc = 0.5, scale = 0.5 / 3, size=(Config.pop_size,))
8685

8786
return population
8887

simulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from visualiser import build_fig, draw_tstep, set_style
1919

2020
#set seed for reproducibility
21-
np.random.seed(100)
21+
#np.random.seed(100)
2222

2323
class Simulation():
2424
#TODO: if lockdown or otherwise stopped: destination -1 means no motion
@@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs):
4242

4343
def population_init(self):
4444
'''(re-)initializes population'''
45-
self.population = initialize_population(self.Config.pop_size, self.Config.mean_age,
45+
self.population = initialize_population(self.Config, self.Config.mean_age,
4646
self.Config.max_age, self.Config.xbounds,
4747
self.Config.ybounds)
4848

@@ -88,10 +88,10 @@ def tstep(self):
8888
self.population[:,5][self.Config.lockdown_vector == 0] = 0
8989
else:
9090
#update randoms
91-
self.population = update_randoms(self.population, self.Config.pop_size, self.Config.speed)
91+
self.population = update_randoms(self.population, self.Config)
9292
else:
9393
#update randoms
94-
self.population = update_randoms(self.population, self.Config.pop_size, self.Config.speed)
94+
self.population = update_randoms(self.population, self.Config)
9595

9696
#for dead ones: set speed and heading to 0
9797
self.population[:,3:5][self.population[:,6] == 3] = 0

0 commit comments

Comments
 (0)