Пример #1
0
    def nodeUpdateRule(self, node, srcNetwork, dt):
        # Read original node state.
        srcState = node[1][self.STATE_ATTR_NAME]
        # By default we have not changed states.
        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 == 'SA':
            # Allow for asymmetric transmission.        
            if eventp < self.beta_ba*nNSt['IB']*dt:
               dstState = 'IA'
        elif srcState == 'SB':
            if eventp < self.beta_ab*nNSt['IA']*dt:
               dstState = 'IB'
        elif srcState == 'IA':
            if eventp < self.gamma*dt:
                dstState = 'RA'
        elif srcState == 'IB':
            if eventp < self.gamma*dt:
                dstState = 'RB'

        node[1][self.STATE_ATTR_NAME] = dstState

        return node
Пример #2
0
    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
Пример #3
0
    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'] +nNSt['J']) + srcNetwork.graph['fracJ'])*dt:
                dstState = 'I'
        elif srcState == 'I':
            # Check recovery before super spreader.
            if eventp < self.gamma*dt:
                dstState = 'R'
            elif eventp - self.gamma*dt < self.alpha*dt:
                dstState = 'J'
                self.Jcounter += 1
            # Super spreaders are still infected and can recover.
        elif srcState == 'J':
            if eventp < self.gamma*dt:
               dstState = 'R' 
               self.Jcounter -= 1

        node[1][self.STATE_ATTR_NAME] = dstState

        return node
Пример #4
0
    def nodeUpdateRule(self, node, srcNetwork, dt):
        # Read original node state.
        srcState = node[1][self.STATE_ATTR_NAME]
        # By default we have not changed states.
        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()
        # Chose an action:
        #-------------------------------------------------#
            

        # Move from Susceptible to Acute
        if srcState == 'SA': 
            eventq = numpy.random.random_sample() 
            if eventp < (self.mu_a+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LA'
                else:
                    dstState = 'SA'
            elif eventq < self.nu_a*dt:
                dstState = 'VA'
            elif eventq < self.beta*(self.c*nNSt['AB']+nNSt['LB'])*dt:
               dstState = 'AA'
        elif srcState == 'SB':
            eventq = numpy.random.random_sample() 
            if eventp < (self.mu_b+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LB'
                else:
                    dstState = 'SB'
            elif eventq < self.nu_b*dt:
                dstState = 'VB'
            elif eventq < self.beta*(self.c*nNSt['AA']+nNSt['LA'])*dt:
               dstState = 'AB'
        # Move from Acute to Latent (or migrate)
        elif srcState == 'AA':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_a+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LA'
                else:
                    dstState = 'SA'
            elif eventq < self.eta*dt:
                dstState = 'LA'
        elif srcState == 'AB':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_b+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LB'
                else:
                    dstState = 'SB'
            elif eventq < self.eta*dt:
                dstState = 'LB'
        # Move from Latent to either Susceptible or Treated
        elif srcState == 'LA':
            eventq = numpy.random.random_sample()
            if eventp < (self.tau+self.mu_a+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LA'
                else:
                    dstState = 'SA'
            elif eventq < self.gamma_a*dt:
                dstState = 'TA'
        elif srcState == 'LB':
            eventq = numpy.random.random_sample()
            if eventp < (self.tau+self.mu_b+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LB'
                else:
                    dstState = 'SB'
            elif eventq < self.gamma_b*dt:
                dstState = 'TB'
        # Move from Treated to Susceptible
        elif srcState == 'TA':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_a+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LA'
                else:
                    dstState = 'SA'
        elif srcState == 'TB':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_b+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LB'
                else:
                    dstState = 'SB'
        # Vaccinated state
        elif srcState == 'VA':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_a+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LA'
                else:
                    dstState = 'SA'
        elif srcState == 'VB':
            eventq = numpy.random.random_sample()
            if eventp < (self.mu_b+self.delta)*dt:
                if eventq < self.alpha*dt:
                    dstState = 'LB'
                else:
                    dstState = 'SB'

        # update node with chosen state
        node[1][self.STATE_ATTR_NAME] = dstState

        return node