Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect Talk Code Changes #57

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions interactives/GettingStarted.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Overview of `epiworldpy`
jupyter: epiworldpy
---

`epiworldpy` is an Python package that provides a fast (C++ backend) and highly-customizable framework for building network-based transmission/diffusion agent-based models. Some key features of `epiworldpy` are the ability to construct multi-virus models (e.g. models of competing multi-pathogens/multi-rumor), design mutating pathogens, architect population-level interventions, and build models with an arbitrary number of compartments/states (beyond SIR/SEIR).
Expand Down Expand Up @@ -158,14 +157,14 @@ plt.figure(figsize=(10, 6))

for virus_id, virus_data in enumerate(reproductive_data):
average_rts = list()

for date_data in virus_data:
if not date_data:
continue

keys_array = np.array(list(date_data.values()), dtype=np.float64)
average_rts.append(np.mean(keys_array))

plt.plot(range(0, len(average_rts)), average_rts, label=f"Virus {virus_id}")

plt.xlabel('Date')
Expand All @@ -189,8 +188,16 @@ print(transition_matrix)
By itself, this data is hard to parse (like previous results). Let's graph it:

```{python}
grouped = transition_matrix.groupby(['dates', 'states_to'])['counts'].sum().unstack().fillna(0)
daily_incidence = grouped.diff().fillna(0)
# Subsetting rows where states_from != states_to.
transition_matrix = transition_matrix[
transition_matrix['states_from'] != transition_matrix['states_to']
]
# Selecting only those where counts > 0
transition_matrix = transition_matrix[
transition_matrix['counts'] > 0
]

daily_incidence = transition_matrix.groupby(['dates', 'states_to'])['counts'].sum().unstack()

# Plot!
plt.figure(figsize=(10, 6))
Expand All @@ -213,6 +220,13 @@ We can also look at generation time, here's an example on how to do that:
from collections import defaultdict

generation_time = covid19.get_db().get_generation_time()
generation_time = pd.DataFrame(generation_time)

# Filtering where gentimes is not -1
generation_time = generation_time[
generation_time['gentimes'] != -1
]

agents = generation_time['agents']
viruses = generation_time['viruses']
times = generation_time['times']
Expand Down Expand Up @@ -268,10 +282,10 @@ fig, ax = plt.subplots(figsize=(6,4))
to_track = { source[0] }
def update(frame):
ax.clear()

agents_involved_today = set()
agents_relationships_we_care_about = []

# Get only the agents involved in the current frame.
for i in range(len(start)):
if start[i] <= frame <= end[i]:
Expand Down Expand Up @@ -385,7 +399,7 @@ vaccine = epiworld.Tool(
as_proportion = True,
susceptibility_reduction = 0.9,
transmission_reduction = 0.5,
recovery_enhancer = 0.5,
recovery_enhancer = 0.5,
death_reduction = 0.9
)

Expand All @@ -408,7 +422,7 @@ Let's bring back our daily incidence graph to see how well the vaccine worked.
transition_matrix = pd.DataFrame(covid19.get_db().get_hist_transition_matrix(False))

grouped = transition_matrix.groupby(['dates', 'states_to'])['counts'].sum().unstack().fillna(0)
daily_incidence = grouped.diff().fillna(0)
daily_incidence = transition_matrix.groupby(['dates', 'states_to'])['counts'].sum().unstack().fillna(0)

# Plot!
plt.figure(figsize=(10, 6))
Expand All @@ -433,14 +447,14 @@ plt.figure(figsize=(10, 6))

for virus_id, virus_data in enumerate(reproductive_data):
average_rts = list()

for date_data in virus_data:
if not date_data:
continue

keys_array = np.array(list(date_data.values()), dtype=np.float64)
average_rts.append(np.mean(keys_array))

plt.plot(range(0, len(average_rts)), average_rts, label=f"Virus {virus_id}")

plt.xlabel('Date')
Expand All @@ -452,4 +466,3 @@ plt.show()
```

The numbers start out lower, and stay lower.