Skip to content

Kinetic wealth and welfare dynamics

The kinetic theory of wealth classes.

  • Class: KineticWealthWelfareSystem
  • Import: from skcomplex.systems.economics.econophysics import KineticWealthWelfareSystem
  • Field: economics/econophysics
  • Topics: wealth, kinetic, distribution, welfare
  • References:
    • Bellomo et al. 2017
    • Dolfin and Lachowicz 2014
    • Bertotti and Delitala 2008

Use this system

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

from skcomplex.systems.economics.econophysics import KineticWealthWelfareSystem

trajectory = KineticWealthWelfareSystem().prepare().simulate()

Parameters

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

Parameter Default
classes 9
cooperation 0.2
competition 0.3
eta 1.0
tax 0.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 lattice
Laws rate
Randomness deterministic
Domains real
Structure fixed

Class

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

class KineticWealthWelfareSystem(BaseSystem):
    """The kinetic theory of wealth classes.

    A positive tax adds a welfare policy. The population is a distribution over wealth classes, a site group on a
    lattice of the classes. Encounters between classes move particles one class up or down, with cooperation narrowing
    the gaps and competition widening them, so the total density stays constant. When competition wins, wealth polarises
    toward the poorest and the richest classes, and the Gini coefficient grows. A welfare policy is an encounter with a
    group of fixed density, which moves the richest third of the classes down and the poorest third up and lowers the
    stationary Gini coefficient.

    The system has the distribution `wealth`, the encounters `exchange`, and with a tax the group `state` and the policy
    `welfare`. Its standard observables are the density, the mean wealth, and the Gini coefficient of `wealth`.

    Args:
        classes:
            The number of wealth classes.

        cooperation:
            The probability of the move that narrows the gap between the classes of an encounter.

        competition:
            The probability of the move that widens it.

        eta:
            The encounter rate.

        tax:
            The rate of the welfare policy, 0 for none.

        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.economics.econophysics import KineticWealthWelfareSystem
        >>> [item.label for item in KineticWealthWelfareSystem(tax=0.2).prepare().system_.interactions]
        ['exchange', 'welfare']
    """

    field = 'economics/econophysics'
    topics = ('wealth', 'kinetic', 'distribution', 'welfare')
    references = WELFARE_REFERENCES
    until = 100
    dt = 1.0

    @staticmethod
    def _get_classes_of(system: System) -> int:
        """Return the number of wealth classes of a system, the size of its distribution."""
        return int(np.size(next(item.x for item in system.elements if item.label == 'wealth')))

    def __init__(
        self,
        classes: int = 9,
        *,
        cooperation: float = 0.2,
        competition: float = 0.3,
        eta: float = 1.0,
        tax: float = 0.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.classes = classes
        self.cooperation = cooperation
        self.competition = competition
        self.eta = eta
        self.tax = tax

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the components built from the model parameters."""
        super()._prepare(context)
        initial = np.exp(-((wealth_classes(self.classes) - 0.5) ** 2) / 0.05)
        components = [
            WealthDensityElement(
                'wealth',
                x=initial / initial.sum(),
                space=LatticeSpace(self.classes, boundary='fixed'),
            ),
        ]
        interactions: list[BaseInteraction] = [
            WealthExchangeInteraction(
                'exchange',
                candidate='wealth',
                field='wealth',
                classes=self.classes,
                eta=self.eta,
                cooperation=self.cooperation,
                competition=self.competition,
            ),
        ]
        if self.tax > 0:
            components.append(WealthDensityElement('state', x=[1.0], size=1))
            interactions.append(
                WelfarePolicyInteraction(
                    'welfare',
                    candidate='wealth',
                    field='state',
                    classes=self.classes,
                    tax=self.tax,
                ),
            )
        self.system_ = System(
            self.label,
            elements=components,
            interactions=interactions,
            space=LatticeSpace(self.classes, boundary='fixed'),
        )
        self.observables_ = tuple(wealth_observables(KineticWealthWelfareSystem._get_classes_of(self.system_)))

Components

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

Elements:

Interactions:

class WealthDensityElement(NonnegativeElement):
    """Value `x` of the density of agents at one wealth class.

    A wealth distribution is this element on a lattice of wealth classes, with one value per class, and the exchanges
    and the welfare policy change it. The element has no laws of its own.

    Args:
        label:
            The label of the element, unique among the components of its system.

        x:
            The initial density, a nonnegative number.

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

        space:
            The space with one member per site, such as a lattice of classes, or `None` for none.

    Examples:
        >>> from skcomplex.core.components.spaces import LatticeSpace
        >>> from skcomplex.systems.economics.econophysics import WealthDensityElement
        >>> classes = LatticeSpace(5, boundary='fixed')
        >>> WealthDensityElement('wealth', x=[0.2] * 5, space=classes).x
        [0.2, 0.2, 0.2, 0.2, 0.2]
    """

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, x=x, size=size, space=space)

class WealthExchangeInteraction(EncounterInteraction):
    """Conservative encounters between wealth classes.

    They include cooperation and competition. A candidate of class `h` meets a field particle of class `k` at the rate
    `eta` and moves by the transition table of `exchange_table`.

    Args:
        label:
            The label of the interaction.

        candidate:
            The path of the distribution over wealth classes whose particles move.

        field:
            The path of the distribution over wealth classes they meet, the candidate again.

        classes:
            The number of wealth classes.

        eta:
            The encounter rate.

        cooperation:
            The probability of the move that narrows the gap between the classes of an encounter.

        competition:
            The probability of the move that widens it.

    Examples:
        >>> from skcomplex.systems.economics.econophysics import WealthExchangeInteraction
        >>> WealthExchangeInteraction('exchange', candidate='wealth', field='wealth').competition
        0.3
    """

    def __init__(
        self,
        label: str,
        *,
        candidate: str,
        field: str,
        classes: Annotated[int, RealSet.open(0, oo)] = 9,
        eta: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        cooperation: Annotated[float, RealSet.closed_open(0, oo)] = 0.2,
        competition: Annotated[float, RealSet.closed_open(0, oo)] = 0.3,
    ) -> None:
        super().__init__(label, candidate=candidate, field=field, rate=self._get_rate, kernel=self._get_kernel)
        self.classes = classes
        self.eta = eta
        self.cooperation = cooperation
        self.competition = competition

    def _get_rate(self, s: SimpleNamespace) -> Expression:
        """Return the encounter rate `eta`."""
        return s.eta

    def _get_kernel(self, s: SimpleNamespace) -> npt.NDArray[np.object_]:
        """Return the transition table of the encounters.

        It uses the cooperation and competition parameters.
        """
        return exchange_table(int(self.classes), s.cooperation, s.competition)