Commit 7d7c8dcb authored by Chris Jewell's avatar Chris Jewell
Browse files

Slight directory restructure

parent 6554f978
Copyright 2018 Chris Jewell <c.p.jewell@lancaster.ac.uk>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import pyods
#!/usr/bin/python
import unittest
import numpy as np
from .context import pyods
##########################################
# Atomic tests on Model structural tests #
##########################################
pop = ['A','B','C','D']
mintime = 0.
maxtime = 100.
timestep = 1.
obstime = 100.
infecTimes = np.array([1.3,1.35,2.4, maxtime])
vaccTimes = np.full(4,np.inf)
removeTimes = np.full(4,np.inf)
net = [[0,1,0,1],
[1,0,1,1],
[0,1,0,1],
[1,1,1,0]]
params = {'epsilon': 0.01,
'alpha': 0.9,
'beta': 0.9,
'theta': 0.2,
'gamma': 0.1}
class ModelTest(unittest.TestCase):
"""Basic Model functionality test"""
def setUp(self):
"""Simple SI model"""
model = pyods.Model(self.pop, self.mintime, self.timestep, self.obstime, self.maxtime)
S = model.createState('S', self.mintime)
I = model.createState('I', self.infecTimes)
wibble
if __name__=="__main__":
unittest.main()
# def test_Complex(self):
# """An SVIR model with the following structure:
# .-->V--.
# alpha | | theta
# | v
# S----->I---------------->R
# o | gamma
# | | beta
# '---'
# """
# self.model = pyods.Model(pop, mintime, timestep, obstime, maxtime)
# self.S = m.createState('S', mintime)
# self.I = m.createState('I', self.infecTimes)
# self.V = m.createState('V', self.vaccTimes)
# self.R = m.createState('R', self.removeTimes)
# SI = m.createTransition(S,I)
# SV = m.createTransition(S,V)
# VI = m.createTransition(V,I)
# IR = m.createTransition(I,R)
# epsilon = 0.01
# alpha = 0.9
# beta = 0.9
# theta = 0.2
# gamma = 0.1
# SI.addRate('Constant', epsilon)
# SI.addRate('StaticNetwork', net, beta, I)
# SV.addRate('Constant', alpha)
# VI.addRate('Constant', theta)
# IR.addRate('Constant', gamma)
# # Test OutbreakDS modules
# import numpy as np
# import random
# from pyods.model.Model import Model
# from pyods.simulator.Simulator import Simulator
# MINTIME = 0.
# TIMESTEP = 1.
# MAXOBSTIME = 25.
# MAXTIME = float("inf")
# popSize = 4
# #####################################################
# pop = ['P%i' % x for x in range(popSize)]
# initialInf = 1
# infecTimes = np.full(popSize, MAXTIME)
# vaccTimes = np.full(popSize, MAXTIME)
# removeTimes = np.full(popSize, MAXTIME)
# for i in range(initialInf):
# infecTimes[i] = MINTIME
# net = np.zeros((popSize,popSize))
# for x in range(net.shape[0]):
# for y in range(net.shape[1]):
# if random.random() < 0.005:
# net[x,y] = 1
# #####################################################
# m = Model(pop, MINTIME, TIMESTEP, MAXOBSTIME, MAXTIME)
# S = m.createState("S", MINTIME)
# I = m.createState("I", infecTimes)
# R = m.createState("R", removeTimes)
# SI = m.createTransition("SI", S, I)
# IR = m.createTransition("IR", I, R)
# # Parameters
# epsilon = 0.01
# alpha = 0.1
# beta = 0.9
# theta = 0.2
# gamma = 0.1
# # Construct rates
# SI.addRate('Constant', epsilon)
# #SI.addRate('StaticNetwork', net, beta, I)
# IR.addRate('Constant', gamma)
# simulation=Simulator(m)
# simulation.iterate()
# m.dumpExitRoutes()
# m.tabulate()
# #simulation.plotData()
# #m.dumpExitRoutes()
# #m.dumpTimes()
# print "Log likelihood: %0.2f" % m.getLogP()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment