Exemplo n.º 1
0
def test_sequential():
    graph = next(pg.load_datasets_graph(["graph5"]))
    for _ in supported_backends():
        prior = pg.to_signal(graph, {"A": 2})
        posterior1 = pg.Normalize(pg.PageRank(), "range").rank(prior)
        posterior2 = pg.Normalize("range")(pg.PageRank()(prior))
        posterior3 = pg.Sequential(pg.PageRank(),
                                   pg.Normalize("range")).rank(prior)
        assert pg.sum(pg.abs(posterior1 - posterior2)) < pg.epsilon(
        )  # TODO: investigate when not exactly zero
        assert pg.sum(pg.abs(posterior1 - posterior3)) < pg.epsilon(
        )  # TODO: investigate when not exactly zero
Exemplo n.º 2
0
def test_norm_maintain():
    # TODO: investigate that 2.5*epsilon is truly something to be expected
    graph = next(pg.load_datasets_graph(["graph5"]))
    for _ in supported_backends():
        prior = pg.to_signal(graph, {"A": 2})
        posterior = pg.MabsMaintain(pg.Normalize(pg.PageRank(),
                                                 "range")).rank(prior)
        assert abs(pg.sum(pg.abs(posterior.np)) - 2) < 2.5 * pg.epsilon()
Exemplo n.º 3
0
def test_separate_and_combine():
    for _ in supported_backends():
        table = pg.to_primitive([[1, 2, 3], [4, 5, 6]])
        cols = pg.separate_cols(table)
        assert len(cols) == 3
        for col in cols:
            assert pg.length(col) == 2
        new_table = pg.combine_cols(cols)
        assert pg.sum(pg.abs(table - new_table)) == 0
Exemplo n.º 4
0
def test_preprocessor_types():
    def test_graph():
        return next(pg.load_datasets_graph(["graph5"]))
    for _ in supported_backends():
        from random import random
        graph = test_graph()
        signal = pg.to_signal(graph, {v: random() for v in graph})
        laplacian = pg.preprocessor(normalization="laplacian")(graph)
        symmetric = pg.preprocessor(normalization="symmetric")(graph)
        assert pg.abs(pg.sum(pg.conv(signal, laplacian) + pg.conv(signal, symmetric) - signal)) <= pg.epsilon()