ryansmcgee / seirsplus

Models of SEIRS epidemic dynamics with extensions, including network-structured populations, testing, contact tracing, and social distancing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError in Network Demo

fdabl opened this issue · comments

Hi there,

Not sure what I am doing wrong. I am trying to run the network demo locally, but I get the following error:

ValueError

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!

Thanks for reaching out, I'm sorry you're encountering this issue. I just tested the notebook on my machine and unfortunately I'm not able to reproduce this error on my end. It appears that in your case baseGraph has one or more nodes that have no edges which causes neighbors to be an empty list that numpy.random.choice can't handle. Are you using the baseGraph generation that was originally in the notebook, or did you modify how that graph is created? The current implementation of custom_exponential_graph implicitly assumes that all nodes have non-zero degree, but I will change the code to be safe for cases where nodes do have zero degree. I'll post here when that is updated on the repo and pip. If you think that is not the source of your error let me know!

Thanks for the quick response! Hmm, it is odd that you cannot reproduce it. I did not change anything in the notebook, but ran it as is. I don't think the explanation you suggested is correct, because

0 in dict(baseGraph.degree).values() # False

returns False, which means that all nodes have non-zero degree, right?

commented

I am having the exact same error..

Thank you both for re-elevating this issue. I know a bunch of people have been able to run the notebooks and package generally, so the problem here seems to be a strange one, but I will investigate further. If you can let me know what version of python you're running and any other environment factors that might be relevant that'd be helpful.

commented

I have python 2.7.15. Basically I have downloaded anaconda with python 2.7 and then launched Jupiter Notebook and ran your code

commented

I created a virtual environment with python 3.7 and everything works fine now! So I guess there was some kind of issue with the python version

Thanks @pjasc, that's helpful for me to know in tracking down the issue for python 2 users.

I'm having this issue with Python 3.6.8 and numpy version 1.15.1
Should I try python 3.7?

I found the problem. You can either upgrade to a newer version of numpy, or better yet the code could be modified not to sample from an empty list. See the comparison below:

import numpy as np
print(np.version)
np.random.choice([], size=0, replace=False)
1.16.2
array([], dtype=float64)

but in another venv:

import numpy as np
print(np.version)
np.random.choice([], size=0, replace=False)
1.15.1


ValueError Traceback (most recent call last)
in
1 import numpy as np
2 print(np.version)
----> 3 np.random.choice([], size=0, replace=False)

mtrand.pyx in mtrand.RandomState.choice()

ValueError: a must be non-empty

Excellent, upgrading numpy fixed it for me; but I agree that it would be best to update the code. Thank you!