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

Commit

Permalink
Merge pull request #205 from EcoJulia/hotfix-spectral
Browse files Browse the repository at this point in the history
Spectral radius bug fix
  • Loading branch information
tpoisot authored Feb 10, 2022
2 parents 43e5f3c + bbbe479 commit 178bb76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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

2 comments on commit 178bb76

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/54397

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" 178bb766c9fedaa500330512b15268a191ed9017
git push origin v0.5.1

Please sign in to comment.