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

Spectral radius bug fix #205

Merged
merged 2 commits into from
Feb 10, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "EcologicalNetworks"
uuid = "f03a62fe-f8ab-5b77-a061-bb599b765229"
authors = ["Timothée Poisot <[email protected]>"]
repo = "https://github.com/EcoJulia/EcologicalNetworks.jl"
version = "0.5.0"
version = "0.5.1"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
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
8 changes: 8 additions & 0 deletions test/community/spectralradius.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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