Skip to content

Exploration and preferential return

The exploration and preferential return model of human mobility.

  • Class: ExplorationPreferentialReturnSystem
  • Import: from skcomplex.systems.social.organizations import ExplorationPreferentialReturnSystem
  • Field: social/organizations
  • Topics: agents, human mobility, exploration, preferential return
  • References:
    • Song, Koren, Wang, and Barabási 2010
    • Alessandretti, Aslak, and Lehmann 2020

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.organizations import ExplorationPreferentialReturnSystem

trajectory = ExplorationPreferentialReturnSystem().prepare().simulate()

Parameters

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

Parameter Default
n_individuals 10
rho 0.6
gamma 0.21
beta 1.55
least_jump 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, real
Structure variable membership

Class

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

class ExplorationPreferentialReturnSystem(BaseSystem):
    """The exploration and preferential return model of human mobility.

    The model is that of Song and coauthors. At every displacement an individual who has visited `S` distinct locations
    explores a new place with the probability `rho S^-gamma`, at a distance drawn from the power law `P(r) ~ r^-beta`,
    and otherwise returns to a visited location chosen in proportion to its number of visits (arXiv 2109.07381 Methods,
    the baseline of Fig. 2). The number of distinct locations grows as `n^(1 / (1 + gamma))` after `n` displacements,
    and the visits of the locations follow Zipf's law. The defaults `rho = 0.6` and `gamma = 0.21` are the values of
    Song and coauthors, and every individual starts at the origin.

    The system has the group `individuals`.

    Args:
        n_individuals:
            The number of individuals.

        rho:
            The factor `rho` of the probability of exploring.

        gamma:
            The exponent `gamma` of the decay of the probability of exploring.

        beta:
            The exponent `beta` of the power law of the jump lengths, above 1.

        least_jump:
            The least jump length.

        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.organizations import ExplorationPreferentialReturnSystem
        >>> ExplorationPreferentialReturnSystem(3).prepare().system_.elements[0].size
        3
    """

    field = 'social/organizations'
    topics = ('agents', 'human mobility', 'exploration', 'preferential return')
    references = ('Song, Koren, Wang, and Barabási 2010', 'Alessandretti, Aslak, and Lehmann 2020')
    until = 500

    def __init__(
        self,
        n_individuals: int = 10,
        *,
        rho: float = 0.6,
        gamma: float = 0.21,
        beta: float = 1.55,
        least_jump: 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.rho = rho
        self.gamma = gamma
        self.beta = beta
        self.least_jump = least_jump

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components built from the model parameters."""
        super()._prepare(context)
        individuals = ExplorerElement('individuals', size=self.n_individuals)
        displacement = ExplorationInteraction(
            'displacement',
            target='individuals',
            rho=self.rho,
            gamma=self.gamma,
            beta=self.beta,
            least_jump=self.least_jump,
        )
        self.system_ = System(self.label, elements=[individuals], interactions=[displacement])

Components

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

Elements:

Interactions:

  • ExplorationInteraction, from Interaction
class ExplorerElement(Element):
    """Individual of the mobility systems.

    It holds its position, its number of distinct locations, and its last level.

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

        x:
            The first coordinate of the current location.

        y:
            The second coordinate of the current location.

        distinct:
            The number of distinct locations visited.

        level:
            The level-distance of the last displacement in a hierarchy of containers, 0 without one.

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

    Examples:
        >>> from skcomplex.systems.social.organizations import ExplorerElement
        >>> ExplorerElement('individual').distinct
        1.0
    """

    def __init__(
        self,
        label: str,
        *,
        x: object = 0.0,
        y: object = 0.0,
        distinct: Annotated[object, NN] = 1.0,
        level: Annotated[object, NN] = 0.0,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.x = x
        self.y = y
        self.distinct = distinct
        self.level = level

class ExplorationInteraction(Interaction):
    """Exploration and preferential return of Song and coauthors.

    There is one displacement per individual and step. An individual who has visited `S` distinct locations explores a
    new one with the probability `rho S^-gamma`, at a distance drawn from the power law `P(r) ~ r^-beta` above
    `least_jump` in a uniform direction, and otherwise returns to a visited location with the probability proportional
    to its number of visits.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the group of individuals.

        rho:
            The factor `rho` of the probability of exploring.

        gamma:
            The exponent `gamma` of the decay of the probability of exploring.

        beta:
            The exponent `beta` of the power law of the jump lengths, above 1.

        least_jump:
            The least jump length.

    Examples:
        >>> from skcomplex.systems.social.organizations import ExplorationInteraction
        >>> ExplorationInteraction('displacement', target='individuals').rho
        0.6
    """

    draws = True

    law_classes = (UpdateLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        rho: Annotated[float, RealSet.closed(0, 1)] = 0.6,
        gamma: Annotated[float, RealSet.closed_open(0, oo)] = 0.21,
        beta: Annotated[float, RealSet.open(1, oo)] = 1.55,
        least_jump: Annotated[float, RealSet.open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.rho = rho
        self.gamma = gamma
        self.beta = beta
        self.least_jump = least_jump

    def _prepare(self, s: SimpleNamespace) -> None:
        """Set the displacement rule.

        Args:
            s:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(s)
        self.laws_: list[BaseLaw] = [UpdateLaw(s, self.move)]

    def move(self, system: SystemView) -> None:
        """Displace every individual once, to a new location or back to a visited one.

        Args:
            system:
                The system.
        """
        rng = system.rng
        memory = system.storage
        for individual in cast(list[ExplorerView], system.get_agents(self.target)):
            places = memory.setdefault(f'places {individual.id}', [(individual.x, individual.y)])
            visits = memory.setdefault(f'visits {individual.id}', [1.0])
            if not isinstance(places, list) or not isinstance(visits, list):
                continue
            if rng.random() < self.rho * len(places) ** -self.gamma:
                length = self.least_jump * (1 - rng.random()) ** (-1 / (self.beta - 1))
                angle = 2 * np.pi * rng.random()
                place = (individual.x + length * np.cos(angle), individual.y + length * np.sin(angle))
                places.append(place)
                visits.append(1.0)
            else:
                weights = np.asarray(visits)
                index = int(rng.choice(len(places), p=weights / weights.sum()))
                visits[index] += 1.0
                place = places[index]
            individual.x, individual.y = float(place[0]), float(place[1])
            individual.distinct = float(len(places))

Equations

The equations are those that symbolic returns for the system with its default parameters.