Exemplo n.º 1
0
def test_ordinals():
    graph = next(pg.load_datasets_graph(["graph5"]))
    for _ in supported_backends():
        test_result = pg.Ordinals(
            pg.Ordinals(pg.Ordinals(pg.PageRank(normalization='col')))).rank(
                graph,
                {"A": 1})  # three ordinal transformations are the same as one
        assert test_result["A"] == 1
Exemplo n.º 2
0
def test_correlation_compliance():
    graph = next(pg.load_datasets_graph(["graph5"]))
    # TODO: Make spearman and pearson correlation support tensorflow
    alg1 = pg.PageRank(alpha=0.5)
    alg2 = pg.PageRank(alpha=0.99)
    pearson_ordinals = pg.PearsonCorrelation(pg.Ordinals(alg1)(graph))(
        pg.Ordinals(alg2)(graph))
    spearman = pg.SpearmanCorrelation(alg1(graph))(alg2(graph))
    assert pearson_ordinals == spearman
Exemplo n.º 3
0
def test_venuerank():
    graph = next(pg.load_datasets_graph(["bigraph"]))
    for _ in supported_backends():
        venuerank = pg.PageRank(alpha=0.85,
                                max_iters=10000,
                                converge_to_eigenvectors=True,
                                tol=1.E-12)
        venuerank_result = venuerank.rank(graph)
        small_restart = pg.PageRank(alpha=0.99, max_iters=10000, tol=1.E-12)
        small_restart_result = small_restart.rank(graph)
        #assert venuerank.convergence.iteration < small_restart.convergence.iteration / 2
        corr = pg.SpearmanCorrelation(pg.Ordinals()(venuerank_result))(
            pg.Ordinals()(small_restart_result))
        assert corr > 0.99
Exemplo n.º 4
0
def test_explicit_citations():
    assert "unknown node ranking algorithm" == pg.NodeRanking().cite()
    assert "with parameters tuned \cite{krasanakis2021pygrank}" in pg.ParameterTuner(
        lambda params: pg.PageRank(params[0])).cite()
    assert "Postprocessor" in pg.Postprocessor().cite()
    assert pg.PageRank().cite() in pg.AlgorithmSelection().cite()
    assert "krasanakis2021pygrank" in pg.ParameterTuner().cite()
    assert "ortega2018graph" in pg.ParameterTuner().cite()
    assert pg.HeatKernel().cite() in pg.SeedOversampling(pg.HeatKernel()).cite()
    assert pg.AbsorbingWalks().cite() in pg.BoostedSeedOversampling(pg.AbsorbingWalks()).cite()
    assert "krasanakis2018venuerank" in pg.BiasedKernel(converge_to_eigenvectors=True).cite()
    assert "yu2021chebyshev" in pg.HeatKernel(coefficient_type="chebyshev").cite()
    assert "susnjara2015accelerated" in pg.HeatKernel(krylov_dims=5).cite()
    assert "krasanakis2021pygrank" in pg.GenericGraphFilter(optimization_dict=dict()).cite()
    assert "tautology" in pg.Tautology().cite()
    assert pg.PageRank().cite() == pg.Tautology(pg.PageRank()).cite()
    assert "mabs" in pg.MabsMaintain(pg.PageRank()).cite()
    assert "max normalization" in pg.Normalize(pg.PageRank()).cite()
    assert "[0,1] range" in pg.Normalize(pg.PageRank(), "range").cite()
    assert "ordinal" in pg.Ordinals(pg.PageRank()).cite()
    assert "exp" in pg.Transformer(pg.PageRank()).cite()
    assert "0.5" in pg.Threshold(pg.PageRank(), 0.5).cite()
    assert "andersen2007local" in pg.Sweep(pg.PageRank()).cite()
    assert pg.HeatKernel().cite() in pg.Sweep(pg.PageRank(), pg.HeatKernel()).cite()
    assert "LFPRO" in pg.AdHocFairness("O").cite()
    assert "LFPRO" in pg.AdHocFairness(pg.PageRank(), "LFPRO").cite()
    assert "multiplicative" in pg.AdHocFairness(pg.PageRank(), "B").cite()
    assert "multiplicative" in pg.AdHocFairness(pg.PageRank(), "mult").cite()
    assert "tsioutsiouliklis2020fairness" in pg.AdHocFairness().cite()
    assert "rahman2019fairwalk" in pg.FairWalk(pg.PageRank()).cite()
    assert "krasanakis2020prioredit" in pg.FairPersonalizer(pg.PageRank()).cite()
Exemplo n.º 5
0
def test_rank_order_convergence():
    graph = next(pg.load_datasets_graph(["graph9"]))
    algorithm1 = pg.Ordinals(pg.PageRank(0.85, tol=1.E-12, max_iters=1000))
    algorithm2 = pg.Ordinals(
        pg.PageRank(0.85, convergence=pg.RankOrderConvergenceManager(0.85)))
    algorithm3 = pg.Ordinals(
        pg.PageRank(0.85,
                    convergence=pg.RankOrderConvergenceManager(
                        0.85, 0.99, "fraction_of_walks")))
    for _ in supported_backends():
        ranks1 = algorithm1.rank(graph, {"A": 1})
        ranks2 = algorithm2.rank(graph, {"A": 1})
        ranks3 = algorithm3.rank(graph, {"A": 1})
        assert pg.SpearmanCorrelation(ranks1)(ranks2) > 0.95
        assert pg.SpearmanCorrelation(ranks1)(ranks3) > 0.95
        assert pg.SpearmanCorrelation(ranks3)(ranks2) > 0.95
        assert "17 iterations" in str(algorithm3.ranker.convergence)
        with pytest.raises(Exception):
            algorithm = pg.Ordinals(
                pg.PageRank(0.85,
                            convergence=pg.RankOrderConvergenceManager(
                                0.85, 0.99, "unknown")))
            algorithm.rank(graph, {"A": 1})
Exemplo n.º 6
0
def test_postprocessor_citations():
    assert pg.Tautology(pg.PageRank()).cite() == pg.PageRank().cite()
    assert pg.Normalize(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.Normalize(pg.PageRank(), "sum").cite() != pg.Normalize(pg.PageRank(), "range").cite()
    assert pg.Ordinals(pg.PageRank()).cite() != pg.Normalize(pg.PageRank(), "sum").cite()
    assert pg.Transformer(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.Threshold(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.Sweep(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.BoostedSeedOversampling(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.SeedOversampling(pg.PageRank()).cite() != pg.PageRank().cite()
    assert pg.SeedOversampling(pg.PageRank(), method="safe").cite() \
           != pg.SeedOversampling(pg.PageRank(), method="top").cite()
    assert pg.BoostedSeedOversampling(pg.PageRank(), objective="partial").cite() \
           != pg.BoostedSeedOversampling(pg.PageRank(), objective="naive").cite()
    assert pg.BoostedSeedOversampling(pg.PageRank(), oversample_from_iteration="previous").cite() \
           != pg.BoostedSeedOversampling(pg.PageRank(), oversample_from_iteration="original").cite()