Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ Apply the page rank algorithm on a weighted graph.
"""
function Graphs.pagerank(g::SimpleWeightedDiGraph, α=0.85, n::Integer=100, ϵ=1.0e-6)
A = weights(g)
S = vec(sum(A; dims=1))
S = 1 ./ S
S = 1 ./ vec(sum(A; dims=2)) # inverse of outdegree
S[findall(S .== Inf)] .= 0.0
M = A' # need a separate line due to bug #17456 in julia
# scaling the adjmat to stochastic adjacency matrix
M = (Diagonal(S) * M)'
M = (Diagonal(S) * A)'
N = Int(nv(g))
# solution vector
x = fill(1.0 / N, N)
Expand Down
9 changes: 8 additions & 1 deletion test/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
@test adjacency_matrix(g; dir=:out) == adjacency_matrix(g; dir=:in)'
@test !issymmetric(laplacian_matrix(g; dir=:out))
@test laplacian_matrix(g, Float64; dir=:out) ≈ g5_l
@test @inferred(pagerank(g))[3]0.2266 atol = 0.001
@test @inferred(pagerank(g)) ≈ [0.119, 0.186, 0.311, 0.383] atol = 0.001 # checked with networkx
@test length(@inferred(pagerank(g))) == nv(g)
@test_throws ErrorException pagerank(g, 2)
@test_throws ErrorException pagerank(g, 0.85, 2)
Expand All @@ -85,4 +85,11 @@
@test g[2:3] == SimpleWeightedDiGraph{eltype(g5),weighttype(g5)}(gc)
@test weights(g[2:3])[1, 2] == 2
end

let
A = [0 1 1; 1 0 0; 0 1 0]
g = SimpleDiGraph(A)
gw = SimpleWeightedDiGraph(A)
@test pagerank(g) ≈ pagerank(gw)
end
end