Skip to content

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.SpeciesInteractionNetworkType.

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.

source

Representing species

# SpeciesInteractionNetworks.PartitenessType.

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.

source

# SpeciesInteractionNetworks.BipartiteType.

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:

  1. T cannot be a Number (i.e. nodes must have names, or be other objects)
  2. All species in top must be unique
  3. All species in bottom must be unique
  4. No species can be found in both bottom and top

source

# SpeciesInteractionNetworks.UnipartiteType.

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:

  1. T cannot be a Number (i.e. nodes must have names, or be other objects)
  2. All species in margin must be unique

source

Representing interactions

# SpeciesInteractionNetworks.InteractionsType.

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.

source

# SpeciesInteractionNetworks.BinaryType.

Binary{Bool} <: Interactions{Bool}

Binary interactions are represented (internally) as a sparse matrix of Boolean values.

source

# SpeciesInteractionNetworks.QuantitativeType.

Quantitative{T <: Number} <: Interactions{T}

Quantitative interactions are represented (internally) as a sparse matrix of numbers.

source

# SpeciesInteractionNetworks.ProbabilisticType.

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.

source

Type conversion

# SpeciesInteractionNetworks.renderFunction.

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.

source

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.

source

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.

source

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.

source

render(::Type{Binary}, N::SpeciesInteractionNetwork{<:Partiteness, <:Interactions})

Returns a binary version of the network, where the non-zero interactions are true.

source