diff --git a/Project.toml b/Project.toml index 5f1da41dc..194811487 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "EcologicalNetworks" uuid = "f03a62fe-f8ab-5b77-a061-bb599b765229" authors = ["Timothée Poisot "] repo = "https://github.com/EcoJulia/EcologicalNetworks.jl" -version = "0.5.0" +version = "0.5.1" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/community/spectralradius.jl b/src/community/spectralradius.jl index 9be2e1efe..2bc1baab8 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 54d855be1..3b3d4c140 100644 --- a/test/community/spectralradius.jl +++ b/test/community/spectralradius.jl @@ -20,4 +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.>0) +@test ρ(N, range=EcologicalNetworks.ρ_raw) ≈ 3.943904 atol = 0.01 +@test ρ(N, range=EcologicalNetworks.ρ_ska) ≈ 0.956537 atol = 0.01 + end