This page presents the core functions to manipulate networks. Whenever possible, the approach of EcologicalNetworks is to overload functions from Base.
Accessing species
EcologicalNetworks.species — Functionspecies(N::AbstractBipartiteNetwork)Returns an array of all species in a bipartite network. The order of the species corresponds to the order of rows (top level) and columns (bottom level) of the adjacency matrix, in this order.
species(N::AbstractUnipartiteNetwork; dims::Int64=1)Returns an array of species on either side of a unipartite network. In a unipartite network, species are the same on either size. This function is nevertheless useful when you want to write code that takes either side of the network in a general way.
Accessing interactions
Presence of an interaction
EcologicalNetworks.has_interaction — Functionhas_interaction{(N::AbstractEcologicalNetwork, i::NT, j::NT)This function returns true if the interaction between i and j is not 0. This refers to species by their names/values, and is the recommended way to test for the presence of an interaction.
Use N[i,j] if you need to get the value of the interaction.
has_interaction(N::AbstractEcologicalNetwork, i::Int64, j::Int64)This function returns true if the interaction between i and j is not 0. This refers to species by their position instead of their name, and is not recommended as the main solution. This is used internally by a few functions, but is exported because it may be of general use.
EcologicalNetworks.interactions — Functioninteractions(N::AbstractEcologicalNetwork)Returns the interactions in the ecological network. Interactions are returned as an array of named tuples. A minima, these have fields from and to. For networks that are probabilistic, there is a probability field. For networks that are quantitative, there is a strength field. This functions allows to iterate over interactions in a network in a convenient way.
Random network samples
StatsBase.sample — Functionsample(N::T, n::Int64) where {T<:AbstractUnipartiteNetwork}Samples a sub-network from a unipartite network. n is the number of species to have in the sampled network. This functions makes no attempt to ensure that the network is not degenerate, or even has a single interaction. This is the recommended way to sample a unipartite network.
sample(N::T, n::Tuple{Int64}) where {T<:AbstractUnipartiteNetwork}Same as sample, but work when called with (n,) instead of a species number. This is an accepted way to sample a unipartite network.
sample(N::T, n::Tuple{Int64,Int64}) where {T<:AbstractUnipartiteNetwork}Same as sample but called with (n,n) instead of a species number. Note that this will fail if the size requested is not square. This is not a really good way to sample a unipartite network.
sample(N::T, n::Tuple{Int64}) where {T<:AbstractBipartiteNetwork}Same as sample but with a single species number given as (n,), to return a bipartite network of equal richness on both sides. This is not a very good way to sample a bipartite network.
sample(N::T, n::Int64) where {T<:AbstractBipartiteNetwork}Same thing as sample but with a single species number, to return a bipartite network of equal richness on both sides. This is not a very good way to sample a bipartite network.
sample(N::T, n::Tuple{Int64,Int64}) where {T<:AbstractBipartiteNetwork}Samples a sub-network from a bipartite network. n is the size of the network to return, i.e. number of top and bottom species. This functions makes no attempt to ensure that the network is not degenerate, or even has a single interaction.
This is the recommended way to sample a bipartite network.
Network utilities
Species richness
EcologicalNetworks.richness — Functionrichness(N::AbstractEcologicalNetwork, i::Int64)Returns the number of species on either side of the network. The value of i can be 1 (top-level species) or 2 (bottom-level species), as in the species function.
Changing network shape
Base.permutedims — Functionpermutedims(N::AbstractBipartiteNetwork)Tranposes the network and returns a copy
EcologicalNetworks.nodiagonal — Functionnodiagonal(N::AbstractUnipartiteNetwork)Returns a copy of the network with its diagonal set to zero.
nodiagonal(N::AbstractBipartiteNetwork)Returns a copy of the network (because the diagonal of a bipartite network is never a meaningful notion). This function is clearly useless, but allows to write general code for all networks types when a step requires removing the diagonal.
EcologicalNetworks.nodiagonal! — Functionnodiagonal!(N::AbstractUnipartiteNetwork)Modifies the network so that its diagonal is set to the appropriate zero.
nodiagonal!(N::AbstractBipartiteNetwork)Does nothing.
Invert interactions
Base.:! — FunctionBase.:!{T<:DeterministicNetwork}(N::T)Returns the inverse of a binary network – interactions that were false become true, and conversely.