def test_simulateParam2(self): ''' Stochastic ode under the interpretation that the parameters follow some sort of distribution. In this case, a function handle which has the same name as R ''' t0 = 0 # the initial state, normalized to zero one x0 = [1, 1.27e-6, 0] # set the time sequence that we would like to observe t = numpy.linspace(0, 150, 100) # Standard. Find the solution. ode = common_models.SIR() ode.setParameters([0.5, 1.0 / 3.0]) ode.setInitialValue(x0, t0) solutionReference = ode.integrate(t[1::], full_output=False) # now we need to define our ode explicitly stateList = ['S', 'I', 'R'] paramList = ['beta', 'gamma'] transitionList = [ Transition(origState='S', destState='I', equation='beta*S*I', transitionType=TransitionType.T), Transition(origState='I', destState='R', equation='gamma*I', transitionType=TransitionType.T) ] # our stochastic version odeS = SimulateOdeModel(stateList, paramList, transitionList=transitionList) # define our parameters in terms of two gamma distributions # where the expected values are the same as before [0.5,1.0/3.0] d = dict() d['beta'] = (rgamma, {'shape': 100.0, 'rate': 200.0}) d['gamma'] = (rgamma, (100.0, 300.0)) odeS.setParameters(d).setInitialValue(x0, t0) # now we generate the solutions solutionDiff = odeS.simulateParam(t[1::], 1000) - solutionReference # test :) if numpy.any(abs(solutionDiff) >= 0.2): raise Exception("Possible problem with simulating the parameters")
def test_simulateParam2(self): ''' Stochastic ode under the interpretation that the parameters follow some sort of distribution. In this case, a function handle which has the same name as R ''' t0 = 0 # the initial state, normalized to zero one x0 = [1,1.27e-6,0] # set the time sequence that we would like to observe t = numpy.linspace(0, 150, 100) # Standard. Find the solution. ode = common_models.SIR() ode.setParameters([0.5,1.0/3.0]) ode.setInitialValue(x0,t0) solutionReference = ode.integrate(t[1::],full_output=False) # now we need to define our ode explicitly stateList = ['S','I','R'] paramList = ['beta','gamma'] transitionList = [ Transition(origState='S',destState='I',equation='beta * S * I',transitionType=TransitionType.T), Transition(origState='I',destState='R',equation='gamma * I',transitionType=TransitionType.T) ] # our stochastic version odeS = SimulateOdeModel(stateList, paramList, transitionList=transitionList) # define our parameters in terms of two gamma distributions # where the expected values are the same as before [0.5,1.0/3.0] d = dict() d['beta'] = (rgamma,{'shape':100.0,'rate':200.0}) d['gamma'] = (rgamma,(100.0,300.0)) odeS.setParameters(d).setInitialValue(x0,t0) # now we generate the solutions solutionDiff = odeS.simulateParam(t[1::],1000) - solutionReference # test :) if numpy.any(abs(solutionDiff)>=0.2): raise Exception("Possible problem with simulating the parameters")