Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Closes #203
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Feb 10, 2022
1 parent 71bf5c5 commit bbbe479
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/community/spectralradius.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/community/spectralradius.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bbbe479

Please sign in to comment.