Forum >> Principianti >> Usare funzioni di Nepidemix

Pagina: 1

Salve, come faccio ad utilizzare le funzioni di questa classe?
from nepidemix.process import ExplicitStateProcess

from nepidemix.utilities.networkxtra import attributeCount, neighbors_data_iter

import numpy


class SIRProcess(ExplicitStateProcess):
"""
S I R process,

Attributes
----------
beta - Infection rate.
gamma - Recovery rate.
"""
def __init__(self, beta, gamma):

super(SIRProcess, self).__init__(['S', 'I', 'R'],
[],
runNodeUpdate = True,
runEdgeUpdate = False,
runNetworkUpdate = False,
constantTopology = True)
self.beta = float(beta)
self.gamma = float(gamma)


def nodeUpdateRule(self, node, srcNetwork, dt):
# Read original node state.
srcState = node[1][self.STATE_ATTR_NAME]
# By default we have not changed states, so set
# the destination state to be the same as the source state.
dstState = srcState

# Start out with a dictionary of zero neighbors in each state.
nNSt = dict(zip(self.nodeStateIds,[0]*len(self.nodeStateIds)))
# Calculate the actual numbers and update dictionary.
nNSt.update(attributeCount(neighbors_data_iter(srcNetwork, node[0]),
self.STATE_ATTR_NAME))

# Pick a random number.
eventp = numpy.random.random_sample()
# Go through each state name, and chose an action.
if srcState == 'S':
if eventp < self.beta*nNSt['I']*dt:
dstState = 'I'
elif srcState == 'I':
if eventp < self.gamma*dt:
dstState = 'R'

node[1][self.STATE_ATTR_NAME] = dstState

return node


Grazie a tutti :)


Pagina: 1



Esegui il login per scrivere una risposta.