Skip to content

Commit 06c0015

Browse files
authored
Improve Virus on Network documentation (#100)
Change 1: Make the ReadMe more descriptive - Added a more detailed explanation of the model - Added an extra method of running the model Change 2: Doc Strings and Cleaning Made small changes to make the code more readable and easy to understand at first glance NOTE: In the model, after running, some of the nodes in the graph are isolated. In my opinion it should be connected (if it was intentional then fine but in case not it needs to be updated with a different graph creation technique)
1 parent 6e68e4e commit 06c0015

File tree

5 files changed

+68
-39
lines changed

5 files changed

+68
-39
lines changed

examples/virus_on_network/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
## Summary
44

5-
This model is based on the NetLogo model "Virus on Network".
5+
This model is based on the NetLogo model "Virus on Network". It demonstrates the spread of a virus through a network and follows the SIR model, commonly seen in epidemiology.
6+
7+
The SIR model is one of the simplest compartmental models, and many models are derivatives of this basic form. The model consists of three compartments:
8+
9+
S: The number of susceptible individuals. When a susceptible and an infectious individual come into "infectious contact", the susceptible individual contracts the disease and transitions to the infectious compartment.
10+
I: The number of infectious individuals. These are individuals who have been infected and are capable of infecting susceptible individuals.
11+
R for the number of removed (and immune) or deceased individuals. These are individuals who have been infected and have either recovered from the disease and entered the removed compartment, or died. It is assumed that the number of deaths is negligible with respect to the total population. This compartment may also be called "recovered" or "resistant".
612

713
For more information about this model, read the NetLogo's web page: http://ccl.northwestern.edu/netlogo/models/VirusonaNetwork.
814

@@ -26,6 +32,15 @@ To run the model interactively, run ``mesa runserver`` in this directory. e.g.
2632

2733
Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press Reset, then Run.
2834

35+
or
36+
37+
Directly run the file ``run.py`` in the terminal. e.g.
38+
39+
```
40+
$ python run.py
41+
```
42+
43+
2944
## Files
3045

3146
* ``run.py``: Launches a model visualization server.

examples/virus_on_network/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def get_resistant_susceptible_ratio(model):
4848

4949
def make_plot(model):
5050
# This is for the case when we want to plot multiple measures in 1 figure.
51-
# We could incorporate this into core Mesa.
5251
fig = Figure()
5352
ax = fig.subplots()
5453
measures = ["Infected", "Susceptible", "Resistant"]

examples/virus_on_network/virus_on_network/__init__.py

Whitespace-only changes.

examples/virus_on_network/virus_on_network/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def number_resistant(model):
2828

2929

3030
class VirusOnNetwork(mesa.Model):
31-
"""A virus model with some number of agents"""
31+
"""
32+
A virus model with some number of agents
33+
"""
3234

3335
def __init__(
3436
self,
@@ -104,6 +106,10 @@ def run_model(self, n):
104106

105107

106108
class VirusAgent(mesa.Agent):
109+
"""
110+
Individual Agent definition and its properties/interaction methods
111+
"""
112+
107113
def __init__(
108114
self,
109115
unique_id,

examples/virus_on_network/virus_on_network/server.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def get_agents(source, target):
4949
return portrayal
5050

5151

52-
network = mesa.visualization.NetworkModule(network_portrayal, 500, 500)
52+
network = mesa.visualization.NetworkModule(
53+
portrayal_method=network_portrayal,
54+
canvas_height=500,
55+
canvas_width=500,
56+
)
5357
chart = mesa.visualization.ChartModule(
5458
[
5559
{"Label": "Infected", "Color": "#FF0000"},
@@ -71,63 +75,68 @@ def get_resistant_susceptible_ratio(model):
7175

7276
model_params = {
7377
"num_nodes": mesa.visualization.Slider(
74-
"Number of agents",
75-
10,
76-
10,
77-
100,
78-
1,
78+
name="Number of agents",
79+
value=10,
80+
min_value=10,
81+
max_value=100,
82+
step=1,
7983
description="Choose how many agents to include in the model",
8084
),
8185
"avg_node_degree": mesa.visualization.Slider(
82-
"Avg Node Degree", 3, 3, 8, 1, description="Avg Node Degree"
86+
name="Avg Node Degree",
87+
value=3,
88+
min_value=3,
89+
max_value=8,
90+
step=1,
91+
description="Avg Node Degree",
8392
),
8493
"initial_outbreak_size": mesa.visualization.Slider(
85-
"Initial Outbreak Size",
86-
1,
87-
1,
88-
10,
89-
1,
94+
name="Initial Outbreak Size",
95+
value=1,
96+
min_value=1,
97+
max_value=10,
98+
step=1,
9099
description="Initial Outbreak Size",
91100
),
92101
"virus_spread_chance": mesa.visualization.Slider(
93-
"Virus Spread Chance",
94-
0.4,
95-
0.0,
96-
1.0,
97-
0.1,
102+
name="Virus Spread Chance",
103+
value=0.4,
104+
min_value=0.0,
105+
max_value=1.0,
106+
step=0.1,
98107
description="Probability that susceptible neighbor will be infected",
99108
),
100109
"virus_check_frequency": mesa.visualization.Slider(
101-
"Virus Check Frequency",
102-
0.4,
103-
0.0,
104-
1.0,
105-
0.1,
110+
name="Virus Check Frequency",
111+
value=0.4,
112+
min_value=0.0,
113+
max_value=1.0,
114+
step=0.1,
106115
description="Frequency the nodes check whether they are infected by a virus",
107116
),
108117
"recovery_chance": mesa.visualization.Slider(
109-
"Recovery Chance",
110-
0.3,
111-
0.0,
112-
1.0,
113-
0.1,
118+
name="Recovery Chance",
119+
value=0.3,
120+
min_value=0.0,
121+
max_value=1.0,
122+
step=0.1,
114123
description="Probability that the virus will be removed",
115124
),
116125
"gain_resistance_chance": mesa.visualization.Slider(
117-
"Gain Resistance Chance",
118-
0.5,
119-
0.0,
120-
1.0,
121-
0.1,
126+
name="Gain Resistance Chance",
127+
value=0.5,
128+
min_value=0.0,
129+
max_value=1.0,
130+
step=0.1,
122131
description="Probability that a recovered agent will become "
123132
"resistant to this virus in the future",
124133
),
125134
}
126135

127136
server = mesa.visualization.ModularServer(
128-
VirusOnNetwork,
129-
[network, get_resistant_susceptible_ratio, chart],
130-
"Virus Model",
131-
model_params,
137+
model_cls=VirusOnNetwork,
138+
visualization_elements=[network, get_resistant_susceptible_ratio, chart],
139+
name="Virus on Network Model",
140+
model_params=model_params,
132141
)
133142
server.port = 8521

0 commit comments

Comments
 (0)