示例#1
0
	def setUp( self ):
		'''Set up the parameters.'''
		# set lab and test parameters
		self._lab = epyc.Lab()

		self._lab[GFs.T] = [0.6, 0.9]
		self._lab[GFs.N] = 5000
		self._lab[GFs.AVERAGE_K] = 5

		# repetitions at each point in the parameter space
		self._repetitions = 1
示例#2
0
def main():
    e = NetworkVariabilityExperiment(params)

    # TODO: Add capability to save study file in user-specified location
    nb = epyc.JSONLabNotebook('network-variability-study.json')
    lab = epyc.Lab(nb)

    for key in asdict(params):
        lab[key] = asdict(params)[key]

    lab.runExperiment(epyc.RepeatedExperiment(e, 1))
示例#3
0
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict(pInfect=0.1, pInfected=0.01, tInfected=1)
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab['pInfect'] = [0.1, 0.2, 0.3]
        self._lab['pInfected'] = [0.01]
        self._lab['tInfected'] = [0.5, 1, 2]
示例#4
0
文件: sir.py 项目: samzhaoziran/cncp
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict(pInfect=0.01, pInfected=0.001, pRecover=0.02)
        self._er = networkx.erdos_renyi_graph(5000, 0.004)

        # lab run
        self._lab = epyc.Lab()
        self._lab['pInfect'] = [0.01]
        self._lab['pInfected'] = [0.001, 0.002, 0.005]
        self._lab['pRecover'] = [0.02]
示例#5
0
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict()
        self._params[SIR_FixedRecovery.P_INFECT] = 0.1
        self._params[SIR_FixedRecovery.P_INFECTED] = 0.01
        self._params[SIR_FixedRecovery.T_INFECTED] = 1
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab[SIR_FixedRecovery.P_INFECT] = [0.1, 0.3]
        self._lab[SIR_FixedRecovery.P_INFECTED] = [0.01]
        self._lab[SIR_FixedRecovery.T_INFECTED] = [0.5, 1, 2]
示例#6
0
 def testEpidemic(self):
     '''Test we get an epidemic'''
     self._lab = epyc.Lab()
     self._lab[SIR.P_INFECT] = 0.3
     self._lab[SIR.P_INFECTED] = 0.01
     self._lab[SIR.P_REMOVE] = 0.05
     e = StochasticDynamics(self._model, self._network)
     self._lab.runExperiment(e)
     rc = (self._lab.results())[0]
     six.assertCountEqual(self, rc[epyc.Experiment.RESULTS],
                          ['S', 'I', 'R'])
     self.assertTrue(rc[epyc.Experiment.RESULTS]['S'] > 0)
     self.assertTrue(rc[epyc.Experiment.RESULTS]['I'] == 0)
     self.assertTrue(rc[epyc.Experiment.RESULTS]['R'] > 0)
     self.assertEqual(
         rc[epyc.Experiment.RESULTS]['S'] +
         rc[epyc.Experiment.RESULTS]['R'], self._network.order())
示例#7
0
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single epidemic-causing experiment
        self._params = dict()
        self._params[SIR.P_INFECT] = 0.3
        self._params[SIR.P_INFECTED] = 0.01
        self._params[SIR.P_REMOVE] = 0.05
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab[SIR.P_INFECT] = [0.1, 0.3]
        self._lab[SIR.P_INFECTED] = 0.01
        self._lab[SIR.P_REMOVE] = [0.05, 1]

        # model
        self._model = SIR()
示例#8
0
    def testEpidemic(self):
        '''Test we get an epidemic'''
        self._lab = epyc.Lab()
        self._lab[SIR.P_INFECT] = 0.3
        self._lab[SIR.P_INFECTED] = 0.01
        self._lab[SIR.P_REMOVE] = 0.05
        e = StochasticDynamics(self._model, self._network)
        self._lab.runExperiment(e)
        rc = (self._lab.results())[0]

        self.assertCountEqual(rc[epyc.Experiment.RESULTS],
                              [SIR.SUSCEPTIBLE, SIR.INFECTED, SIR.REMOVED])
        self.assertTrue(rc[epyc.Experiment.RESULTS][SIR.SUSCEPTIBLE] > 0)
        self.assertTrue(rc[epyc.Experiment.RESULTS][SIR.INFECTED] == 0)
        self.assertTrue(rc[epyc.Experiment.RESULTS][SIR.REMOVED] > 0)
        self.assertEqual(
            rc[epyc.Experiment.RESULTS][SIR.SUSCEPTIBLE] +
            rc[epyc.Experiment.RESULTS][SIR.REMOVED], self._network.order())
示例#9
0
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict(pInfect=0.1, pInfected=0.01, pRemove=0.05)
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab['pInfect'] = [0.1, 0.2, 0.3]
        self._lab['pInfected'] = [0.01]
        self._lab['pRecover'] = [0.05, 0.1, 1]

        # model
        self._model = SIR()

        # no maximum time needed
        self._maxTime = None
示例#10
0
文件: sis.py 项目: wwbrannon/epydemic
    def setUp(self):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict()
        self._params[SIS.P_INFECT] = 0.1
        self._params[SIS.P_INFECTED] = 0.01
        self._params[SIS.P_REMOVE] = 0.05
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab[SIS.P_INFECT] = [0.1, 0.3]
        self._lab[SIS.P_INFECTED] = 0.01
        self._lab[SIS.P_REMOVE] = [0.05, 1]

        # model
        self._model = SIS()

        # maximum time needed as disease may be endemic
        self._maxTime = 2000
示例#11
0
    def testHDF5(self):
        '''Test we can save and retrieve the time series as HDF5.'''
        tf = NamedTemporaryFile()
        tf.close()
        fn = tf.name
        #fn = 'test.h5'

        try:
            nb = epyc.HDF5LabNotebook(fn, create=True)
            lab = epyc.Lab(nb)

            # run the experiment
            m = MonitoredSIR()
            m.setMaximumTime(100)
            e = StochasticDynamics(
                m, networkx.erdos_renyi_graph(1000, 5.0 / 1000))
            lab[SIR.P_INFECTED] = 0.01
            lab[SIR.P_INFECT] = 0.002
            lab[SIR.P_REMOVE] = 0.002
            lab[Monitor.DELTA] = 1.0
            rc = lab.runExperiment(e)
            df = lab.dataframe()

            # check we read back in correctly
            with epyc.HDF5LabNotebook(fn).open() as nb1:
                df1 = nb1.dataframe()
                r = df.iloc[0]
                r1 = df1.iloc[0]
                for f in [
                        Monitor.OBSERVATIONS,
                        Monitor.timeSeriesForLocus(SIR.SI),
                        Monitor.timeSeriesForLocus(SIR.INFECTED)
                ]:
                    self.assertCountEqual(r[f], r1[f])
        finally:
            try:
                os.remove(fn)
                #pass
            except OSError:
                pass
示例#12
0
    def setUp( self ):
        '''Set up the experimental parameters and experiment.'''

        # single experiment
        self._params = dict()
        self._params[SEIR.P_INFECT_SYMPTOMATIC] = 0.3
        self._params[SEIR.P_INFECT_ASYMPTOMATIC] = 0.3
        self._params[SEIR.P_EXPOSED] = 0.01
        self._params[SEIR.P_SYMPTOMS] = 0.05
        self._params[SEIR.P_REMOVE] = 0.05
        self._network = networkx.erdos_renyi_graph(1000, 0.005)

        # lab run
        self._lab = epyc.Lab()
        self._lab[SEIR.P_INFECT_SYMPTOMATIC] = 0.1
        self._lab[SEIR.P_INFECT_ASYMPTOMATIC] = [ 0.1,  0.3 ]
        self._lab[SEIR.P_EXPOSED] = 0.01
        self._lab[SEIR.P_SYMPTOMS] = [ 0.05, 1 ]
        self._lab[SEIR.P_REMOVE] = 0.05

        # model
        self._model = SEIR()
示例#13
0
import matplotlib
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import seaborn


class CurveExperiment(epyc.Experiment):

    def do(self, params):
        x = params['x']
        y = params['y']
        r = numpy.sin(numpy.sqrt(x ** 2 + y ** 2))
        return dict(result=r)

lab = epyc.Lab(notebook=epyc.LabNotebook(description="A point cloud of $sin \sqrt{x^2 + y^2}$"))
lab['x'] = numpy.linspace(-2 * numpy.pi, 2 * numpy.pi)
lab['y'] = numpy.linspace(-2 * numpy.pi, 2 * numpy.pi)
lab.runExperiment(CurveExperiment())

df = lab.notebook().dataframe()
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')

ax.scatter(df['x'], df['y'], df['result'], c = df['result'], depthshade = False, cmap = cm.coolwarm)
ax.set_xlim(numpy.floor(df['x'].min()), numpy.ceil(df['x'].max()))
ax.set_ylim(numpy.floor(df['y'].min()), numpy.ceil(df['y'].max()))
ax.set_zlim(numpy.floor(df['result'].min()), numpy.ceil(df['result'].max()))

plt.title(lab.notebook().description())
ax.set_xlabel('$x$')