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()
def test_tautology(): graph = next(pg.load_datasets_graph(["bigraph"])) r = pg.PageRank().rank(graph) tr = pg.Tautology(pg.PageRank()).rank(graph) rt = pg.Tautology().transform(r) for u in graph: assert r[u] == rt[u] assert r[u] == tr[u] u = pg.Tautology().rank(graph) assert float(sum(u.np)) == len(graph)
def test_stream(): graph = next(pg.load_datasets_graph(["graph9"])) for _ in supported_backends(): ranks1 = pg.Normalize( pg.PageRank(0.85, tol=pg.epsilon(), max_iters=1000, use_quotient=False)).rank(graph, {"A": 1}) ranks2 = pg.to_signal(graph, {"A": 1}) >> pg.PageRank( 0.85, tol=pg.epsilon(), max_iters=1000) + pg.Tautology() >> pg.Normalize() assert pg.Mabs(ranks1)(ranks2) < pg.epsilon()
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()
def __init__(self, ranker=None, weights=[0.5**i for i in range(3)], dims: int = 1024, sparsity: Optional[float] = None, beta: float = 1., normalization: str = "symmetric", assume_immutability: bool = True): super().__init__(pg.Tautology() if ranker is None else ranker) self.known_ranks = dict() self.embeddigns = dict() self.dims = dims self.weights = weights self.sparsity = sparsity self.beta = beta self.assume_immutability = assume_immutability self.normalization = normalization