Model Parameters

This commit is contained in:
Noah L. Schrick 2023-04-28 18:26:05 -05:00
parent 56f6a9bb90
commit 7942bbb48a
2 changed files with 62 additions and 11 deletions

View File

@ -393,6 +393,7 @@ strict digraph G {
391; 391;
392; 392;
393; 393;
394 [fillcolor=red,style=filled];
0->1 [label=5]; 0->1 [label=5];
1->2 [label=5]; 1->2 [label=5];
2->3 [label=2]; 2->3 [label=2];
@ -1771,4 +1772,5 @@ strict digraph G {
390->393 [label=1]; 390->393 [label=1];
391->393 [label=2]; 391->393 [label=2];
392->393 [label=2]; 392->393 [label=2];
393->394 [label=99];
} }

View File

@ -4,20 +4,23 @@ import networkx as nx
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from collections import OrderedDict from collections import OrderedDict
from operator import getitem from operator import getitem
import itertools, os import itertools, os, sys
# Change dir to location of this python file
os.chdir(os.path.dirname(sys.argv[0]))
# AGraph preserves attributes, networkx Graph does not. # AGraph preserves attributes, networkx Graph does not.
# Many of the desired functions are in networkx. # Many of the desired functions are in networkx.
# So import AGraph to keep attributes, then convert to Networkx. # So import AGraph to keep attributes, then convert to Networkx.
A = nx.drawing.nx_agraph.to_agraph(nx.drawing.nx_pydot.read_dot("./1_mo_color_DOTFILE.dot")) A = nx.drawing.nx_agraph.to_agraph(nx.drawing.nx_pydot.read_dot("./1_mo_color_DOTFILE.dot"))
A.layout('dot') A.layout('dot')
A.draw('tree.png') #A.draw('tree.png')
A.remove_node('\\n') # Remove "newline" node from newline end of dot file A.remove_node('\\n') # Remove "newline" node from newline end of dot file
G=nx.DiGraph(A) G=nx.DiGraph(A)
color_map = [] color_map = []
color_d = {} color_d = {}
node_pos = {} node_pos = {} # used for drawing/graphing
# Compartments # Compartments
S = 0 S = 0
@ -26,14 +29,7 @@ E = 0
R = 0 R = 0
D = 0 D = 0
# Params ep_tmp = 0 # counter for epsilon
beta = 0
delta = 0
gamma_r = 0
gamma_d = 0
mu = 0
epsilon = 0
omega = 0
for node in A: for node in A:
color = A.get_node(node).attr.to_dict()['fillcolor'] color = A.get_node(node).attr.to_dict()['fillcolor']
@ -46,11 +42,64 @@ for node in A:
color_map.append("white") color_map.append("white")
color_d[node] = color color_d[node] = color
in_edges = list(G.in_edges(node)) in_edges = list(G.in_edges(node))
tmp_S = 1
for source in in_edges:
tmp_S = 1
# If previous node was infected, then we are recovered
if (color_d[source[0]] == 'red'):
R = R + 1
tmp_S = 0
break # No need to check the other nodes
S = S + tmp_S
#G[source[0]][node]['weight'] = 3
elif color == 'yellow': elif color == 'yellow':
color_map.append(color) color_map.append(color)
color_d[node] = color color_d[node] = color
in_edges = list(G.in_edges(node)) in_edges = list(G.in_edges(node))
tmp_E = 1
for source in in_edges:
tmp_E = 1
# If previous node was infected, then we are recovered
if (color_d[source[0]] == 'red'):
R = R + 1
tmp_E = 0
break # No need to check the other nodes
E = E + tmp_E
else: else:
color_map.append(color) color_map.append(color)
color_d[node] = color color_d[node] = color
I = I + 1
# Check if node dies
out_edges = list(G.out_edges(node))
if not out_edges:
D = D + 1
# Check if imported
in_edges = list(G.in_edges(node)) in_edges = list(G.in_edges(node))
if not in_edges:
ep_tmp = ep_tmp + 1
# Params
beta = I/len(A) # rate of infec (I/total?)
delta = E/len(A) # symptom appearance rate (E/total?)
gamma_r = R/len(A) # recov rate (R/total?)
gamma_d = D/len(A) # death rate (D/total?)
mu = D/I # fatality ratio (D/I)
epsilon = ep_tmp/len(A) # infected import rate
omega = 0 # waning immunity rate
print("Model Compartments:")
print("S:", str(S))
print("I:", str(I))
print("E:", str(E))
print("R:", str(R))
print("D:", str(D))
print("\n")
print("Model Parameters:")
print("beta:", str(beta))
print("delta:", str(delta))
print("gamma_r:", str(gamma_r))
print("gamma_d:", str(gamma_d))
print("mu:", str(mu))
print("epsilon:", str(epsilon))