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

Commit

Permalink
🔧 dependency to Statistics + update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichielStock committed May 12, 2019
1 parent 4a121ee commit f7cf182
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Missings]]
deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"]
git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042"
deps = ["SparseArrays", "Test"]
git-tree-sha1 = "f0719736664b4358aa9ec173077d4285775f8007"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "0.4.0"
version = "0.4.1"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
5 changes: 1 addition & 4 deletions docs/src/properties/resilience.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ with
## Available functions

```@docs
s_in
s_out
s_mean
s
σ_in
σ_out
symmetry
heterogeneity
βeff
resilience
```
2 changes: 1 addition & 1 deletion src/EcologicalNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export AJS, EAJS

# Overlap
include(joinpath(".", "community/resilience.jl"))
export βeff, resilience
export resilience
export symmetry, heterogeneity
export s
export σ_in, σ_out
Expand Down
34 changes: 8 additions & 26 deletions src/community/resilience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ density of interactions.
If dims is provided, the incoming (`dims=1`) or outgoing (`dims=2`) is computed.
"""
function s(N::AbstractUnipartiteNetwork; dims::Union{Nothing,Integer}=nothing)
dims == 1 && return sum(N, dims=2)
dims == 2 && return sum(N, dims=1)'
dims == 1 && return sum(N.A, dims=2)
dims == 2 && return sum(N.A, dims=1)'
if dims == nothing
return sum(N) / size(N)[1]
return sum(N.A) / size(N)[1]
end
end
#=
Expand All @@ -43,15 +43,15 @@ s_out(N::AbstractUnipartiteNetwork) = sum(N.A, dims=1)'
Computes the standard deviation of the ingoing weighted degree of an unipartite
network.
"""
σ_in(N::AbstractUnipartiteNetwork) = std(s_in(N), corrected=false)
σ_in(N::AbstractUnipartiteNetwork) = std(s(N, dims=1), corrected=false)

"""
σ_out(N::AbstractUnipartiteNetwork)
Computes the standard deviation of the outgoing weighted degree of an unipartite
network.
"""
σ_out(N::AbstractUnipartiteNetwork) = std(s_out(N), corrected=false)
σ_out(N::AbstractUnipartiteNetwork) = std(s(N, dims=2), corrected=false)

"""
symmetry(N::AbstractUnipartiteNetwork)
Expand All @@ -68,7 +68,7 @@ to be prey would have a negative symmetry.
> Nature 530(7590), 307-312. doi:10.1038/nature16948
"""
symmetry(N::AbstractUnipartiteNetwork) = (mean(s_in(N) .* s_out(N)) - mean(s_in(N)) * mean(s_out(N))) / (σ_in(N) * σ_out(N))
symmetry(N::AbstractUnipartiteNetwork) = (mean(s(N, dims=1) .* s(N, dims=2)) - mean(s(N, dims=1)) * mean(s(N, dims=2))) / (σ_in(N) * σ_out(N))

"""
heterogeneity(N::AbstractUnipartiteNetwork)
Expand All @@ -82,25 +82,7 @@ have the same (weighted) in- and outdegrees.
> Nature 530(7590), 307-312. doi:10.1038/nature16948
"""
heterogeneity(N::AbstractUnipartiteNetwork) = (σ_in(N) * σ_out(N)) / s_mean(N)

"""
βeff(N::AbstractUnipartiteNetwork)
A resilience parameters described by Gao et al. (2016). It is a global parameters
describing the dynamics of an unipartite network as an effective 1D equation of
the form
f(xeff) = F(xeff) + βeff G(xeff, xeff)
i.e. describing a second-order term representing the effect of the network on the
dynamics of the 'effective state' xeff of the system.
> Goa, J., Barzael, B. and Barabási 2016. Universal resilience patterns in complex networks.
> Nature 530(7590), 307-312. doi:10.1038/nature16948
"""
βeff(N::AbstractUnipartiteNetwork) = dot(s_in(N), s_out(N)) / sum(N.A)
heterogeneity(N::AbstractUnipartiteNetwork) = (σ_in(N) * σ_out(N)) / s(N)

"""
resilience(N::AbstractUnipartiteNetwork)
Expand All @@ -118,4 +100,4 @@ dynamics of the 'effective state' xeff of the system.
> Nature 530(7590), 307-312. doi:10.1038/nature16948
"""
resilience(N::AbstractUnipartiteNetwork) = βeff(N)
resilience(N::AbstractUnipartiteNetwork) = dot(s(N, dims=1), s(N, dims=2)) / sum(N)
8 changes: 4 additions & 4 deletions test/community/resilience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module TestResilience
A = rand([0, 1, 0.5], 10, 10)
N = UnipartiteQuantitativeNetwork(A)

@assert s_mean(N) sum(A) / 10
@assert s_in(N) sum(A, dims=2)
@assert s_out(N) sum(A, dims=1)'
@assert s(N) sum(A) / 10
@assert s(N, dims=1) sum(A, dims=2)
@assert s(N, dims=2) sum(A, dims=1)'

@assert βeff(N) s_mean(N) + symmetry(N) * heterogeneity(N)
@assert resilience(N) s(N) + symmetry(N) * heterogeneity(N)

# species only interact with themselves
Nid = UnipartiteNetwork([true false false false;
Expand Down

0 comments on commit f7cf182

Please sign in to comment.