示例#1
0
    def test_SimulateCTMC(self):
        '''
        Stochastic ode under the interpretation that we have a continuous
        time Markov chain as the underlying process 
        '''
        #x0 = [1,1.27e-6,0] # original
        x0 = [2362206.0, 3.0, 0.0]
        t = numpy.linspace(0, 250, 50)
        stateList = ['S', 'I', 'R']
        paramList = ['beta', 'gamma', 'N']
        transitionList = [
            Transition(origState='S',
                       destState='I',
                       equation='beta*S*I/N',
                       transitionType=TransitionType.T),
            Transition(origState='I',
                       destState='R',
                       equation='gamma*I',
                       transitionType=TransitionType.T)
        ]
        # initialize the model
        odeS = SimulateOdeModel(stateList,
                                paramList,
                                transitionList=transitionList)

        odeS.setParameters([0.5, 1.0 / 3.0, x0[0]]).setInitialValue(x0, t[0])
        solution = odeS.integrate(t[1::])
        odeS.transitionMean(x0, t[0])
        odeS.transitionVar(x0, t[0])

        odeS.transitionMean(solution[10, :], t[10])
        odeS.transitionVar(solution[10, :], t[10])

        simX, simT = odeS.simulateJump(250, 3, full_output=True)
    def test_SimulateCTMC(self):
        '''
        Stochastic ode under the interpretation that we have a continuous
        time Markov chain as the underlying process 
        '''
        #x0 = [1,1.27e-6,0] # original
        x0 = [2362206.0, 3.0, 0.0]
        t = numpy.linspace(0, 250, 50)
        stateList = ['S','I','R']
        paramList = ['beta','gamma','N']
        transitionList = [
                          Transition(origState='S',destState='I',equation='beta * S * I/N',transitionType=TransitionType.T),
                          Transition(origState='I',destState='R',equation='gamma * I',transitionType=TransitionType.T)
                          ]
        # initialize the model    
        odeS = SimulateOdeModel(stateList,
                                paramList,
                                transitionList=transitionList)

        odeS.setParameters([0.5, 1.0/3.0, x0[0]]).setInitialValue(x0, t[0])
        solution = odeS.integrate(t[1::])
        odeS.transitionMean(x0,t[0])
        odeS.transitionVar(x0,t[0])

        odeS.transitionMean(solution[10,:],t[10])
        odeS.transitionVar(solution[10,:],t[10])

        simX,simT = odeS.simulateJump(250, 3, full_output=True)