ryansmcgee / seirsplus Goto Github PK
View Code? Open in Web Editor NEWModels of SEIRS epidemic dynamics with extensions, including network-structured populations, testing, contact tracing, and social distancing.
License: MIT License
Models of SEIRS epidemic dynamics with extensions, including network-structured populations, testing, contact tracing, and social distancing.
License: MIT License
Floating point precision limitations can cause an error to be raised by the scipy solver when running a SEIRSModel. In the models.py line 127, the end time is calculated as the current time plus the runtime. When the runtime is calculated as runtime = self.tmax - self.t
(e.g. models.py:line229) this can result in the last value of t_eval
being greater than self.tmax
and therefore outside t_span
. In other words, sometimes self.t + (self.tmax - self.t) > self.tmax
.
I believe you could solve this by using t_span
instead of [self.t, self.tmax]
in line 144.
If not using checkpoints, the model should run for a specific time. I suppose at line 200 in the run() function self.run_epoch(runtime=self.tmax, dt=dt)
should be self.run_epoch(runtime=T, dt=dt)
When running this:
G_normal = custom_exponential_graph(baseGraph, scale=100)
I get the following error:
TypeError Traceback (most recent call last)
mtrand.pyx in mtrand.RandomState.choice()
TypeError: 'KeysView' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in
3
4 # Baseline normal interactions:
----> 5 G_normal = custom_exponential_graph(baseGraph, scale=100)
6 plot_degree_distn(G_normal, max_degree=40)
~\Anaconda3\envs\corona\lib\site-packages\seirsplus\models.py in custom_exponential_graph(base_graph, scale, min_num_edges, m, n)
1175 neighbors = graph[node].keys()
1176 quarantineEdgeNum = int( max(min(numpy.random.exponential(scale=scale, size=1), len(neighbors)), min_num_edges) )
-> 1177 quarantineKeepNeighbors = numpy.random.choice(neighbors, size=quarantineEdgeNum, replace=False)
1178 for neighbor in neighbors:
1179 if(neighbor not in quarantineKeepNeighbors):
mtrand.pyx in mtrand.RandomState.choice()
solved it by wrapping graph[node].keys() with list():
neighbors = graph[node].keys() -> neighbors = list(graph[node].keys())
Is it right?
Hello!
Thanks for the excellent repo, I found it by following up on the Color return-to-work model, which was useful for thinking through the impact of different testing regimes on safety. I found myself wanting to tweak a few knobs that weren't included in their GUI (such as test sensitivity and specificity, infectivity post-vaccine, etc). Are the notebooks supporting those models available?
Thank you,
-Josh
When using NodeGroupData, these two lines in the SymptomaticSEIRSNetworkModel are standalone and self.D_I_S and Self.D_I_A don't seem to be defined anywhere else:
self.nodeGroupData[groupName]['numD_I_S'][0] = numpy.count_nonzero(self.nodeGroupData[groupName]['mask']*self.X==self.D_I_S) self.nodeGroupData[groupName]['numD_I_A'][0] = numpy.count_nonzero(self.nodeGroupData[groupName]['mask']*self.X==self.D_I_A)
Hello,
i am using this great simulation for visualizing purpose but in Extended SEIRS Model i am continuously getting error on Network and it is giving me error as model not defined. if i am trying to resolve it than its giving my further error on FARZ import.
kindly guide me in this regard as i am not a programmer and just want to run this simulation.
TIA
Hi,
I'm trying to packaging this into Debian as a Debian package, and now I'm writing the copyright information.
I found the copyright statement in LICENSE which seems missed year
and fullname
.
Line 3 in 5c04080
There supposes would be Copyright (c) 2020 Ryan Seamus McGee
.
Could you please let me know if this statement is correct or not and fix this?
Thank you~
Following the tutorial here and just need to add installation of the libraries at the top of the notebook
When I set a checkpoint between t=15 and t=75, I was expecting to see something like this:
The blue curve represents the number of infected people if no restrictions are applied. The green curve is during a simulated quarantine supposing a social contact reduction of 50% (that is, beta is cut in half) at time t=15 and goes back to the original value at the end of the checkpoint (I know this is different in the real world, just for the sake of simplicity).
But this is what I'm getting from seirsplus:
The checkpoint doesn't seem to take any effect. Below is a print of the settings I'm using:
What am I getting wrong?
Minimal working example:
from seirsplus.models import *
from seirsplus.networks import *
import networkx as nx
graph = nx.barabasi_albert_graph(n=500, m=10)
graph = custom_exponential_graph(graph)
base_model = SEIRSNetworkModel(G=graph,
beta=0.25,
sigma=1/5,
gamma=1/15,
initE=10)
base_model.run(T=100)
Code produces the following error occasionally; interestingly enough the same error shows up in the model wiki example (line 6):
seirsplus\models.py:838: RuntimeWarning: divide by zero encountered in log
self.delta = numpy.log(self.degree)/numpy.log(numpy.mean(self.degree)) if self.parameters['delta'] is None else numpy.array(self.parameters['delta']) if isinstance(self.parameters['delta'], (list, numpy.ndarray)) else numpy.full(fill_value=self.parameters['delta'], shape=(self.numNodes,1))
seirsplus\models.py:839: RuntimeWarning: divide by zero encountered in log
self.delta_Q = numpy.log(self.degree_Q)/numpy.log(numpy.mean(self.degree_Q)) if self.parameters['delta_Q'] is None else numpy.array(self.parameters['delta_Q']) if isinstance(self.parameters['delta_Q'], (list, numpy.ndarray)) else numpy.full(fill_value=self.parameters['delta_Q'], shape=(self.numNodes,1))
I believe the randomness comes from the way custom_exponential_graph
modifies the original graph. One might have to run the code several times to reproduce the issue.
jkhjh
Why can the model with De ,DI test the effect of infection on kinetics?
Most of the explanatory images on the main page (https://github.com/ryansmcgee/seirsplus) are not showing and link to a 404.
Very interesting and thorough implementation of SEIRs modeling, and I find the Stochastic approach particularly promising in complex real-life scenarios.
One question though, since the simulation is with respect to the number of nodes in the graph, I suppose the complexity depends on it, too. May I ask how the complexity(memory and runtime) scales with the number of nodes, or some guidelines on how many number of nodes can be included before the experiment becomes prohibitively computationally infeasible (on a decent PC)?
Edit: according to Specifying Interaction Networks section, it is suggested to use 10,000 nodes as a trade-off between small stochastic volatility and realism.
Hi there,
Not sure what I am doing wrong. I am trying to run the network demo locally, but I get the following error:
The error persists for scale values up to and including 19, and goes away for values larger than 19. Any ideas what is happening?
Thanks!
In lines 1932 and 1933 for ExtSEIRSNetworkModel
self.nodeGroupData[groupName]['numQ_I_sym'][0] = numpy.count_nonzero(self.nodeGroupData[groupName]['mask']*self.X==self.Q_I_sym)
self.nodeGroupData[groupName]['numQ_I_asym'][0] = numpy.count_nonzero(self.nodeGroupData[groupName]['mask']*self.X==self.Q_I_asym)
Q_I_sym
and Q_I_asym
should be Q_sym
and Q_asym
instead
I am getting this error when running the example model.. Do you know how to deal with this error? @ryansmcgee @mschauer @fdabl @jrhomburger @tomermilo
This has happened after migrating from 0.14 to 1.0.x on code that ran without issues on the older version. This is a basic SEIR model on a network (no quarantine/tracing/social distancing), after instantiating the network. I'll do more investigating to see what the exact context is, but in the meantime I thought I would flag it. If it matters, the network I am using has roughly 4,000 nodes and 100,000 edges.
The error message is as follows:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-6-4d6a510161ce> in <module>
104 gamma = 1/15,
105 initI = 5)
--> 106 model.run(T=100, print_interval=10)
seirsplus\models.py in run(self, T, checkpoints, print_interval, verbose)
1336 while running:
1337
-> 1338 running = self.run_iteration()
1339
1340 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
seirsplus\models.py in run_iteration(self)
1224 # Save information about infection events when they occur:
1225 if(transitionType == 'StoE'):
-> 1226 transitionNode_GNbrs = list(self.G[transitionNode].keys())
1227 transitionNode_GQNbrs = list(self.G_Q[transitionNode].keys())
1228 self.infectionsLog.append({ 't': self.t,
networkx\classes\graph.py in __getitem__(self, n)
473 AtlasView({1: {}})
474 """
--> 475 return self.adj[n]
476
477 def add_node(self, node_for_adding, **attr):
networkx\classes\coreviews.py in __getitem__(self, name)
79
80 def __getitem__(self, name):
---> 81 return AtlasView(self._atlas[name])
82
83 def copy(self):
KeyError: 3047
Hi there,
First, let me say that I came across this package back in April and was already very impressed, but what you have done since is truly amazing. Thank you!
I am trying to familiarize myself with all the updates, so apologies if there is a straightforward answer to my question. In particular, I am interested in assessing how testing a fixed amount of randomly selected people in addition to the testing that symptomatic individuals have access to can influence an epidemic.
Currently, it seems one can allocate 'PCT_TESTED_PER_DAY' % of tests, of which a maximum of 'MAX_PCT_TESTS_FOR_SYMPTOMATICS' % is available to symptomatic individuals. If the amount of tests is not exhausted, then the remaining tests go to traced contacts, and finally to the random sample. However, this does not allow me to specify that X% of the population is randomly sampled and tested periodically. Is there a way to do this?
I suppose I could tweak 'TESTING_COMPLIANCE_RATE_RANDOM' to get an approximation of the fixed percentage, but that will always be stochastic since I can't control how many tests actually go to symptomatic individuals.
Thank you for any input!
The current code has the potential to raise NameError at runtime. This code was previously in a class method that defined self
but when it was moved into a standalone function, the self.
was not removed.
https://github.com/ryansmcgee/seirsplus/blob/master/seirsplus/models.py#L1194
$ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
./seirsplus/models.py:1194:49: F821 undefined name 'self'
nodeDegrees = graph.sum(axis=0).reshape(self.numNodes,1) # sums of adj matrix cols
^
When running a simulation, if there the next event will take place in more than a day, then there is a chance that time will advance (for example) from day 6 to day 8. This can be a problem if in the simulation there is weekly randomized testing going on in day 7.
I will be post a pull request soon that addresses this issue together with some other enhancements.
In the SEIRS+ Network Model document, I think the description of D_I should be "Number of infectious individuals with detected cases" instead of "Number of exposed individuals with detected cases", which is the same description as D_E.
I've started working with the seirsplus framework with a networkx created SBM network, but it became very memory-intensive and slow. Is there a way we can use graph_tool networks to work with the seirsplus models?
The current README.MD on master (commit 63dcba1) contains an example code block in the Code Usage section:
https://github.com/ryansmcgee/seirsplus#code-usage
One of the arguments being passed to SEIRSNetworkModel()
in that example code is "Q
", which does not exist in the current version of SEIRSNetworkModel
, hence leading to errors if a user were to try to run the code straight from that example.
I do not use this library but I found this issue via a StackOverflow user that had this problem: https://stackoverflow.com/questions/73872826/unexpected-keyword-argument-within-init
There seems to be a typo below about accessing Q_E
and Q_I
. What is the proper way to access these -- is it something like model.numQ_E
and model.numQ_I
, respectively?
S = model.numS # time series of S counts
E = model.numE # time series of E counts
I = model.numI # time series of I counts
R = model.numR # time series of R counts
F = model.numF # time series of F counts
Q_E = model.numE # time series of Q_E counts
Q_I = model.numI # time series of Q_I counts
In the network model, just increasing phi_E
and phi_I
(test rate when a close contact has tested positive) seems to increase the number of cases. I feel like this should never happen. My first guess is self.numI[self.tidx]
in models.py-ln 693 should be self.numI[self.tidx] - self.numD_I[self.tidx]
but not sure.
Initial parameters
time=300 beta =2.4/12.39 sigma =1/4.58 gamma =1/12.39 mu_I =0.0004 mu_0 =0 nu =0 xi =0 p =0.5 Q =G_quarantine beta_D =beta sigma_D =sigma gamma_D =gamma mu_D =0.0004 theta_E =0 theta_I =0 phi_E =0 phi_I =0 psi_E =1.0, psi_I =1.0 q =0.05 initI =numNodes/100 initE =0 initD_E =0 initD_I =0 initR =0 initF =0
Checkpoints-1
{'t': [21, 42, 100], 'G': [G_distancing, G_distancing, G_normal], 'p': [0.1 , 0.1, 0.5 ], 'theta_E': [0.02, 0.1, 0.02], 'theta_I': [0.02, 0.1, 0.02], 'phi_E': [0.6 , 0.6, 0.6 ], 'phi_I': [0.6 , 0.6, 0.6]}
Checkpoints-2
{'t': [21, 42, 100], 'G': [G_distancing, G_distancing, G_normal], 'p': [0.1 , 0.1, 0.5 ], 'theta_E': [0.02, 0.1, 0.02], 'theta_I': [0.02, 0.1, 0.02], 'phi_E': [0.6 , 0.85, 0.85 ], 'phi_I': [0.6 , 0.85, 0.85 ]}
Result with Checkpoints-1
Simulation time is set to 300 but it ends around 150, indicating there are no cases left.
A quick suggestion to update the wiki text for Basic SEIRS Model Description:
Below the SEIRS deterministic equations (under Deterministic Mean-field Implementation), suggest defining F and N , e.g.: Note, F are the numbers of deceased individuals (fatalities) and N is the total number of individuals in the population.
I want to predict the covid happend in hongkong, so the 2.0version is required which is sharply satisfy my requirement, please help me do that with the 2.0 code
I'm trying to model SEIR situations that occur in nursing homes, cruise ships, and prisons where there is close contact between residents/inmates and staff contact between separate populations.
Specifically, I'm interested in the following:
If there are two separate populations A and B from the beginning, and the only thing common between them is a staff population S, how long does it take for an infection to spread from A to B given control over how densely connected the S graph is to A and B
If B is a more vulnerable population, what are the clinical outcomes in the following situations:
Is this the type of thing that the SIER plus framework can handle? I don't mind taking a stab at implementing a Gilllespie style implementation of this myself, but if SIER plus can do this off-the shelf it would help a lot.
I think you have a problem in raw 522:
it should be: self.update_Q(Q)
and not: self.update_Q(G)
Hi, there, is there a way to identify nodes in each state at each period?
I figured it out. Model.X gives the states for all nodes. :)
Dear Prof.,
I have just learn the seirsplus package with great interest. I think the Version 2.0 code is very suitable for my research on COVID-19.
I wonder whether you can share me the Version 2.0 code for our research. Also, I'd very glad to ask you to join us to help me to finish that work. Any help or suggestions are greatly appreciated.
[email protected]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.