Beispiel #1
0
def test_construct_bayes_net() -> None:
    uniform = UniformInt(0, 1)
    graph = set(uniform.get_connected_graph())
    vertex_ids = [vertex.get_id() for vertex in graph]

    assert len(vertex_ids) == 3
    assert uniform.get_id() in vertex_ids

    net = BayesNet(graph)
    latent_vertex_ids = [
        vertex.get_id() for vertex in net.get_latent_vertices()
    ]

    assert len(latent_vertex_ids) == 1
    assert uniform.get_id() in latent_vertex_ids
Beispiel #2
0
    def model(self) -> Model:
        start_year, end_year = (self._data.index.min(), self._data.index.max())

        with Model() as m:
            m.switchpoint = UniformInt(start_year, end_year + 1)

            m.early_rate = Exponential(1.0)
            m.late_rate = Exponential(1.0)

            m.years = np.array(self._data.index)
            m.rates = If(m.switchpoint > m.years, m.early_rate, m.late_rate)
            m.disasters = Poisson(m.rates)

        return m
Beispiel #3
0
    python_id = gaussian.get_id()

    assert all(value in python_id for value in java_id)


def test_ids_are_reset() -> None:
    gaussian = Gaussian(0., 1.)
    set_deterministic_state()
    gaussian2 = Gaussian(0., 1.)

    assert gaussian.get_id() == gaussian2.get_id()


@pytest.mark.parametrize("vertex, expected_type",
                         [(Gaussian(0., 1.), np.floating),
                          (UniformInt(0, 10), np.integer),
                          (Bernoulli(0.5), np.bool_)])
@pytest.mark.parametrize(
    "value, assert_vertex_value_equals",
    [(np.array([[4]]), assert_vertex_value_equals_ndarray),
     (np.array([[5.]]), assert_vertex_value_equals_ndarray),
     (np.array([[True]]), assert_vertex_value_equals_ndarray),
     (np.array([[1, 2], [3, 4]]), assert_vertex_value_equals_ndarray),
     (pd.Series(data=[4]), assert_vertex_value_equals_pandas),
     (pd.Series(data=[5.]), assert_vertex_value_equals_pandas),
     (pd.Series(data=[True]), assert_vertex_value_equals_pandas),
     (pd.Series(data=[1, 2, 3]), assert_vertex_value_equals_pandas),
     (pd.Series(data=[1., 2., 3.]), assert_vertex_value_equals_pandas),
     (pd.Series(data=[True, False, False]), assert_vertex_value_equals_pandas),
     (pd.DataFrame(data=[[4]]), assert_vertex_value_equals_pandas),
     (pd.DataFrame(data=[[5.]]), assert_vertex_value_equals_pandas),