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

Commit

Permalink
✏️ typo function + general s
Browse files Browse the repository at this point in the history
  • Loading branch information
MichielStock committed May 12, 2019
1 parent dde23a5 commit 4a121ee
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/src/properties/resilience.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ with

- $$\langle s \rangle$$ the average weighted degree (computed using `s_mean`),
- $$\mathcal{S}$$ the symmetry(computed using `symmetry`),
- $$\mathcal{H}$$ the heterogenity (computed using `heterogenity`).
- $$\mathcal{H}$$ the heterogeneity (computed using `heterogeneity`).


> Goa, J., Barzael, B. and Barabási 2016. Universal resilience patterns in complex networks.
Expand All @@ -46,7 +46,7 @@ s_mean
σ_in
σ_out
symmetry
heterogenity
heterogeneity
βeff
resilience
```
4 changes: 2 additions & 2 deletions src/EcologicalNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export AJS, EAJS
# Overlap
include(joinpath(".", "community/resilience.jl"))
export βeff, resilience
export symmetry, heterogenity
export s_in, s_out, s_mean
export symmetry, heterogeneity
export s
export σ_in, σ_out

# Modularity
Expand Down
34 changes: 22 additions & 12 deletions src/community/resilience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ Some functions from *Universal resilience patterns in complex networks*
by Gao et al. (2016)
=#

using StatsBase: mean, std
using Statistics: mean, std

"""
s_in(N::AbstractUnipartiteNetwork)
s(N::AbstractUnipartiteNetwork; dims::Union{Nothing,Integer}=nothing)
Computes the average weighted degree. This is proportional to the (weighted)
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)'
if dims == nothing
return sum(N) / size(N)[1]
end
end
#=
"""
s(N::AbstractUnipartiteNetwork; dims)
Computes the vector of incoming weighted degrees of an unipartite network.
"""
Expand All @@ -19,13 +35,7 @@ Computes the vector of outgoing weighted degrees of an unipartite network.
"""
s_out(N::AbstractUnipartiteNetwork) = sum(N.A, dims=1)'
"""
s_mean(N::AbstractUnipartiteNetwork)
Computes the average weighted degree. This is proportional to the (weighted)
density of interactions.
"""
s_mean(N::AbstractUnipartiteNetwork) = sum(N.A) / size(N.A, 1)
=#

"""
σ_in(N::AbstractUnipartiteNetwork)
Expand Down Expand Up @@ -61,9 +71,9 @@ to be prey would have a negative symmetry.
symmetry(N::AbstractUnipartiteNetwork) = (mean(s_in(N) .* s_out(N)) - mean(s_in(N)) * mean(s_out(N))) / (σ_in(N) * σ_out(N))

"""
heterogenity(N::AbstractUnipartiteNetwork)
heterogeneity(N::AbstractUnipartiteNetwork)
Computes the heterogenity for an unipartite network, a topological characteristic
Computes the heterogeneity for an unipartite network, a topological characteristic
which quantifies the difference in in- and outgoing degrees between species. It
is computed as σ_in * σ_out / s_mean. A value of 0 indicates that all species
have the same (weighted) in- and outdegrees.
Expand All @@ -72,7 +82,7 @@ have the same (weighted) in- and outdegrees.
> Nature 530(7590), 307-312. doi:10.1038/nature16948
"""
heterogenity(N::AbstractUnipartiteNetwork) = (σ_in(N) * σ_out(N)) / s_mean(N)
heterogeneity(N::AbstractUnipartiteNetwork) = (σ_in(N) * σ_out(N)) / s_mean(N)

"""
βeff(N::AbstractUnipartiteNetwork)
Expand Down
10 changes: 5 additions & 5 deletions test/community/resilience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module TestResilience
@assert s_in(N) sum(A, dims=2)
@assert s_out(N) sum(A, dims=1)'

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

# species only interact with themselves
Nid = UnipartiteNetwork([true false false false;
false true false false;
false false true false;
false false false true])

@assert heterogenity(Nid) 0.0
@assert heterogeneity(Nid) 0.0
# @assert symmetry(Nid) NAN

# symetric network
Expand All @@ -25,7 +25,7 @@ module TestResilience
true false false false;
true false false false])
@assert symmetry(Nsym) 1.0 # in- and out degree is same
@assert heterogenity(Nsym) 0.5
@assert heterogeneity(Nsym) 0.5


# asymetric network
Expand All @@ -34,9 +34,9 @@ module TestResilience
false false false false;
false false false false])
@assert symmetry(Nasym) -1.0 # in- and out degree is same
@assert heterogenity(Nasym) 0.75
@assert heterogeneity(Nasym) 0.75

v = ones(10) / 10
Nhomo = UnipartiteProbabilisticNetwork(v * v')
@assert isapprox(heterogenity(Nhomo), 0.0, atol=1e-10)
@assert isapprox(heterogeneity(Nhomo), 0.0, atol=1e-10)
end

0 comments on commit 4a121ee

Please sign in to comment.