Skip to content

Arthur-Polak technology evolution

Arthur and Polak's evolution of technology.

  • Class: ArthurPolakSystem
  • Import: from skcomplex.systems.economics.innovation import ArthurPolakSystem
  • Field: economics/innovation
  • Topics: innovation, technology, combinatorial evolution, agents
  • References:
    • Thurner et al. 2018
    • Arthur and Polak 2006

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.innovation import ArthurPolakSystem

trajectory = ArthurPolakSystem().prepare().simulate()

Parameters

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

Parameter Default
max_components 12
max_inputs 3
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 deterministic
Domains integer
Structure variable membership

Class

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

class ArthurPolakSystem(BaseSystem):
    """Arthur and Polak's evolution of technology.

    It builds logic functions from NAND gates. The pool starts with the NAND gate and the constants 0 and 1. Every step
    wires a random circuit from the pool and keeps it when it computes a wanted function, negation, two-input and, or,
    exclusive or, nor, equivalence, and implication, or three-input and, or, parity, and majority, so simple inventions
    become the building blocks of complex ones. The system has the pool `technologies`, whose size is the reporter
    `technologies.count`.

    Args:
        max_components:
            The largest number of technologies in a circuit.

        max_inputs:
            The largest number of inputs of a circuit.

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

    field = 'economics/innovation'
    topics = ('innovation', 'technology', 'combinatorial evolution', 'agents')
    references = ('Thurner et al. 2018', 'Arthur and Polak 2006')
    until = 200

    def __init__(
        self,
        *,
        max_components: int = 12,
        max_inputs: int = 3,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.max_components = max_components
        self.max_inputs = max_inputs

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the components built from the model parameters."""
        super()._prepare(context)
        primitives = (NAND, FALSE, TRUE)
        technologies = TechnologyElement(
            'technologies',
            arity=[float(arity) for arity, _ in primitives],
            table=[float(table) for _, table in primitives],
            cost=[1.0, 0.0, 0.0],
            size=len(primitives),
        )
        invention = InventionInteraction(
            'invention',
            technologies='technologies',
            max_components=float(self.max_components),
            max_inputs=float(self.max_inputs),
        )
        self.system_ = System(self.label, elements=[technologies], interactions=[invention])

Components

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

Elements:

Interactions:

  • InventionInteraction, from Interaction
class TechnologyElement(Element):
    """Logic circuit in the pool of technologies.

    It is described by the truth table of the function it computes. Bit `r` of the table is the output on the inputs
    whose bits form `r`, with the first input as the lowest bit.

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

        arity:
            The number of inputs.

        table:
            The truth table.

        cost:
            The number of NAND gates in the circuit.

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

    Examples:
        >>> from skcomplex.systems.economics.innovation import TechnologyElement
        >>> TechnologyElement('technologies', arity=[2, 0, 0], table=[7, 0, 1], size=3).size
        3
    """

    def __init__(
        self,
        label: str,
        *,
        arity: Annotated[object, NN] = 2,
        table: Annotated[object, NN] = NAND[1],
        cost: Annotated[object, NN] = 1,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.arity = arity
        self.table = table
        self.cost = cost

class InventionInteraction(Interaction):
    """Random wiring of technologies of the pool into a circuit.

    The circuit is kept if it computes a wanted function more cheaply. A circuit has between one and `max_inputs` inputs
    and wires between two and `max_components` technologies in a row, each pin to an input or to the output of an
    earlier technology. The output of the last one is the circuit's output. A circuit that computes a wanted function
    joins the pool, or replaces the technology of that function when it uses fewer NAND gates.

    Args:
        label:
            The label of the interaction.

        technologies:
            The path of the group of technologies.

        max_components:
            The largest number of technologies in a circuit.

        max_inputs:
            The largest number of inputs of a circuit.

    Examples:
        >>> from skcomplex.systems.economics.innovation import InventionInteraction
        >>> InventionInteraction('invention', technologies='technologies', max_components=6).max_components
        6
    """

    law_classes = (UpdateLaw,)

    def __init__(
        self,
        label: str,
        *,
        technologies: Role,
        max_components: Annotated[float, RealSet.open(0, oo)] = 12,
        max_inputs: Annotated[float, RealSet.open(0, oo)] = 3,
    ) -> None:
        super().__init__(label)
        self.technologies = technologies
        self.max_components = max_components
        self.max_inputs = max_inputs

    def _wire(self, pool: list[TechnologyView], system: SystemView) -> tuple[int, int, int]:
        """Return the arity, the truth table, and the cost of a random circuit.

        The circuit wires technologies of the pool.
        """
        rng = system.rng
        n_inputs = int(rng.integers(1, int(system.get_parameter('max_inputs')) + 1))
        n_parts = int(rng.integers(2, int(system.get_parameter('max_components')) + 1))
        signals, cost = InventionInteraction._get_input_signals(n_inputs), 0
        for _ in range(n_parts):
            part = pool[int(rng.integers(len(pool)))]
            pins = [signals[int(rng.integers(len(signals)))] for _ in range(int(part.arity))]
            signals.append(InventionInteraction._apply(int(part.table), int(part.arity), pins, n_inputs))
            cost += int(part.cost)
        return n_inputs, signals[-1], cost

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the rule of the system.

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

    def invent(self, system: SystemView) -> None:
        """Wire a random circuit and add it to the pool if it is better.

        It is better when it computes a wanted function better.

        Args:
            system:
                The system.
        """
        pool = cast(list[TechnologyView], system.get_agents('technologies'))
        arity, table, cost = self._wire(pool, system)
        if (arity, table) not in GOALS:
            return
        known = [technology for technology in pool if (technology.arity, technology.table) == (arity, table)]
        if not known:
            system.create('technologies', arity=arity, table=table, cost=cost)
        elif cost < known[0].cost:
            known[0].cost = cost

    @staticmethod
    def _get_input_signals(n_inputs: int) -> list[int]:
        """Return the truth tables of the primary inputs of a circuit."""
        rows = range(2**n_inputs)
        return [sum(1 << row for row in rows if row >> pin & 1) for pin in range(n_inputs)]

    @staticmethod
    def _apply(table: int, arity: int, signals: Sequence[int], n_inputs: int) -> int:
        """Return the truth table of a gate with a table and an arity.

        The gate is wired to the signals of a circuit.
        """
        output = 0
        for row in range(2**n_inputs):
            index = sum((signal >> row & 1) << pin for pin, signal in enumerate(signals[:arity]))
            output |= (table >> index & 1) << row
        return output

Equations

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