Skip to content

SIS on hypergraphs with heterogeneous exposure and a nonlinear infection kernel

The SIS contagion of St-Onge et al. in the environments of a hypergraph.

  • Class: HypergraphExposureSisSystem
  • Import: from skcomplex.systems.social.spreading import HypergraphExposureSisSystem
  • Field: social/spreading
  • Topics: contagion, hypergraph, exposure, bistability
  • References:
    • St-Onge et al. 2021
    • Majhi et al. 2022

Use this system

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

from skcomplex.systems.social.spreading import HypergraphExposureSisSystem

trajectory = HypergraphExposureSisSystem().prepare().simulate()

Parameters

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

Parameter Default
n_nodes 1000
sizes (10, 20, 30)
hyperdegree 5.0
rate 0.06
exponent 2.0
recovery 0.05
share 0.3
seed 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 hypergraph
Laws update
Randomness stochastic
Domains boolean
Structure fixed

Class

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

class HypergraphExposureSisSystem(BaseSystem):
    """The SIS contagion of St-Onge et al. in the environments of a hypergraph.

    Its kernel is nonlinear. Participants meet in environments, the hyperedges of a random hypergraph. In every step an
    environment gives a susceptible member the dose `rate * rho ** exponent` from the share `rho` of its other members
    that are infected, the member is infected with probability `1 - exp(-D)` of the sum `D` of its doses, and an
    infected participant recovers with probability `recovery`. Heterogeneous exposure times give the power law
    `rho ** exponent` to the infection kernel. With a sublinear or linear kernel the epidemic sets in continuously, and
    with a supralinear kernel, `exponent > 1`, the healthy state stays stable: an endemic state coexists with it above a
    critical rate, so a small seed dies out and a large one persists. In mean field the prevalence `I` is endemic where
    `k rate I ** (exponent - 1) (1 - I) = recovery` for `k` environments per participant.

    The system has the states `participants.infected` and the prevalence `prevalence`.

    Args:
        n_nodes:
            The number of participants.

        sizes:
            The sizes of the environments.

        hyperdegree:
            The mean number of environments of a participant, split evenly over the sizes, whose members are drawn at
            random.

        rate:
            The dose of an environment whose other members are all infected.

        exponent:
            The exponent of the infection kernel.

        recovery:
            The probability of recovery in a step.

        share:
            The share of infected participants at the start.

        seed:
            The seed of the hypergraph and the infected participants.

        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.social.spreading import HypergraphExposureSisSystem
        >>> len(HypergraphExposureSisSystem(40).prepare().system_.elements[0].infected)
        40
    """

    field = 'social/spreading'
    topics = ('contagion', 'hypergraph', 'exposure', 'bistability')
    references = ('St-Onge et al. 2021', 'Majhi et al. 2022')
    until = 200
    dt = 1
    observables = (Observable('prevalence', group='participants', variable='infected'),)

    def __init__(
        self,
        n_nodes: int = 1000,
        *,
        sizes: Sequence[int] = (10, 20, 30),
        hyperdegree: float = 5.0,
        rate: float = 0.06,
        exponent: float = 2.0,
        recovery: float = 0.05,
        share: float = 0.3,
        seed: int = 0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_nodes = n_nodes
        self.sizes = sizes
        self.hyperdegree = hyperdegree
        self.rate = rate
        self.exponent = exponent
        self.recovery = recovery
        self.share = share
        self.seed = seed

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components built from the model parameters."""
        super()._prepare(context)
        rng = np.random.default_rng(self.seed)
        hypergraph = xgi.Hypergraph()
        hypergraph.add_nodes_from(range(self.n_nodes))
        for size in self.sizes:
            number = round(self.n_nodes * self.hyperdegree / (len(self.sizes) * size))
            hypergraph.add_edges_from(rng.choice(self.n_nodes, size, replace=False).tolist() for _ in range(number))
        infected = (rng.permutation(self.n_nodes) < round(self.share * self.n_nodes)).astype(float)
        participants = ParticipantElement(
            'participants',
            infected=infected,
            recovery=self.recovery,
            space=NetworkSpace(xgi.to_graph(hypergraph), hyperedges=hypergraph),
        )
        exposure = ExposureInteraction('exposure', target='participants', rate=self.rate, exponent=self.exponent)
        self.system_ = System(self.label, elements=[participants], interactions=[exposure])

Components

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

Elements:

Interactions:

  • ExposureInteraction, from Interaction
class ParticipantElement(Element):
    """Participant in the environments of a contagion.

    It is susceptible at 0 and infected at 1. The infection and the recovery are an `ExposureInteraction` of the
    hypergraph, which `HypergraphExposureSisSystem` adds.

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

        infected:
            The initial state, 0 or 1, one per participant or shared.

        recovery:
            The probability that an infected participant recovers in a step.

        space:
            The network with one participant per node, or `None` for one participant.

    Examples:
        >>> from skcomplex.systems.social.spreading import ParticipantElement
        >>> ParticipantElement('participant').recovery
        0.05
    """

    visual = VisualSpec('sites', {'states': ['infected'], 'low': 0.0, 'high': 1.0})

    def __init__(
        self,
        label: str,
        *,
        infected: Annotated[object, FiniteEnumeratedSet([0, 1])] = 0.0,
        recovery: Annotated[float, RealSet.closed(0, 1)] = 0.05,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.infected = infected
        self.recovery = recovery

class ExposureInteraction(Interaction):
    """Infection of participants by the doses of their environments, and recovery.

    The infected participants are susceptible, and the time is discrete. An environment, a hyperedge, gives each
    susceptible member the dose `rate * rho ** exponent`, where `rho` is the share of the other members that are
    infected, and the doses of the environments of a participant add up to `D`. In every step a susceptible participant
    is infected with probability `1 - exp(-D)`, and an infected one recovers with probability `recovery`, a parameter of
    the participants.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the participants on the network.

        rate:
            The dose of an environment whose other members are all infected.

        exponent:
            The exponent of the infection kernel, sublinear below 1 and supralinear above.

    Examples:
        >>> from skcomplex.systems.social.spreading import ExposureInteraction
        >>> ExposureInteraction('exposure', target='participants', exponent=1.5).exponent
        1.5
    """

    law_classes = (UpdateLaw,)
    draws = True

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        rate: Annotated[float, RealSet.closed_open(0, oo)] = 0.06,
        exponent: Annotated[float, RealSet.open(0, oo)] = 2.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.rate = rate
        self.exponent = exponent

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the next state of every participant, from the sum of the doses of its environments, as the law.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        member = context.target
        others = total(member.members.infected, over=member.members) - member.infected
        share = others / (count(over=member.members) - 1)
        dose = hyperedges(context.rate * share**context.exponent)
        draw = uniform('exposure')
        infection = where(draw < 1 - exp(-dose), 1, 0)
        self.laws_: list[BaseLaw] = [
            UpdateLaw(member.infected, where(member.infected == 1, where(draw < member.recovery, 0, 1), infection)),
        ]