Skip to content

Commit c508a11

Browse files
authored
Fix pagerank transpose bug and tests (#44)
1 parent 289d729 commit c508a11

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/overrides.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ Apply the page rank algorithm on a weighted graph.
5555
"""
5656
function Graphs.pagerank(g::SimpleWeightedDiGraph, α=0.85, n::Integer=100, ϵ=1.0e-6)
5757
A = weights(g)
58-
S = vec(sum(A; dims=1))
59-
S = 1 ./ S
58+
S = 1 ./ vec(sum(A; dims=2)) # inverse of outdegree
6059
S[findall(S .== Inf)] .= 0.0
61-
M = A' # need a separate line due to bug #17456 in julia
6260
# scaling the adjmat to stochastic adjacency matrix
63-
M = (Diagonal(S) * M)'
61+
M = (Diagonal(S) * A)'
6462
N = Int(nv(g))
6563
# solution vector
6664
x = fill(1.0 / N, N)

test/overrides.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
@test adjacency_matrix(g; dir=:out) == adjacency_matrix(g; dir=:in)'
7777
@test !issymmetric(laplacian_matrix(g; dir=:out))
7878
@test laplacian_matrix(g, Float64; dir=:out) g5_l
79-
@test @inferred(pagerank(g))[3] 0.2266 atol = 0.001
79+
@test @inferred(pagerank(g)) [0.119, 0.186, 0.311, 0.383] atol = 0.001 # checked with networkx
8080
@test length(@inferred(pagerank(g))) == nv(g)
8181
@test_throws ErrorException pagerank(g, 2)
8282
@test_throws ErrorException pagerank(g, 0.85, 2)
@@ -85,4 +85,11 @@
8585
@test g[2:3] == SimpleWeightedDiGraph{eltype(g5),weighttype(g5)}(gc)
8686
@test weights(g[2:3])[1, 2] == 2
8787
end
88+
89+
let
90+
A = [0 1 1; 1 0 0; 0 1 0]
91+
g = SimpleDiGraph(A)
92+
gw = SimpleWeightedDiGraph(A)
93+
@test pagerank(g) pagerank(gw)
94+
end
8895
end

0 commit comments

Comments
 (0)