Skip to content

Neutral macroecology

Many species under neutral birth, death, and immigration.

  • Class: NeutralMacroecologySystem
  • Import: from skcomplex.systems.biology.ecology import NeutralMacroecologySystem
  • Field: biology/ecology
  • Topics: macroecology, neutral theory, jump process, species abundance
  • References:
    • Hubbell 2001
    • Volkov et al. 2003
    • Gros 2015

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.biology.ecology import NeutralMacroecologySystem

trajectory = NeutralMacroecologySystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
species 100
n 10.0
b0 1.0
b1 0.9
d0 0.0
d1 1.0
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space none
Laws jump
Randomness stochastic
Domains integer
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class NeutralMacroecologySystem(BaseSystem):
    """Many species under neutral birth, death, and immigration.

    Their abundances follow a gamma-like law.

    Without emigration, `d0 = 0`, the abundances settle on the negative binomial distribution of mean `b0 / (d1 - b1)`,
    the discrete form of the gamma distribution that the Fokker-Planck equation of macroecology predicts and that fits
    the abundances of tropical trees. The system has the abundances `species.x`.

    Args:
        species:
            The number of species.

        n:
            The initial number of individuals of every species.

        b0:
            The rate of immigration or speciation.

        b1:
            The per capita birth rate.

        d0:
            The rate of emigration or extinction.

        d1:
            The per capita death rate, above `b1`.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.biology.ecology import NeutralMacroecologySystem
        >>> NeutralMacroecologySystem(20).prepare().system_.elements[0].size
        20
    """

    field = 'biology/ecology'
    topics = ('macroecology', 'neutral theory', 'jump process', 'species abundance')
    references = ('Hubbell 2001', 'Volkov et al. 2003', 'Gros 2015')
    until = 100.0
    dt = 1.0

    def __init__(
        self,
        species: int = 100,
        n: float = 10.0,
        *,
        b0: float = 1.0,
        b1: float = 0.9,
        d0: float = 0.0,
        d1: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.species = species
        self.n = n
        self.b0 = b0
        self.b1 = b1
        self.d0 = d0
        self.d1 = d1

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of many species under neutral birth.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        self.system_ = System(
            self.label,
            elements=[NeutralSpeciesElement('species', x=self.n, size=self.species)],
            interactions=[
                NeutralBirthInteraction('birth', target='species', b0=self.b0, b1=self.b1),
                NeutralDeathInteraction('death', target='species', d0=self.d0, d1=self.d1),
            ],
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • NeutralSpeciesElement, from Element

Interactions:

  • NeutralBirthInteraction, from Interaction
  • NeutralDeathInteraction, from Interaction
class NeutralSpeciesElement(Element):
    """Species of neutral theory, a compartment of `x` individuals.

    Args:
        label:
            The label of the species or of the group of species.

        x:
            The initial number of individuals.

        size:
            The number of species, or `None` for one.

        space:
            The space with one species per site, or `None` for none.

    Examples:
        >>> from skcomplex.systems.biology.ecology import NeutralSpeciesElement
        >>> NeutralSpeciesElement('trees', size=50).size
        50
    """

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[float | npt.ArrayLike, NN] = 10.0,
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, size=size, space=space)
        self.x = x

class NeutralBirthInteraction(Interaction):
    """Births of single individuals at the rate `b0 + b1 x`, shared by every species.

    The constant part `b0` is immigration or speciation, and `b1` the birth rate of an individual.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the species or of the group of species.

        b0:
            The rate of immigration or speciation.

        b1:
            The birth rate of an individual.

    Examples:
        >>> from skcomplex.systems.biology.common.populations import NeutralBirthInteraction
        >>> NeutralBirthInteraction('birth', target='trees').b1
        0.9
    """

    law_classes = (JumpLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        b0: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        b1: Annotated[float, RealSet.closed_open(0, oo)] = 0.9,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.b0 = b0
        self.b1 = b1

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the births of single individuals.

        Args:
            context:
                The namespace of the species, the time `t`, and the parameters.
        """
        super()._prepare(context)
        x = context.target.x
        self.laws_ = [JumpLaw(context.b0 + context.b1 * x, {x: 1})]

class NeutralDeathInteraction(Interaction):
    """Deaths of single individuals at the rate `d0 + d1 x`, shared by every species.

    The constant part `d0` is emigration or extinction while the species has members, and `d1` the death rate of an
    individual.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the species or of the group of species.

        d0:
            The rate of emigration or extinction while the species has members.

        d1:
            The death rate of an individual.

    Examples:
        >>> from skcomplex.systems.biology.common.populations import NeutralDeathInteraction
        >>> NeutralDeathInteraction('death', target='trees').d1
        1.0
    """

    law_classes = (JumpLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        d0: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
        d1: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.d0 = d0
        self.d1 = d1

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the deaths of single individuals.

        Args:
            context:
                The namespace of the species, the time `t`, and the parameters.
        """
        super()._prepare(context)
        x = context.target.x
        self.laws_ = [JumpLaw(where(x > 0, context.d0, 0) + context.d1 * x, {x: -1})]