def test__init__(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']
        contact_data_matrix = np.array([[10, 5.2], [0, 3]])
        region_data_matrix = np.array([[0.5, 1.2], [0.29, 6]])
        pop_size = [18, 2]
        dI = 4

        contacts = em.ContactMatrix(age_groups, contact_data_matrix)
        regional = em.RegionMatrix(region_name, age_groups, region_data_matrix)
        next_gen = em.UniNextGenMatrix(pop_size, contacts, regional, dI)

        self.assertEqual(next_gen.region, 'London')
        npt.assert_array_equal(next_gen.ages, np.array(['0-10', '10-25']))
        npt.assert_array_equal(next_gen.susceptibles, np.array([18, 2]))
        npt.assert_array_equal(next_gen.contacts, contact_data_matrix)
        npt.assert_array_equal(next_gen.regional_suscep, region_data_matrix)
        self.assertEqual(next_gen.infection_period, 4)

        pdt.assert_frame_equal(
            next_gen.get_next_gen_matrix(),
            pd.DataFrame(data=np.array([[360, 449.28], [0, 144]]),
                         index=['0-10', '10-25'],
                         columns=['0-10', '10-25']))

        with self.assertRaises(TypeError):
            em.UniNextGenMatrix(pop_size, 0, regional, dI)

        with self.assertRaises(TypeError):
            em.UniNextGenMatrix(pop_size, contacts, 0, dI)

        with self.assertRaises(ValueError):
            new_age_groups = ['0-15', '15-25']
            regional1 = em.RegionMatrix(region_name, new_age_groups,
                                        region_data_matrix)
            em.UniNextGenMatrix(pop_size, contacts, regional1, dI)

        with self.assertRaises(TypeError):
            em.UniNextGenMatrix(pop_size, contacts, regional, '4')

        with self.assertRaises(ValueError):
            em.UniNextGenMatrix(pop_size, contacts, regional, 0)

        with self.assertRaises(ValueError):
            em.UniNextGenMatrix([[1], [2]], contacts, regional, dI)

        with self.assertRaises(ValueError):
            em.UniNextGenMatrix([0, 1, 1], contacts, regional, dI)

        with self.assertRaises(ValueError):
            em.UniNextGenMatrix([0, -1], contacts, regional, dI)

        with self.assertRaises(TypeError):
            em.UniNextGenMatrix([0, '1'], contacts, regional, dI)
    def test__init__(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[10, 0], [0, 3]])
        region_data_matrix_0 = np.array([[0.5, 0], [0, 6]])
        init_pop_size = [1, 2]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        regional_0 = em.RegionMatrix(region_name, age_groups,
                                     region_data_matrix_0)
        next_gen_0 = em.UniNextGenMatrix(init_pop_size, contacts_0, regional_0,
                                         dI)

        initial_r = 0.5
        infect = em.UniInfectivityMatrix(initial_r,
                                         initial_nextgen_matrix=next_gen_0)

        self.assertEqual(infect.r0, 0.5)
        self.assertEqual(infect.r0_star, 144)

        with self.assertRaises(TypeError):
            em.UniInfectivityMatrix('0', initial_nextgen_matrix=next_gen_0)

        with self.assertRaises(TypeError):
            em.UniInfectivityMatrix(initial_r, initial_nextgen_matrix=0)
    def __init__(self):
        # Instantiate model
        super(TestPHEModel, self).__init__()

        # Populate the model
        regions = ['SW']
        age_groups = [
            '65-75', '75+']

        matrices_region = []

        # Initial state of the system
        weeks_matrices_region = []
        for r in regions:
            region_data_matrix = np.array([[0.5025, 0.1977], [0.1514, 0.7383]])
            regional = em.RegionMatrix(r, age_groups, region_data_matrix)
            weeks_matrices_region.append(regional)

        matrices_region.append(weeks_matrices_region)

        contacts = em.ContactMatrix(
            age_groups, np.ones((len(age_groups), len(age_groups))))
        matrices_contact = [contacts]

        # Matrices contact
        time_changes_contact = [1]
        time_changes_region = [1]

        # Set the region names, age groups, contact and regional data of the
        # model
        self.set_regions(regions)
        self.set_age_groups(age_groups)
        self.read_contact_data(matrices_contact, time_changes_contact)
        self.read_regional_data(matrices_region, time_changes_region)
    def test_plot_heat_map(self):
        with patch('plotly.graph_objs.Figure.show') as show_patch:
            region_name = 'London'
            age_groups = ['0-10', '10-25']
            data_matrix = np.array([[10, 5.2], [0, 3]])
            r = em.RegionMatrix(region_name, age_groups, data_matrix)

            r.plot_heat_map()

        # Assert show_figure is called once
        assert show_patch.called
    def test_compute_reproduction_number(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[10, 0], [0, 3]])
        region_data_matrix_0 = np.array([[0.5, 0], [0, 6]])
        init_pop_size = [1, 2]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        regional_0 = em.RegionMatrix(region_name, age_groups,
                                     region_data_matrix_0)
        next_gen_0 = em.UniNextGenMatrix(init_pop_size, contacts_0, regional_0,
                                         dI)

        # Later time state of the system
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])
        region_data_matrix_1 = np.array([[0.5, 1.2], [0.29, 6]])
        current_pop_size = [18, 2]

        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_1 = em.RegionMatrix(region_name, age_groups,
                                     region_data_matrix_1)
        next_gen_1 = em.UniNextGenMatrix(current_pop_size, contacts_1,
                                         regional_1, dI)

        initial_r = 0.5
        temp_variation = 1
        infect = em.UniInfectivityMatrix(initial_r,
                                         initial_nextgen_matrix=next_gen_0)

        self.assertEqual(
            infect.compute_reproduction_number(temp_variation, next_gen_1),
            5 / 4)

        with self.assertRaises(TypeError):
            infect.compute_reproduction_number('1', next_gen_1)

        with self.assertRaises(TypeError):
            infect.compute_reproduction_number(temp_variation, 0)
    def test_change_region_name(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']
        data_matrix = np.array([[10, 5.2], [0, 3]])
        r = em.RegionMatrix(region_name, age_groups, data_matrix)

        new_region_name = 'Oxford'
        r.change_region_name(new_region_name)

        self.assertEqual(r.region, 'Oxford')

        with self.assertRaises(TypeError):
            r.change_region_name(0)
    def test_compute_dom_eigenvalue(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']
        contact_data_matrix = np.array([[10, 0], [0, 3]])
        region_data_matrix = np.array([[0.5, 0], [0, 6]])
        pop_size = [1, 2]
        dI = 4

        contacts = em.ContactMatrix(age_groups, contact_data_matrix)
        regional = em.RegionMatrix(region_name, age_groups, region_data_matrix)
        next_gen = em.UniNextGenMatrix(pop_size, contacts, regional, dI)

        self.assertEqual(next_gen.compute_dom_eigenvalue(), 144)
    def test__init__(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']
        data_matrix = np.array([[10, 5.2], [0, 3]])
        r = em.RegionMatrix(region_name, age_groups, data_matrix)

        self.assertEqual(r.region, 'London')
        self.assertEqual(r.num_a_groups, 2)
        npt.assert_array_equal(r.ages, np.array(['0-10', '10-25']))
        pdt.assert_frame_equal(
            r.region_matrix,
            pd.DataFrame(data=np.array([[10, 5.2], [0, 3]]),
                         index=['0-10', '10-25'],
                         columns=['0-10', '10-25']))

        with self.assertRaises(ValueError):
            em.RegionMatrix(region_name, '0', data_matrix)

        with self.assertRaises(TypeError):
            em.RegionMatrix(region_name, [0, '1'], data_matrix)

        with self.assertRaises(TypeError):
            em.RegionMatrix(region_name, ['0', 1], data_matrix)

        with self.assertRaises(ValueError):
            em.RegionMatrix(region_name, age_groups, [1])

        with self.assertRaises(ValueError):
            em.RegionMatrix(region_name, age_groups,
                            np.array([[10, 5, 0], [0, 0, 3]]))

        with self.assertRaises(ValueError):
            em.RegionMatrix(region_name, age_groups,
                            np.array([[10, 5], [0, 3], [0, 0]]))

        with self.assertRaises(TypeError):
            em.RegionMatrix(region_name, age_groups,
                            np.array([[10, 5], [0, '3']]))

        with self.assertRaises(TypeError):
            em.RegionMatrix([0], age_groups, data_matrix)
    def test_change_age_groups(self):
        region_name = 'London'
        age_groups = ['0-10', '10-25']
        data_matrix = np.array([[10, 5.2], [0, 3]])
        r = em.RegionMatrix(region_name, age_groups, data_matrix)

        new_age_groups = ['0-15', '15-25']
        r.change_age_groups(new_age_groups)

        self.assertEqual(r.num_a_groups, 2)
        npt.assert_array_equal(r.ages, np.asarray(['0-15', '15-25']))
        pdt.assert_frame_equal(
            r.region_matrix,
            pd.DataFrame(data=np.array([[10, 5.2], [0, 3]]),
                         index=['0-15', '15-25'],
                         columns=['0-15', '15-25']))

        with self.assertRaises(ValueError):
            r.change_age_groups(['0-15', '15-25', '25+'])
Ejemplo n.º 10
0
    def test_new_infections(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver'
        ]

        times = [1, 2]

        output = model.simulate(list(deepflatten(parameters, ignore=str)),
                                times)

        npt.assert_array_equal(model.new_infections(output),
                               np.array([[0, 0], [0, 0]]))

        with self.assertRaises(ValueError):
            output1 = np.array([5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
            model.new_infections(output1)

        with self.assertRaises(ValueError):
            output1 = np.array([[5, 6, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0]])
            model.new_infections(output1)

        with self.assertRaises(ValueError):
            output1 = np.array([[5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
            model.new_infections(output1)

        with self.assertRaises(TypeError):
            output1 = np.array([['5', 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
            model.new_infections(output1)
    def test__init__(self):
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[10, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[0, 2], [1, 1]]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        initial_r = [0.5, 1]

        m = em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        self.assertEqual(m._regions, ['London', 'Cornwall'])
        npt.assert_array_equal(m.initial_r, np.array([0.5, 1]))
        self.assertEqual(m.dI, 4)
        npt.assert_array_equal(m.times_contact, np.array([1, 3]))
        npt.assert_array_equal(m.times_region, np.array([1, 2]))
        self.assertCountEqual(m.contact_matrices, matrices_contact)
        self.assertCountEqual(m.region_matrices, matrices_region)
        self.assertEqual(len(m.initial_infec_matrices), 2)

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(0, time_changes_contact, regions,
                                     matrices_region, time_changes_region,
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity([contacts_0, 0], time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, 1, regions,
                                     matrices_region, time_changes_region,
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, [1], regions,
                                     matrices_region, time_changes_region,
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity(matrices_contact, [1, 1.5], regions,
                                     matrices_region, time_changes_region,
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, [0, 1], regions,
                                     matrices_region, time_changes_region,
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     'London', matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     [0, 'London'], matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, [regional_1_0, regional_1_1],
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            matrices_region_1 = [[regional_0_0], [regional_1_0]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region_1,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(TypeError):
            matrices_region_1 = [[regional_0_0, 1],
                                 [regional_1_0, regional_1_1]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region_1,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            matrices_region_1 = [[regional_0_0, regional_0_1],
                                 [
                                     regional_1_0,
                                     em.RegionMatrix(regions[0], age_groups,
                                                     region_data_matrix_1_1)
                                 ]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region_1,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region, 1, initial_r,
                                     dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region, [1, 2, 3],
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region, [1, '2'],
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region, [0, 2],
                                     initial_r, dI, susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, 0.5, dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, [0.5], dI,
                                     susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, [0.5, '1'], dI,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, [0.5, 0], dI,
                                     susceptibles[0])

        with self.assertRaises(TypeError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, '4',
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, 0,
                                     susceptibles[0])

        with self.assertRaises(ValueError):
            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI, [1])

        with self.assertRaises(ValueError):
            susceptibles_1 = [[[1], [3]], [[5], [7]], [[0], [1]]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles_1[0])

        with self.assertRaises(ValueError):
            susceptibles_1 = [[[1, 2]], [[5, 6]], [[0, 2]]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles_1[0])

        with self.assertRaises(TypeError):
            susceptibles_1 = [[[1, '2'], [3, 4]], [[5, 6], [7, 8]],
                              [[0, 2], [1, 1]]]

            em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles_1[0])
    def test_compute_reproduction_number(self):
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[10, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[0, 2], [1, 1]]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        initial_r = [0.5, 1]

        m = em.MultiTimesInfectivity(matrices_contact, time_changes_contact,
                                     regions, matrices_region,
                                     time_changes_region, initial_r, dI,
                                     susceptibles[0])

        self.assertEqual(
            m.compute_reproduction_number(1, 3, susceptibles[2][0]), 0.5)

        with self.assertRaises(TypeError):
            m.compute_reproduction_number('1', 3, susceptibles[2][0], 1)

        with self.assertRaises(ValueError):
            m.compute_reproduction_number(3, 3, susceptibles[2][0], 1)

        with self.assertRaises(ValueError):
            m.compute_reproduction_number(0, 3, susceptibles[2][0], 1)

        with self.assertRaises(TypeError):
            m.compute_reproduction_number(1, '3', susceptibles[2][0], 1)

        with self.assertRaises(ValueError):
            m.compute_reproduction_number(1, 0, susceptibles[2][0], 1)

        with self.assertRaises(TypeError):
            m.compute_reproduction_number(1, 3, susceptibles[2][0], '1')
Ejemplo n.º 13
0
    def test_samples_deaths(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0.1, 0.2], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 60, [1] * 60], 4, dI, 0.5, 'my-solver'
        ]

        times = np.arange(1, 61).tolist()

        output = model.simulate(list(deepflatten(parameters, ignore=str)),
                                times)

        new_infections = model.new_infections(output)

        fatality_ratio = [0.1, 0.5]

        td_mean = 15.0
        td_var = 12.1**2
        theta = td_var / td_mean
        k = td_mean / theta
        time_to_death = gamma(k, scale=theta).pdf(np.arange(1, 60)).tolist()

        self.assertEqual(
            model.samples_deaths(new_infections, fatality_ratio, time_to_death,
                                 0.5, 41).shape, (len(age_groups), ))

        self.assertEqual(
            model.samples_deaths(new_infections, fatality_ratio, time_to_death,
                                 0.5, 1).shape, (len(age_groups), ))

        with self.assertRaises(ValueError):
            model.samples_deaths(new_infections, fatality_ratio, time_to_death,
                                 0.5, -1)

        with self.assertRaises(TypeError):
            model.samples_deaths(new_infections, fatality_ratio, time_to_death,
                                 0.5, '1')

        with self.assertRaises(ValueError):
            model.samples_deaths(new_infections, fatality_ratio, time_to_death,
                                 0.5, 62)
Ejemplo n.º 14
0
    def test_simulate(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 2, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 2, [1] * 2], 4, dI, 0.5, 'RK45'
        ]

        times = [1, 2]

        output_my_solver = model.simulate(
            list(deepflatten(parameters, ignore=str)), times)

        npt.assert_almost_equal(
            output_my_solver,
            np.array([[7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                      [7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]),
            decimal=3)

        parameters[-1] = 'my-solver'

        output_scipy_solver = model.simulate(
            list(deepflatten(parameters, ignore=str)), times)

        npt.assert_almost_equal(
            output_scipy_solver,
            np.array([[7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                      [7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]),
            decimal=3)

        parameters[-1] = 'my-solver'

        with self.assertRaises(TypeError):
            model.simulate(list(deepflatten(parameters, ignore=str)), '0')

        with self.assertRaises(TypeError):
            model.simulate(list(deepflatten(parameters, ignore=str)), ['1', 2])

        with self.assertRaises(ValueError):
            model.simulate(list(deepflatten(parameters, ignore=str)), [0, 1])

        with self.assertRaises(TypeError):
            model.simulate('parameters', times)

        with self.assertRaises(ValueError):
            model.simulate([0], times)

        with self.assertRaises(TypeError):
            parameters1 = [
                initial_r, 0.5, susceptibles, [[0, 0], [0, 0]], [[0, 0],
                                                                 [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=(str, float))),
                           times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 0, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 3, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            susceptibles1 = [5, 6]

            parameters1 = [
                initial_r, 1, susceptibles1, [[0, 0], [0, 0]], [[0, 0], [0,
                                                                         0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]],
                [[0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0, 0], [0, 0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[[1] * 2, [1] * 2], [[1] * 2, [1] * 2]], 4, dI, 0.005,
                'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2, [1] * 2], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 4, [1] * 4], 4, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(TypeError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], '4', dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], -1, dI, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(TypeError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, '4', 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, 0, 0.005, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(TypeError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, '0.005', 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0, 'my-solver'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(TypeError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.5, 3
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)

        with self.assertRaises(ValueError):
            parameters1 = [
                initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
                [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver2'
            ]

            model.simulate(list(deepflatten(parameters1, ignore=str)), times)
Ejemplo n.º 15
0
    def test_check_positives_format(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0.1, 0.2], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver'
        ]

        times = [1, 2]

        output = model.simulate(list(deepflatten(parameters, ignore=str)),
                                times)

        tests = [[20, 30], [10, 0]]
        sens = 0.9
        spec = 0.1

        with self.assertRaises(ValueError):
            output1 = np.array([5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

            model.check_positives_format(output1, tests, sens, spec)

        with self.assertRaises(ValueError):
            output1 = np.array([[5, 6, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0]])

            model.check_positives_format(output1, tests, sens, spec)

        with self.assertRaises(ValueError):
            output1 = np.array([[5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])

            model.check_positives_format(output1, tests, sens, spec)

        with self.assertRaises(TypeError):
            output1 = np.array([['5', 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                [5, 6, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])

            model.check_positives_format(output1, tests, sens, spec)

        with self.assertRaises(ValueError):
            tests1 = 100

            model.check_positives_format(output, tests1, sens, spec)

        with self.assertRaises(ValueError):
            tests1 = np.array([2, 50])

            model.check_positives_format(output, tests1, sens, spec)

        with self.assertRaises(ValueError):
            tests1 = np.array([[20, 30, 1], [10, 0, 0]])

            model.check_positives_format(output, tests1, sens, spec)

        with self.assertRaises(TypeError):
            tests1 = np.array([[20, '30'], [10, 0]])

            model.check_positives_format(output, tests1, sens, spec)

        with self.assertRaises(ValueError):
            tests1 = np.array([[-1, 50], [10, 0]])

            model.check_positives_format(output, tests1, sens, spec)

        with self.assertRaises(TypeError):
            model.check_positives_format(output, tests, '0.9', spec)

        with self.assertRaises(ValueError):
            model.check_positives_format(output, tests, -0.2, spec)

        with self.assertRaises(ValueError):
            model.check_positives_format(output, tests, 1.2, spec)

        with self.assertRaises(TypeError):
            model.check_positives_format(output, tests, sens, '0.1')

        with self.assertRaises(ValueError):
            model.check_positives_format(output, tests, sens, -0.1)

        with self.assertRaises(ValueError):
            model.check_positives_format(output, tests, sens, 1.2)
Ejemplo n.º 16
0
    def test_samples_positive_tests(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0.1, 0.2], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver'
        ]

        times = [1, 2]

        output = model.simulate(list(deepflatten(parameters, ignore=str)),
                                times)

        tests = [[20, 30], [10, 0]]
        sens = 0.9
        spec = 0.1

        self.assertEqual(
            model.samples_positive_tests(output, tests[0], sens, spec,
                                         0).shape, (len(age_groups), ))

        with self.assertRaises(TypeError):
            model.samples_positive_tests(output, tests[0], sens, spec, '1')

        with self.assertRaises(ValueError):
            model.samples_positive_tests(output, tests[0], sens, spec, -1)

        with self.assertRaises(ValueError):
            model.samples_positive_tests(output, tests[0], sens, spec, 3)
Ejemplo n.º 17
0
    def test_check_death_format(self):
        model = em.PheSEIRModel()

        # Populate the model
        regions = ['London', 'Cornwall']
        age_groups = ['0-10', '10-25']

        # Initial state of the system
        contact_data_matrix_0 = np.array([[1, 0], [0, 3]])
        contact_data_matrix_1 = np.array([[10, 5.2], [0, 3]])

        region_data_matrix_0_0 = np.array([[0.5, 0], [0, 6]])
        region_data_matrix_0_1 = np.array([[1, 10], [1, 0]])
        region_data_matrix_1_0 = np.array([[0.5, 1.2], [0.29, 6]])
        region_data_matrix_1_1 = np.array([[0.85, 1], [0.9, 6]])

        susceptibles = [[5, 6], [7, 8]]
        dI = 4

        contacts_0 = em.ContactMatrix(age_groups, contact_data_matrix_0)
        contacts_1 = em.ContactMatrix(age_groups, contact_data_matrix_1)
        regional_0_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_0_0)
        regional_0_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_0_1)
        regional_1_0 = em.RegionMatrix(regions[0], age_groups,
                                       region_data_matrix_1_0)
        regional_1_1 = em.RegionMatrix(regions[1], age_groups,
                                       region_data_matrix_1_1)

        # Matrices contact
        matrices_contact = [contacts_0, contacts_1]
        time_changes_contact = [1, 3]
        matrices_region = [[regional_0_0, regional_0_1],
                           [regional_1_0, regional_1_1]]
        time_changes_region = [1, 2]

        model.set_regions(regions)
        model.read_contact_data(matrices_contact, time_changes_contact)
        model.read_regional_data(matrices_region, time_changes_region)

        initial_r = [0.5, 1]

        parameters = [
            initial_r, 1, susceptibles, [[0, 0], [0, 0]], [[0.1, 0.2], [0, 0]],
            [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]],
            [[1] * 2, [1] * 2], 4, dI, 0.5, 'my-solver'
        ]

        times = [1, 2]

        output = model.simulate(list(deepflatten(parameters, ignore=str)),
                                times)

        new_infections = model.new_infections(output)

        fatality_ratio = [0.1, 0.5]
        time_to_death = [0.5, 0.5]

        with self.assertRaises(TypeError):
            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death, '0.5')

        with self.assertRaises(ValueError):
            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death, -2)

        with self.assertRaises(ValueError):
            new_infections1 = \
                np.array([5, 6])

            model.check_death_format(new_infections1, fatality_ratio,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            new_infections1 = np.array([[5, 6, 0, 0], [5, 6, 0, 0]])

            model.check_death_format(new_infections1, fatality_ratio,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            new_infections1 = np.array([[5, 6], [5, 6], [5, 6]])

            model.check_death_format(new_infections1, fatality_ratio,
                                     time_to_death, 0.5)

        with self.assertRaises(TypeError):
            new_infections1 = np.array([['5', 6], [5, '0']])

            model.check_death_format(new_infections1, fatality_ratio,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            fatality_ratio1 = 0

            model.check_death_format(new_infections, fatality_ratio1,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            fatality_ratio1 = np.array([0.1, 0.5, 0.1])

            model.check_death_format(new_infections, fatality_ratio1,
                                     time_to_death, 0.5)

        with self.assertRaises(TypeError):
            fatality_ratio1 = np.array([0.1, '0.5'])

            model.check_death_format(new_infections, fatality_ratio1,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            fatality_ratio1 = np.array([-0.1, 0.5])

            model.check_death_format(new_infections, fatality_ratio1,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            fatality_ratio1 = np.array([0.1, 1.5])

            model.check_death_format(new_infections, fatality_ratio1,
                                     time_to_death, 0.5)

        with self.assertRaises(ValueError):
            time_to_death1 = np.array([[0.5], [0.5]])

            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death1, 0.5)

        with self.assertRaises(ValueError):
            time_to_death1 = np.array([0.5, 0.5, 0.15])

            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death1, 0.5)

        with self.assertRaises(TypeError):
            time_to_death1 = np.array(['0.1', 0.5])

            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death1, 0.5)

        with self.assertRaises(ValueError):
            time_to_death1 = np.array([-0.1, 0.5])

            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death1, 0.5)

        with self.assertRaises(ValueError):
            time_to_death1 = np.array([0.5, 1.1])

            model.check_death_format(new_infections, fatality_ratio,
                                     time_to_death1, 0.5)