The type system
The package relies on a comprehensive system of types to represent networks. The purpose of the type system is to ensure that data are represented without ambiguities, but also to specialize the algorithm applied to each type of network.
The networks are represented as sparse matrices, for performance reasons. In practice, networks are standard Julia arrays, in that they can be accessed by position, sliced, have a size
and axes
, etc..
#
SpeciesInteractionNetworks.SpeciesInteractionNetwork
— Type.
SpeciesInteractionNetwork{P<:Partiteness, E<:Interactions}
A SpeciesInteractionNetwork
type represents a species interaction network.
This type has two fields: nodes
(a Partiteness
), and edges
(an Interactions
). Because these two types are parametric, we can learn everything there is to know about the data structure in a network by looking at the type alone.
For example, a bipartite quantitative network where species are symbols and interactions are 32-bits floating point numbers will have the type
SpeciesInteractionNetwork{Bipartite{Symbol}, Interactions{Float32}}
This enables very specialized dispatch and indexing thoughout the package.
Representing species
#
SpeciesInteractionNetworks.Partiteness
— Type.
Partiteness{T}
The species in a network are stored in a parametric sub-type of Partiteness
. By default, this can be Unipartite
or Bipartite
. The inner type T
indicates what types can be used to represent species. Note that species cannot be represented as integers, and will instead have a name. We recommend using strings or symbols.
#
SpeciesInteractionNetworks.Bipartite
— Type.
Bipartite{T <: Any} <: Partiteness{T}
A bipartite set of species is represented by two sets of species, called top
and bottom
. Both set of species are represented as Vector{T}
, with a few specific constraints:
T
cannot be aNumber
(i.e. nodes must have names, or be other objects)- All species in
top
must be unique - All species in
bottom
must be unique - No species can be found in both
bottom
andtop
#
SpeciesInteractionNetworks.Unipartite
— Type.
Unipartite{T <: Any} <: Partiteness{T}
A unipartite set of species is represented by a single set of species, called margin
internally. Both set of species are represented as Vector{T}
, with a few specific constraints:
T
cannot be aNumber
(i.e. nodes must have names, or be other objects)- All species in
margin
must be unique
Representing interactions
#
SpeciesInteractionNetworks.Interactions
— Type.
Interactions{T}
The interactions in a network are stored in a parametric sub-type of Interactions
. By default, this can be Binary
, Quantitative
, and Probabilistic
. The inner type T
indicates what types are used to represent interactions.
#
SpeciesInteractionNetworks.Binary
— Type.
Binary{Bool} <: Interactions{Bool}
Binary interactions are represented (internally) as a sparse matrix of Boolean values.
#
SpeciesInteractionNetworks.Quantitative
— Type.
Quantitative{T <: Number} <: Interactions{T}
Quantitative interactions are represented (internally) as a sparse matrix of numbers.
#
SpeciesInteractionNetworks.Probabilistic
— Type.
Probabilistic{T <: AbstractFloat} <: Interactions{T}
Probabilistic interactions are represented (internally) as a sparse matrix of floating point values. The values must be in the unit interval for the type to be valid.
Type conversion
#
SpeciesInteractionNetworks.render
— Function.
render(::Type{Unipartite}, N::SpeciesInteractionNetwork{<:Bipartite, <:Interactions})
Returns the unipartite projection of a bipartite network. By constructions, species cannot be shared between levels of bipartite network, so this operation will always succeed.
render(::Type{Bipartite}, N::SpeciesInteractionNetwork{<:Unipartite, <:Interactions})
Returns the bipartite projection of a unipartite network. By constructions, species cannot be shared between levels of bipartite network, so this operation may not always succeed. If it fails, it will throw a BipartiteProjectionFailed
exception.
render(::Type{Quantitative{T}}, N::SpeciesInteractionNetwork{<:Partiteness, <:Interactions}) where {T <: Number}
Returns a quantitative version of the network, where interaction strengths have the type T
. This can be used to convert a quantitative network into a different number representation.
render(::Type{Probabilistic{T}}, N::SpeciesInteractionNetwork{<:Partiteness, <:Interactions}) where {T <: AbstractFloat}
Returns a probabilistic version of the network, where interaction probabilities have the type T
. This can be used to convert a probabilistic network into a different number representation.
render(::Type{Binary}, N::SpeciesInteractionNetwork{<:Partiteness, <:Interactions})
Returns a binary version of the network, where the non-zero interactions are true
.