Initial subgraphing work

This commit is contained in:
Noah L. Schrick 2023-05-02 00:04:52 -05:00
parent 9c2f92b91c
commit a4354f5ba0
4 changed files with 45 additions and 9 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
## Set Working Directory to file directory - RStudio approach ## Set Working Directory to file directory - RStudio approach
setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
weighted <- 'False' weighted <- 'True'
#conda_install(envname = "r-reticulate", packages="networkx") #conda_install(envname = "r-reticulate", packages="networkx")
#conda_install(envname = "r-reticulate", packages="matplotlib") #conda_install(envname = "r-reticulate", packages="matplotlib")
#conda_install(envname = "r-reticulate", packages="pydot") #conda_install(envname = "r-reticulate", packages="pydot")

View File

@ -36,6 +36,7 @@ def prep_seirds(weighted):
ep_tmp = 0 # counter for epsilon ep_tmp = 0 # counter for epsilon
inf_ct = 0 # infection rate counter inf_ct = 0 # infection rate counter
recov_ct = 0 # recov rate counter
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']
@ -50,16 +51,18 @@ def prep_seirds(weighted):
in_edges = list(G.in_edges(node)) in_edges = list(G.in_edges(node))
out_edges = list(G.out_edges(node)) out_edges = list(G.out_edges(node))
tmp_S = 1 tmp_S = 1
tmp_recov = 0
tmp_inf = 0 tmp_inf = 0
for source in in_edges: for source in in_edges:
tmp_S = 1 tmp_S = 1
# If previous node was infected, then we are recovered # If previous node was infected, then we are recovered
if (color_d[source[0]] == 'red'): if (color_d[source[0]] == 'red'):
R = R + 1 if(weighted == 'False' or not in_edges):
tmp_S = 0 tmp_recov = 1
break # No need to check the other nodes else:
recov_ct = recov_ct + 1/len(in_edges) # trivial weighting
recov_ct = recov_ct + tmp_recov
for source in out_edges: for source in out_edges:
if (color_d[source[0]] == 'red'): if (color_d[source[0]] == 'red'):
if(weighted == 'False' or not out_edges): if(weighted == 'False' or not out_edges):
@ -68,26 +71,30 @@ def prep_seirds(weighted):
inf_ct = inf_ct + 1/len(out_edges) # trivial weighting inf_ct = inf_ct + 1/len(out_edges) # trivial weighting
inf_ct = inf_ct + tmp_inf inf_ct = inf_ct + tmp_inf
S = S + tmp_S 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 tmp_E = 1
tmp_R = 0 tmp_R = 0
tmp_inf = 0 tmp_inf = 0
tmp_recov = 0
for source in in_edges: for source in in_edges:
# If previous node was infected, then we are recovered # If previous node was infected, then we are recovered
if (color_d[source[0]] == 'red'): if (color_d[source[0]] == 'red'):
tmp_R = 1
tmp_E = 0 tmp_E = 0
if(weighted == 'False' or not in_edges):
tmp_recov = 1
else:
recov_ct = recov_ct + 1/len(in_edges) # trivial weighting
if (color_d[source[0]] == '' or color_d[source[0]] == 'white'): if (color_d[source[0]] == '' or color_d[source[0]] == 'white'):
if(weighted == 'False' or not in_edges): if(weighted == 'False' or not in_edges):
tmp_inf = 1 # add 1 for the inf counter tmp_inf = 1 # add 1 for the inf counter
else: else:
inf_ct = inf_ct + 1/len(in_edges) # trivial weighting inf_ct = inf_ct + 1/len(in_edges) # trivial weighting
E = E + tmp_E E = E + tmp_E
R = R + tmp_R recov_ct = recov_ct + tmp_recov
inf_ct = inf_ct + tmp_inf inf_ct = inf_ct + tmp_inf
else: else:
color_map.append(color) color_map.append(color)
@ -116,7 +123,8 @@ def prep_seirds(weighted):
# Params # Params
beta = (inf_ct)/len(A) # rate of infec beta = (inf_ct)/len(A) # rate of infec
delta = 1 # incubation period delta = 1 # incubation period
gamma_r = R/len(A) # recov rate #gamma_r = R/len(A) # recov rate
gamma_r = recov_ct/len(A)
gamma_d = D/len(A) # death rate gamma_d = D/len(A) # death rate
mu = D/(I_R+I_D) # fatality ratio mu = D/(I_R+I_D) # fatality ratio
epsilon = ep_tmp/len(A) # infected import rate epsilon = ep_tmp/len(A) # infected import rate

View File

@ -0,0 +1,28 @@
#!/usr/bin/python3
import networkx as nx
import matplotlib.pyplot as plt
from collections import OrderedDict
from operator import getitem
import itertools, os, sys
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.remove_node('\\n') # Remove "newline" node from newline end of dot file
G=nx.DiGraph(A)
print(A.get_edge_data(0, 1))
subgraph = []
to_explore = []
to_explore.append('0')
for node in to_explore:
for edge in list(G.out_edges(node)):
print(edge)
print()
for u, v, d in G.edges(data=True):
print(u, v, d['label'])
#for node in A: