diff --git a/src/community/spectralradius.jl b/src/community/spectralradius.jl index 9be2e1ef..2bc1baab 100644 --- a/src/community/spectralradius.jl +++ b/src/community/spectralradius.jl @@ -14,7 +14,7 @@ end ρ_phillips(N::T, v::Float64) where {T <: UnipartiteNetwork} = v/((links(N)*(richness(N)-1))/richness(N))^0.5 -ρ_ska(N::T, v::Float64) where {T <: UnipartiteNetwork} = v/sqrt(links(N)) +ρ_ska(N::T, v::Float64) where {T <: UnipartiteNetwork} = v/sqrt((links(N)-sum(diag(adjacency(N))))/2.0) ρ_raw(N::T, v::Float64) where {T <: UnipartiteNetwork} = v """ @@ -45,7 +45,7 @@ and S the number of nodes) are: 1. `EcologicalNetworks.ρ_phillips`: divides by the square root of (2L(S-1))/S, as in Phillips (20110) 1. `EcologicalNetworks.ρ_ska`: divides by the square root of L, as in - Staniczenko *et al.* (2013) - this is the **default** + Staniczenko *et al.* (2013) - this is the **default**, and has an upper bound of the square root of the number of links 1. `EcologicalNetworks.ρ_raw`: returns the raw value #### References diff --git a/test/community/spectralradius.jl b/test/community/spectralradius.jl index 28d00842..3b3d4c14 100644 --- a/test/community/spectralradius.jl +++ b/test/community/spectralradius.jl @@ -20,9 +20,12 @@ A = [1 0 1 1; 1 1 0 1; 1 1 1 0; 1 1 1 0; 1 1 1 0; 0 1 0 1] N = BipartiteNetwork(A.>0) @test ρ(N; range=EcologicalNetworks.ρ_raw) ≈ 3.595 atol = 0.01 +# This specific example was added to catch a bug due to the wrong +# normalization, see issue #203 + A = [1 1 1 1; 1 1 1 0; 1 1 1 0; 1 1 1 0; 1 1 1 0; 1 0 0 0] -N = BipartiteNetwork(A) -@test ρ(N, range=ρ_raw) ≈ 3.943904 atol = 0.01 -@test ρ(N, range=ρ_ska) ≈ 0.956537 atol = 0.01 +N = BipartiteNetwork(A.>0) +@test ρ(N, range=EcologicalNetworks.ρ_raw) ≈ 3.943904 atol = 0.01 +@test ρ(N, range=EcologicalNetworks.ρ_ska) ≈ 0.956537 atol = 0.01 end