Skip to content

Commit

Permalink
'resolved'
Browse files Browse the repository at this point in the history
  • Loading branch information
j-i-l committed Aug 25, 2019
2 parents 0e7eddf + f42b5e5 commit 0152c9d
Show file tree
Hide file tree
Showing 14 changed files with 1,567 additions and 620 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
EndemicPy is written (and eventually maintained) by Jonas I. Liechti
=======

Main Authors
````````````

- Jonas I. Liechti <jonas.i.liechti@protonmail.ch> `@j-i-l <https://github.com/j-i-l>`_, Creator.
- Jonas I. Liechti <jonas.i.liechti@gmail.com> `@j-i-l <https://github.com/j-i-l>`_, Creator.


Patches and Suggestions
Expand Down
13 changes: 13 additions & 0 deletions LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2015 Jonas I. Liechti

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Endemic is a python package to run diseas spreading simulations on various host structures
=====


Features
--------

- Static and temporal host networks

- Extended .
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Jonas I Liechti'
6 changes: 3 additions & 3 deletions endemic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
__title__ = 'endemic'
__version__ = '0.1.0'
#__build__ =
__version__ = '0.3.0'
# __build__ =
__author__ = 'Jonas I Liechti'
__license__ = 'MIT'
__copyright__ = 'Copyright 2016 Jonas I. Liechti'
__copyright__ = 'Copyright 2019 Jonas I. Liechti'
"""
Expand Down
265 changes: 180 additions & 85 deletions endemic/nw_construct/GraphConstructor.py

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions endemic/nw_construct/create_nw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
__author__ = 'Jonas I Liechti'
#this will be used to create a command line tool, so it is of no importance here.
from argparse import ArgumentParser

from endemic.nw_construct import Graph


def main():
parser = ArgumentParser(description='Generate a network following a probabilistic framework.',
epilog="Note: Only the options specific for the chosen network_type need to be\
entered."
)
parser.add_argument('n', metavar='n', type=int,
help='the number of nodes in the network.')
parser.add_argument('--type', dest='network_type', type=str,
help='chose the type of network to construct.')
parser.add_argument('--method', dest='method', type=str, default='stub',
help="set the network construction method (stub or proba, default: stub).")
parser.add_argument('--file', dest='filename', type=str,
help='The file where the network will be stored')
parser.add_argument('--format', dest='fileformat', type=str, default='edges',
help="Specify the format of the destination file (default: edges). If the format is given with \
the filename, this argument is ignored.")
parser.add_argument('--shape', dest='shape', type=float,
help='The shape parameter of a distribution (for gamma, exponential and weibull)')
#is a for weibull
parser.add_argument('--centre', dest='loc', type=float,
help='Centre of the normal distribution.')
parser.add_argument('--scale', dest='scale', type=float,
help='The scale parameter of a distribution (for gamma, normal and exponential)')
parser.add_argument('--trials', dest='n', type=int,
help='The number of trials for a binomial distribution')
parser.add_argument('--p', dest='p', type=float,
help='The success probability (for binomial and geometric).')
parser.add_argument('--lambda', dest='lam', type=float,
help='Expected value for the poisson distribution')
parser.add_argument('--1+exponent', dest='a', type=float,
help='Set the exponent for a power distribution (the dist will be p(x,a)=ax^{a-1}).')
parser.add_argument('--l', dest='l', type=int,
help='In l-partition network, the number of partitions in an l-partition graph.')
parser.add_argument('--avg_degree', dest='avg_degree', type=float,
help="In l-partition network, the expected average degree of each node in the l-partition \
network.")
parser.add_argument('--density_ratio', dest='density_ratio', type=float,
help="In l-partition network, the egde-density ratio between inter- and intra-partition links \
(eg. 2: inside twice as dense as outside)")
parser.add_argument('--p_in', dest='p_in', type=float,
help='In l-partition network, the connection probability of any pair inside a partition.')
parser.add_argument('--p_out', dest='p_out', type=float,
help='In l-partition network, the connection probability of any pair in-between partitions.')
#parser.add_argument('integer', metavar='n', type=str, nargs='+',
# help='an integer for the accumulator')
#parser.add_argument('--sum', dest='accumulate', action='store_const',
# const=sum, default=max,
# help='sum the integers (default: find the max)')

args = parser.parse_args()
as_dict = args.__dict__
filename = as_dict.pop('filename')
fileformat = as_dict.pop('fileformat')
if as_dict['network_type'] == 'weibull':
as_dict['a'] = as_dict.pop('shape')
if filename is None:
raise IOError('Please specify a destination to save the graph (--file FILENAME)')
for key in as_dict.keys():
if as_dict[key] is None:
as_dict.pop(key)
g = Graph(n=as_dict.pop('n'), method=as_dict.pop('method'), **as_dict)
g.export_graph(filename=filename, fileformat=fileformat)
return 0
38 changes: 38 additions & 0 deletions endemic/nw_construct/test_neg_binom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from GraphConstructor import Graph

n=100000
k=4
var=2.0
#distro = 'negative_binomial'
distro = 'gamma'

def get_p(k, var):
"""
In the numpy implementation the probability of success is needed, so
this returns to probability of success.
"""
return k/float(var)
def get_r(k, var):
#return (k**2/var)*(1/(var/float(k)-1))
return int(k**2/(var - k))
def get_scale(k,var):
return var / float(k)
def get_shape(k,var):
return k ** 2 / float(var)
distribution_params = {}
distribution_params['network_type'] = distro
if var== 0.0:
distribution_params['network_type'] = 'uniform'
distribution_params['degree'] = k
elif distro == 'negative_binomial':
distribution_params['p'] = get_p(k,var)
distribution_params['n'] = get_r(k,var)
elif distro == 'gamma':
distribution_params['scale'] = get_scale(k,var)
distribution_params['shape'] = get_shape(k,var)

m_g = Graph(
N=n,
method='stub',
**distribution_params
)
7 changes: 6 additions & 1 deletion endemic/nw_spread/HostStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(self, from_object, susceptible=1, is_static=True):

@property
def info(self):
# ToDo: would make sense to define this.
return self.graph_info

def _check_integrity(self):
Expand Down Expand Up @@ -193,13 +194,17 @@ def get_events(self, node_id, start_time, delta_t):
)
nn1 = self.node1s.view()[the_filter]
nn2 = self.node2s.view()[the_filter]

nn = np.where(
node_id != nn1,
nn1,
nn2
)
return nn, self.starts.view()[the_filter], \
return (
nn,
self.starts.view()[the_filter],
self.stops.view()[the_filter]
)


class Host():
Expand Down
2 changes: 1 addition & 1 deletion endemic/nw_spread/RateDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def __setstate__(self, d):
self.queue = SimpleQueue(maxsize=self.pre + 1)
self.v_put = vectorize(self.queue.put_nowait) # this is specific to the queue, thus reinit here
self.draw_fct = no_mut
self.fillup()
self.fillup()
Loading

0 comments on commit 0152c9d

Please sign in to comment.