示例#1
0
def test_DAG_from_amat():
    unconnected_amat = np.zeros((4, 4))
    unconnected_graph = DAG.from_amat(unconnected_amat, list("ABCD"))
    unconnected_graph_list = DAG.from_amat(unconnected_amat.tolist(),
                                           list("ABCD"))
    fully_connected_amat = np.tril(np.ones((4, 4)), -1)
    fully_connected_graph = DAG.from_amat(fully_connected_amat, list("ABCD"))

    assert DAG.from_amat(unconnected_amat).nodes == {"A", "B", "C", "D"}

    assert np.all(unconnected_graph.get_numpy_adjacency() == unconnected_amat)
    assert np.all(
        unconnected_graph_list.get_numpy_adjacency() == unconnected_amat)
    assert np.all(
        fully_connected_graph.get_numpy_adjacency() == fully_connected_amat)

    assert fully_connected_graph.nodes == unconnected_graph.nodes == {
        "A", "B", "C", "D"
    }
    assert unconnected_graph.edges == set()
    assert (fully_connected_graph.edges == fully_connected_graph.directed_edges
            == {
                ('C', 'A'),
                ('B', 'A'),
                ('D', 'B'),
                ('D', 'C'),
                ('D', 'A'),
                ('C', 'B'),
            })
示例#2
0
def empty_dag() -> DAG:
    return DAG.from_amat(np.zeros((4, 4)), list("ABCD"))