Axelrod culture dissemination
Axelrod's culture dissemination system on a full grid.
- Class:
AxelrodSystem - Import:
from skcomplex.systems.social.opinion_dynamics import AxelrodSystem - Field:
social/opinion_dynamics - Topics:
culture,agents,grid,social influence,phase transition - References:
- Axelrod 1997
- 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 AxelrodSystem
trajectory = AxelrodSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
width |
20 |
height |
20 |
features |
5 |
traits |
10 |
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 | lattice |
| 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 AxelrodSystem(BaseSystem):
"""Axelrod's culture dissemination system on a full grid.
The grid has von Neumann neighbourhoods. Every village starts with random traits. For few traits per feature the
villages converge to one culture, and for many traits they freeze into many small cultural regions, an
order-disorder transition at a critical `q`. The system has the group `villages` and the influence `influence`.
`culture_observables` gives the share of the largest cultural region and the number of cultures.
Args:
width:
The number of columns.
height:
The number of rows.
features:
The number of cultural features `F`.
traits:
The number of traits `q` of every feature.
random_state:
The seed or generator of the initial cultures.
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 AxelrodSystem
>>> AxelrodSystem(5, 4).prepare().system_.elements[0].size
20
"""
field = 'social/opinion_dynamics'
topics = ('culture', 'agents', 'grid', 'social influence', 'phase transition')
references = ('Axelrod 1997', 'Castellano, Fortunato, and Loreto 2009')
until = 200
def __init__(
self,
width: int = 20,
height: int = 20,
*,
features: int = 5,
traits: int = 10,
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.width = width
self.height = height
self.features = features
self.traits = traits
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)
rng = np.random.default_rng(self.random_state)
size = self.width * self.height
digits = rng.integers(self.traits, size=(size, self.features))
cultures = (digits * self.traits ** np.arange(self.features)).sum(axis=1).astype(float)
columns, rows = np.divmod(np.arange(size), self.height)
villages = VillageElement(
'villages',
culture=cultures,
features=self.features,
traits=self.traits,
x=columns,
y=rows,
size=size,
space=LatticeSpace((self.width, self.height), boundary='fixed', metric='manhattan', capacity=1),
)
self.system_ = System(
self.label,
elements=[villages],
interactions=[CulturalInfluenceInteraction('influence', target='villages')],
)
if not self.observables_:
self.observables_ = tuple(culture_observables(self.width, self.height))
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
VillageElement, fromElement
Interactions:
CulturalInfluenceInteraction, fromInteraction
class VillageElement(Element):
"""Village of Axelrod's system, with a culture of `F` features of `q` traits each.
The culture is stored as one integer.
Args:
label:
The label of the agent or group.
culture:
The culture code, the traits of the features as the digits of a number in base `q`.
features:
The number of features `F`.
traits:
The number of traits `q` of every feature.
x:
The column of the cell of the village on a lattice, one per village or shared.
y:
The row of the cell of the village on a lattice, one per village or shared.
size:
The number of villages, or `None` for one.
space:
The lattice the villages live on, whose axes `x` and `y` make `x` and `y` their cell, or `None`.
Examples:
>>> from skcomplex.systems.social.opinion_dynamics import VillageElement
>>> VillageElement('villages', culture=0, features=3, traits=5, size=4).size
4
"""
visual = VisualSpec('agents', {'color_by': 'culture'})
def __init__(
self,
label: str,
*,
culture: Annotated[object, NN] = 0,
features: Annotated[float, RealSet.open(0, oo)] = 5.0,
traits: Annotated[float, RealSet.open(0, oo)] = 10.0,
x: object = 0,
y: object = 0,
size: int | None = None,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, size=size, space=space)
self.culture = culture
self.features = features
self.traits = traits
self.x = x
self.y = y
class CulturalInfluenceInteraction(NeighborhoodsInteraction):
"""Cultural influence of Axelrod's system.
Every step every village, in random order, picks a random neighbour and, with probability equal to the fraction of
features they share, copies the trait of one feature on which they differ.
Args:
label:
The label of the interaction.
target:
The path of the group of villages.
phase:
The phase of the step the influence runs in, or `None` for the default phase.
Examples:
>>> from skcomplex.systems.social.opinion_dynamics import CulturalInfluenceInteraction
>>> CulturalInfluenceInteraction('influence', target='villages').target
'villages'
"""
def __init__(
self,
label: str,
*,
target: Role,
phase: str | None = None,
) -> None:
super().__init__(label, target=target, phase=phase)
def act_on(self, members: list[AgentViewProtocol], system: SystemView) -> None:
"""Copy one differing trait of a random neighbour.
The probability is equal to the cultural overlap.
Args:
members:
The village, followed by its neighbours.
system:
The system view of the rule.
"""
agent, *neighbors = cast(list[VillageView], members)
if not neighbors:
return
neighbor = neighbors[int(system.rng.integers(len(neighbors)))]
features, traits = int(agent.features), int(agent.traits)
own = cultural_traits(agent.culture, features, traits)
other = cultural_traits(neighbor.culture, features, traits)
different = np.flatnonzero(own != other)
if len(different) and system.rng.random() < 1 - len(different) / features:
feature = int(different[int(system.rng.integers(len(different)))])
agent.culture += float((int(other[feature]) - int(own[feature])) * traits**feature)