Galton-Watson branching
A Galton-Watson branching process with Poisson offspring.
- Class:
GaltonWatsonSystem - Import:
from skcomplex.systems.mathematics.stochastic_processes import GaltonWatsonSystem - Field:
mathematics/stochastic_processes - Topics:
branching process,agents,extinction,criticality - References:
- Watson and Galton 1875
- Gros 2015
- Jensen 2023
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.mathematics.stochastic_processes import GaltonWatsonSystem
trajectory = GaltonWatsonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_individuals |
10 |
m |
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 | discrete |
| Space | none |
| Laws | update |
| Randomness | stochastic |
| Domains | integer |
| Structure | variable membership |
Class
The source of the class shows how it builds its components from its model parameters.
class GaltonWatsonSystem(BaseSystem):
"""A Galton-Watson branching process with Poisson offspring.
Every step is one generation.
The mean size of generation `n` is `n_individuals m^n`. The process dies out with certainty for `m <= 1`, and
survives with a positive probability for `m > 1`. The system has the group `population`, whose count is the size of
the current generation.
Args:
n_individuals:
The size of the first generation.
m:
The mean number of offspring of an individual.
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.mathematics.stochastic_processes import GaltonWatsonSystem
>>> GaltonWatsonSystem(5, m=1.2).prepare().system_.elements[0].size
5
"""
field = 'mathematics/stochastic_processes'
topics = ('branching process', 'agents', 'extinction', 'criticality')
references = ('Watson and Galton 1875', 'Gros 2015', 'Jensen 2023')
until = 20
def __init__(
self,
n_individuals: int = 10,
*,
m: float = 1.0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_individuals = n_individuals
self.m = m
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the first generation and its reproduction."""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[IndividualElement('population', size=self.n_individuals)],
interactions=[BranchingInteraction('reproduction', target='population', m=self.m)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
IndividualElement, fromElement
Interactions:
BranchingInteraction, fromInteraction
class IndividualElement(Element):
"""Individuals of a branching process, each with its generation `generation`.
Args:
label:
The label of the individuals.
generation:
The initial generation, one per individual or shared.
size:
The number of individuals, or `None` for one.
Examples:
>>> from skcomplex.systems.mathematics.stochastic_processes import IndividualElement
>>> IndividualElement('population', size=10).size
10
"""
visual = VisualSpec('agents', {'color_by': 'generation'})
def __init__(
self,
label: str,
*,
generation: Annotated[object, NN] = 0.0,
size: int | None = None,
) -> None:
super().__init__(label, size=size)
self.generation = generation
class BranchingInteraction(Interaction):
"""Replacement of every individual by a Poisson number of offspring of mean `m` at every step.
The offspring belong to the next generation and act from the next step on, so every step is one generation.
Args:
label:
The label of the interaction.
target:
The individuals that reproduce and die.
m:
The mean number of offspring of an individual.
Examples:
>>> from skcomplex.systems.mathematics.stochastic_processes import BranchingInteraction
>>> BranchingInteraction('reproduction', m=1.5).m
1.5
"""
law_classes = (UpdateLaw,)
draws = True
def __init__(self, label: str, *, target: Role = 'population', m: float = 1.0) -> None:
super().__init__(label)
self.target = target
self.m = m
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the reproduction of every individual as the rule.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
self.laws_: list[BaseLaw] = [UpdateLaw(context.target, self._replace)]
def _replace(self, agent: IndividualView, system: SystemView) -> None:
"""Create the offspring of an individual and remove it."""
for _ in range(int(system.rng.poisson(self.m))):
agent.create(generation=agent.generation + 1)
agent.remove()
Equations
The equations are those that symbolic returns for the system with its default parameters.