From 7942bbb48a1a9854c8a9e0ab6fd8a55f40b8c778 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 28 Apr 2023 18:26:05 -0500 Subject: [PATCH] Model Parameters --- Analysis/1_mo_color_DOTFILE.dot | 2 + Analysis/prep_model.py | 71 ++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/Analysis/1_mo_color_DOTFILE.dot b/Analysis/1_mo_color_DOTFILE.dot index 34e94a8..00e5f13 100644 --- a/Analysis/1_mo_color_DOTFILE.dot +++ b/Analysis/1_mo_color_DOTFILE.dot @@ -393,6 +393,7 @@ strict digraph G { 391; 392; 393; +394 [fillcolor=red,style=filled]; 0->1 [label=5]; 1->2 [label=5]; 2->3 [label=2]; @@ -1771,4 +1772,5 @@ strict digraph G { 390->393 [label=1]; 391->393 [label=2]; 392->393 [label=2]; +393->394 [label=99]; } diff --git a/Analysis/prep_model.py b/Analysis/prep_model.py index 8185bdd..aefac3d 100644 --- a/Analysis/prep_model.py +++ b/Analysis/prep_model.py @@ -4,20 +4,23 @@ import networkx as nx import matplotlib.pyplot as plt from collections import OrderedDict 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. # Many of the desired functions are in 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.layout('dot') -A.draw('tree.png') +#A.draw('tree.png') A.remove_node('\\n') # Remove "newline" node from newline end of dot file G=nx.DiGraph(A) color_map = [] color_d = {} -node_pos = {} +node_pos = {} # used for drawing/graphing # Compartments S = 0 @@ -26,14 +29,7 @@ E = 0 R = 0 D = 0 -# Params -beta = 0 -delta = 0 -gamma_r = 0 -gamma_d = 0 -mu = 0 -epsilon = 0 -omega = 0 +ep_tmp = 0 # counter for epsilon for node in A: color = A.get_node(node).attr.to_dict()['fillcolor'] @@ -46,11 +42,64 @@ for node in A: color_map.append("white") color_d[node] = color 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': color_map.append(color) color_d[node] = color 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: color_map.append(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)) + 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)) \ No newline at end of file