Esempio n. 1
0
    def test_lattice(self):
        # define links and network layout
        N_side = 20
        N = N_side**2
        links = get_2D_lattice_links(N_side,
                                     periodic=True,
                                     diagonal_links=True)
        network = get_grid_layout(N)

        # define model
        R0 = 3
        recovery_rate = 1 / 8
        model = StochasticSIRModel(N,
                                   R0,
                                   recovery_rate,
                                   edge_weight_tuples=links)
        model.set_random_initial_conditions({'I': 20, 'S': N - 20})

        sampling_dt = 2

        visualize(model,
                  network,
                  sampling_dt,
                  config={
                      'draw_nodes_as_rectangles': True,
                      'draw_links': False,
                      'show_legend': False,
                      'show_curves': False,
                  })
Esempio n. 2
0
    def test_network(self):
        N = 1000
        k = 4
        links = []
        for i in range(N):
            neighs = np.random.randint(0, N - 1, size=(k, ), dtype=int)
            neighs[neighs >= i] += 1
            for neigh in neighs:
                links.append((i, int(neigh), 1.0))

        network = get_random_layout(N, links, windowwidth=500)

        model = StochasticEpiModel(
            list("SIRXTQ"),
            N=len(network['nodes']),
            directed=True,
            edge_weight_tuples=links,
        )
        k0 = model.out_degree.mean()
        R0 = 10
        recovery_rate = 1 / 8
        quarantine_rate = 1 / 16
        tracing_rate = 1 / 2
        waning_immunity_rate = 1 / 14
        infection_rate = R0 * (recovery_rate) / k0
        model.set_node_transition_processes([
            ("I", recovery_rate, "R"),
            ("I", quarantine_rate, "T"),
            ("T", tracing_rate, "X"),
            ("Q", waning_immunity_rate, "S"),
            ("X", recovery_rate, "R"),
        ])
        model.set_link_transmission_processes([("I", "S", infection_rate, "I",
                                                "I")])
        model.set_conditional_link_transmission_processes({
            ("T", "->", "X"): [
                ("X", "I", 0.5, "X", "T"),
                #("X","S",0.5,"X","Q"),
            ],
        })
        model.set_random_initial_conditions({'I': 20, 'S': N - 20})

        sampling_dt = 0.08

        visualize(model,
                  network,
                  sampling_dt,
                  ignore_plot_compartments=['S'],
                  quarantine_compartments=['X', 'T', 'Q'])
Esempio n. 3
0
def MHRN_network_vis():
    import epipack as epk
    from epipack.vis import visualize
    import netwulf as nw

    network, _, __ = nw.load('../cookbook/readme_vis/MHRN.json')
    N = len(network['nodes'])
    links = [(l['source'], l['target'], 1.0) for l in network['links']]

    model = epk.StochasticEpiModel(["S","I","R"],N,links)\
                .set_link_transmission_processes([ ("I", "S", 1.0, "I", "I") ])\
                .set_node_transition_processes([ ("I", 1.0, "R") ])\
                .set_random_initial_conditions({ "S": N-5, "I": 5 })

    visualize(model, network, sampling_dt=0.1)
Esempio n. 4
0
    def test_grid_well_mixed(self):
        N = 20 * 20
        network = get_grid_layout(N)

        R0 = 3
        recovery_rate = 1 / 8
        model = StochasticSIRModel(N, R0, recovery_rate)
        model.set_random_initial_conditions({'I': 20, 'S': N - 20})

        sampling_dt = 2

        visualize(model,
                  network,
                  sampling_dt,
                  ignore_plot_compartments=['S'],
                  config={
                      'draw_nodes_as_rectangles': True,
                      'show_legend': False,
                  })
Esempio n. 5
0
def network_simulation_visualization():
    from epipack import StochasticEpiModel
    from epipack.plottools import plot
    import matplotlib.pyplot as pl
    import networkx as nx

    k0 = 50
    R0 = 2.5
    rho = 1
    eta = R0 * rho / k0
    omega = 1 / 14
    N = int(1e4)
    edges = [ (e[0], e[1], 1.0) for e in \
              nx.fast_gnp_random_graph(N,k0/(N-1)).edges() ]

    SIRS = StochasticEpiModel(
                compartments=list('SIR'),
                N=N,
                edge_weight_tuples=edges
                )\
            .set_link_transmission_processes([
                ('I', 'S', eta, 'I', 'I'),
            ])\
            .set_node_transition_processes([
                ('I', rho, 'R'),
                ('R', omega, 'S'),
            ])\
            .set_random_initial_conditions({
                                            'S': N-100,
                                            'I': 100
                                           })

    from epipack.vis import visualize
    from epipack.networks import get_random_layout
    layouted_network = get_random_layout(N, edges)
    visualize(SIRS,
              layouted_network,
              sampling_dt=0.1,
              config={'draw_links': False})
Esempio n. 6
0
model.set_node_transition_processes([
    ("I", recovery_rate, "R"),
    ("I", quarantine_rate, "T"),
    ("T", tracing_rate, "X"),
    ("Q", waning_immunity_rate, "S"),
])

model.set_conditional_link_transmission_processes({
    ("T", "->", "X"): [
        ("X", "I", 0.03, "X", "T"),
        ("X", "S", 0.03, "X", "Q"),
    ],
})
#model.set_random_initial_conditions({'I':20,'S':N-20})

# set initial conditions with a small number of infected
model.set_random_initial_conditions({'I': 10, 'S': N - 10})

# in every step of the simulation/visualization, let a time of `sampling_dt` pass
sampling_dt = 0.1

# simulate and visualize, do not plot the "S" count,
# and remove links from nodes that transition to "X"
visualize(
    model,
    network,
    sampling_dt,
    ignore_plot_compartments=[],
    quarantine_compartments=['X'],
)
Esempio n. 7
0
# usual infection process
model.set_link_transmission_processes([("I", "S", infection_rate, "I", "I")])

# standard SIR dynamic with additional quarantine of symptomatic infecteds
model.set_node_transition_processes([
    ("I", recovery_rate, "R"),
    ("I", quarantine_rate, "X"),
])

# set initial conditions with a small number of infected
model.set_random_initial_conditions({'I': 20, 'S': N - 20})

# in every step of the simulation/visualization, let a time of `sampling_dt` pass
sampling_dt = 0.12

# simulate and visualize, do not plot the "S" count,
# and remove links from nodes that transition to "X"
visualize(
    model,
    network,
    sampling_dt,
    ignore_plot_compartments=['S'],
    quarantine_compartments=['X'],
    config={
        #'link_color': '#A1A1A1',
        'compartment_colors':
        [colors[name] for name in palettes['french79 pastel']],
        'bgcolor':
        hex_bg_colors['french79 pastel'],
    })
Esempio n. 8
0
from epipack.vis import visualize, get_grid_layout
from epipack import StochasticSIRModel

if __name__ == "__main__":

    N = 100 * 100
    network = get_grid_layout(N)
    edge_list = [(link['source'], link['target'], 1.0)
                 for link in network['links']]

    R0 = 3
    recovery_rate = 1 / 8
    model = StochasticSIRModel(N, R0, recovery_rate)
    model.set_random_initial_conditions({'I': 20, 'S': N - 20})

    sampling_dt = 0.5

    visualize(model,
              network,
              sampling_dt,
              ignore_plot_compartments=['S'],
              config={'draw_nodes_as_rectangles': True})
Esempio n. 9
0
    ("Q", waning_immunity_rate, "S"),
])

model.set_conditional_link_transmission_processes({
    ("T", "->", "X"): [
        ("X", "I", 0.03, "X", "T"),
        ("X", "S", 0.03, "X", "Q"),
    ],
})
#model.set_random_initial_conditions({'I':20,'S':N-20})

# set initial conditions with a small number of infected
model.set_random_initial_conditions({'I': 10, 'S': N - 10})

# in every step of the simulation/visualization, let a time of `sampling_dt` pass
sampling_dt = 1

# simulate and visualize, do not plot the "S" count,
# and remove links from nodes that transition to "X"
visualize(model,
          network,
          sampling_dt,
          ignore_plot_compartments=['S'],
          quarantine_compartments=['X'],
          config={
              'compartment_colors':
              [colors[name] for name in palettes['brewer dark']],
              'bgcolor':
              hex_bg_colors['brewer dark'],
          })
Esempio n. 10
0
import epipack as epk
import epipack.vis as vis
import netwulf as nw

network, cfg, g = nw.load('MHRN.json')
N = len(network['nodes'])
links = [ (l['source'], l['target'], 1.0) for l in network['links'] ]

model = epk.StochasticEpiModel(["S","I","R"],N,links)\
            .set_link_transmission_processes([ ("I", "S", 1.0, "I", "I") ])\
            .set_node_transition_processes([ ("I", 1.0, "R") ])\
            .set_random_initial_conditions({ "S": N-5, "I": 5 })

vis.visualize(model, network, sampling_dt=0.1)
Esempio n. 11
0
from epipack.vis import visualize, get_grid_layout
from epipack import StochasticSISModel, get_2D_lattice_links

if __name__ == "__main__":

    N_side = 100
    N = N_side**2
    network = get_grid_layout(N)
    edge_list = get_2D_lattice_links(N_side,
                                     periodic=True,
                                     diagonal_links=False)

    R0 = 3
    recovery_rate = 1 / 8
    model = StochasticSISModel(N,
                               R0,
                               recovery_rate,
                               edge_weight_tuples=edge_list)
    model.set_random_initial_conditions({'I': 20, 'S': N - 20})

    sampling_dt = 1

    visualize(model,
              network,
              sampling_dt,
              config={
                  'draw_nodes_as_rectangles': True,
                  'show_legend': False
              })
Esempio n. 12
0
        #("I",quarantine_rate,"T"),
        ("T", tracing_rate, "X"),
        ("Q", waning_immunity_rate, "S"),
        ("X", recovery_rate, "R"),
    ])
    model.set_link_transmission_processes([("I", "S", infection_rate, "I", "I")
                                           ])
    model.set_conditional_link_transmission_processes({
        ("T", "->", "X"): [
            ("X", "I", 1, "X", "T"),
            ("X", "S", 1, "X", "Q"),
        ],
    })
    model.set_random_initial_conditions({'I': 20, 'S': N - 20})

    sampling_dt = 0.1

    visualize(
        model,
        network,
        sampling_dt,
        ignore_plot_compartments=['S', 'R'],
        quarantine_compartments=['X', 'T', 'Q'],
        config={
            'draw_nodes_as_rectangles': True,
            'draw_links': False,
            #'draw_nodes':False
            'plot_sampled_curve': True,
            'show_curves': False,
        })
Esempio n. 13
0
from epipack.vis import visualize, get_grid_layout
from epipack import StochasticSIRModel, get_2D_lattice_links

# define links and network layout
N_side = 100
N = N_side**2
links = get_2D_lattice_links(N_side, periodic=True, diagonal_links=True)
network = get_grid_layout(N)

# define model
R0 = 3; recovery_rate = 1/8
model = StochasticSIRModel(N,R0,recovery_rate,
                           edge_weight_tuples=links)
model.set_random_initial_conditions({'I':20,'S':N-20})

sampling_dt = 1

visualize(model,network,sampling_dt,
        config={
             'draw_nodes_as_rectangles':True,
             'draw_links':False,
           }
      )