Skip to content

Galam majority

The Galam majority system.

  • Class: GalamMajoritySystem
  • Import: from skcomplex.systems.social.opinion_dynamics import GalamMajoritySystem
  • Field: social/opinion_dynamics
  • Topics: opinion, agents, majority, consensus
  • References:
    • Galam 2002
    • Castellano, Fortunato, and Loreto 2009

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.opinion_dynamics import GalamMajoritySystem

trajectory = GalamMajoritySystem().prepare().simulate()

Parameters

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

Parameter Default
n_agents 300
group_size 3
share 0.4
random_state 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 fixed

Class

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

class GalamMajoritySystem(BaseSystem):
    """The Galam majority system.

    Random groups adopt their majority until one opinion wins. The system has the group `citizens`.

    Args:
        n_agents:
            The number of agents.

        group_size:
            The number of agents in each discussion group.

        share:
            The share of agents with opinion 1.

        random_state:
            The seed or generator of the opinions.

        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.opinion_dynamics import GalamMajoritySystem
        >>> GalamMajoritySystem(30, random_state=0).prepare().system_.elements[0].size
        30
    """

    field = 'social/opinion_dynamics'
    topics = ('opinion', 'agents', 'majority', 'consensus')
    references = ('Galam 2002', 'Castellano, Fortunato, and Loreto 2009')
    until = 20

    def __init__(
        self,
        n_agents: int = 300,
        *,
        group_size: int = 3,
        share: float = 0.4,
        random_state: int | np.random.Generator | None = 0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_agents = n_agents
        self.group_size = group_size
        self.share = share
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components built from the model parameters."""
        super()._prepare(context)
        citizens = CitizenElement(
            'citizens',
            opinion=SznajdSystem._get_shares(self.n_agents, self.share, self.random_state),
            size=self.n_agents,
        )
        self.system_ = System(
            self.label,
            elements=[citizens],
            interactions=[DiscussionsInteraction('talks', among='citizens', along=RandomPartition(self.group_size))],
        )

Components

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

Elements:

Interactions:

  • DiscussionsInteraction, from Interaction
class CitizenElement(Element):
    """Agent of the Galam majority system, who holds a binary opinion.

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

        opinion:
            The initial opinion, 0 or 1.

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

    Examples:
        >>> from skcomplex.systems.social.opinion_dynamics import CitizenElement
        >>> group = CitizenElement('citizens', opinion=1.0, size=10)
        >>> group.label, type(group).__name__, group.size
        ('citizens', 'CitizenElement', 10)
    """

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

class DiscussionsInteraction(Interaction):
    """Discussions of the Galam system.

    They split the citizens into random groups that adopt their majority opinion, drawn again at every step. A tie in a
    group of even size goes to opinion 0, the status quo.

    Args:
        label:
            The label of the interaction.

        among:
            The path of the group of citizens.

        along:
            The random groups of the discussions, such as `RandomPartition(3)` for groups of three citizens, the last
            group holding the remainder.

    Examples:
        >>> from skcomplex.core.components.interactions import RandomPartition
        >>> from skcomplex.systems.social.opinion_dynamics import DiscussionsInteraction
        >>> DiscussionsInteraction('talks', among='citizens', along=RandomPartition(4)).along
        RandomPartition(size=4)
    """

    def __init__(self, label: str, *, among: Role, along: RandomPartition = TRIPLES) -> None:
        super().__init__(label, among=among, along=along)

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the opinion of every citizen to 1 when most members of its group hold 1, and to 0 otherwise.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        majority = where(mean(context.members.opinion, over=context.members) > 1 / 2, 1, 0)
        self.laws_ = [UpdateLaw(context.member.opinion, majority)]

Equations

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

citizens.opinion[i]: opinion_citizens(t + 1) == where(1/3*opinion_citizens__member + 1/3*opinion_citizens__other0 + 1/3*opinion_citizens__other1 > 0.5, 1, 0)