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

Random "division by zero" error #33

Closed
mihaibanciu opened this issue Aug 11, 2020 · 1 comment
Closed

Random "division by zero" error #33

mihaibanciu opened this issue Aug 11, 2020 · 1 comment

Comments

@mihaibanciu
Copy link

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.

@ryansmcgee
Copy link
Owner

This is a warning coming from taking the log of 0 when calculating the delta parameter for node(s) with 0 degree (which can happen when you call custom_exponential_graph on a network). This warning wasn't affecting the execution of the model, but I've updated the relevant lines to handle the log calculation more cleanly and do a resulting value check. Thanks for prompting this improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants