-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44b66c4
commit 9922331
Showing
4 changed files
with
93 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Base.map(fcn, net::Network{ST,<:Global}) where {ST} | ||
Overload of the `map` method for `Global` networks. | ||
""" | ||
function Base.map(fcn, net::Network{ST,<:Global}) where {ST} | ||
Global(fcn(network(net))) | ||
end | ||
|
||
function Base.map(fcn, net::Network{ST,SC}) where {ST,SC} | ||
_sc = SC.name.wrapper | ||
_sc(Union{SpeciesInteractionNetwork,Nothing}[fcn(localnet) for localnet in network(net)]) | ||
end | ||
|
||
function Base.map(fcn, occ::Occurrence{T}) where {T} | ||
_sc = T <: Range ? Spatial : Temporal | ||
_sc(Union{SpeciesInteractionNetwork,Nothing}[fcn(x) for x in eachindex(occ)]) | ||
end | ||
|
||
function Base.map(fcn, ranges::Occurrence{<:Range}, phen::Occurrence{<:Phenology}) where {T} | ||
return Spatiotemporal(Union{SpeciesInteractionNetwork,Nothing}[fcn(x, t) for x in eachindex(ranges), t in eachindex(phen)]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
|
||
struct NeutrallyForbiddenLinks <: RealizationModel | ||
relative_abundance::Abundance{RelativeAbundance} | ||
energy | ||
end | ||
struct Equal <: RealizationModel end | ||
|
||
function _rate_matrix(localnet, relabd, energy) | ||
if !isnothing(localnet) | ||
rates = Quantitative(zeros(Float32, size(localnet))) | ||
rate_network = SpeciesInteractionNetwork(localnet.nodes, rates) | ||
ra_sum = 0.0 | ||
ints = interactions(localnet) | ||
for int in ints | ||
spᵢ, spⱼ, θᵢⱼ = int | ||
rᵢ, rⱼ = relabd[spᵢ], relabd[spⱼ] | ||
θᵢⱼ = rᵢ * rⱼ | ||
rate_network[spᵢ, spⱼ] = θᵢⱼ | ||
ra_sum += θᵢⱼ | ||
end | ||
return (energy .* rate_network) ./ ra_sum | ||
end | ||
end | ||
|
||
|
||
function realizable( | ||
net::Network{ST,SC}, | ||
rm::NeutrallyForbiddenLinks | ||
) where {ST<:Union{Feasible,Possible},SC} | ||
relabd = rm.relative_abundance | ||
|
||
function _rate_matrix(localnet) | ||
if !isnothing(localnet) | ||
rates = SpeciesInteractionNetworks.Quantitative(zeros(Float32, size(localnet))) | ||
rate_network = SpeciesInteractionNetworks.SpeciesInteractionNetwork(localnet.nodes, rates) | ||
ra_sum = 0.0 | ||
ints = SpeciesInteractionNetworks.interactions(localnet) | ||
for int in ints | ||
spᵢ, spⱼ, θᵢⱼ = int | ||
rᵢ, rⱼ = relabd[spᵢ], relabd[spⱼ] | ||
θᵢⱼ = rᵢ * rⱼ | ||
rate_network[spᵢ, spⱼ] = θᵢⱼ | ||
ra_sum += θᵢⱼ | ||
end | ||
return rate_network ./ ra_sum | ||
end | ||
end | ||
relabd, energy = rm.relative_abundance, rm.energy | ||
|
||
_sc = SC.name.wrapper | ||
localnets = scale(net).network | ||
Network{Realizable}(net.species, _sc(Union{SpeciesInteractionNetworks.SpeciesInteractionNetwork,Nothing}[_rate_matrix(localnet) for localnet in localnets])) | ||
_scale = map(x -> _rate_matrix(x, relabd, energy), net) | ||
Network{Realizable}( | ||
net.species, | ||
_scale, | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
|
||
function realize(net::Network{Realizable,SC}) where {SC} | ||
|
||
function _realize(localnet) | ||
if !isnothing(localnet) | ||
counts = SpeciesInteractionNetworks.Quantitative(zeros(Int, size(localnet))) | ||
realized_net = SpeciesInteractionNetworks.SpeciesInteractionNetwork(localnet.nodes, counts) | ||
for int in SpeciesInteractionNetworks.interactions(localnet) | ||
i, j, θ = int | ||
if θ > 0 | ||
realized_net[i, j] = rand(Poisson(θ)) | ||
end | ||
function _realize(localnet) | ||
if !isnothing(localnet) | ||
counts = Quantitative(zeros(Int, size(localnet))) | ||
realized_net = SpeciesInteractionNetwork(localnet.nodes, counts) | ||
for int in interactions(localnet) | ||
i, j, θ = int | ||
if θ > 0 | ||
realized_net[i, j] = rand(Poisson(θ)) | ||
end | ||
return realized_net | ||
end | ||
return realized_net | ||
end | ||
end | ||
|
||
|
||
_sc = SC.name.wrapper | ||
localnets = scale(net).network | ||
Network{Realized}(net.species, _sc(Union{SpeciesInteractionNetworks.SpeciesInteractionNetwork,Nothing}[_realize(localnet) for localnet in localnets])) | ||
function realize(net::Network{Realizable,SC}) where {SC} | ||
_scale = map(_realize, net) | ||
Network{Realized}( | ||
net.species, | ||
_scale, | ||
) | ||
end |