NK technology system
McNerney's system of technological improvement.
- Class:
NkTechnologySystem - Import:
from skcomplex.systems.economics.innovation import NkTechnologySystem - Field:
economics/innovation - Topics:
innovation,technology,learning curve,agents - References:
- Thurner et al. 2018
- McNerney et al. 2011
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 NkTechnologySystem
trajectory = NkTechnologySystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_components |
10 |
d |
2 |
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 | real |
| Structure | variable membership |
Class
The source of the class shows how it builds its components from its model parameters.
class NkTechnologySystem(BaseSystem):
"""McNerney's system of technological improvement.
Its cost falls as a power of the cumulative production. Every step is one unit of production and one attempt to
redesign a random component together with the components that depend on it. Redesigns are kept only when they cut
the total cost, which falls like Wright's law, more slowly for designs whose components depend on more others. The
system has the group `components` and the total cost `total_cost`.
Args:
n_components:
The number of components.
d:
The number of components that a redesign of one component changes, itself included.
random_state:
The seed or generator of the design structure matrix and the initial costs.
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 NkTechnologySystem
>>> NkTechnologySystem(5, 1).prepare().system_.interactions[0].dependencies[0]
(1.0, 0.0, 0.0, 0.0, 0.0)
"""
field = 'economics/innovation'
topics = ('innovation', 'technology', 'learning curve', 'agents')
references = ('Thurner et al. 2018', 'McNerney et al. 2011')
until = 200
observables = (Observable('total_cost', group='components', reduce='sum', variable='cost'),)
def __init__(
self,
n_components: int = 10,
d: int = 2,
*,
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_components = n_components
self.d = d
self.random_state = random_state
@staticmethod
def _get_design_structure(n_components: int, d: int, rng: np.random.Generator) -> Array:
"""Return a design structure matrix.
A change of a component changes it and `d - 1` other ones.
"""
matrix = np.eye(n_components)
for column in range(n_components):
others = rng.choice([row for row in range(n_components) if row != column], d - 1, replace=False)
matrix[others, column] = 1.0
return matrix
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the components built from the model parameters."""
super()._prepare(context)
rng = np.random.default_rng(self.random_state)
dependencies = self._get_design_structure(self.n_components, self.d, rng)
components = PartElement('components', cost=rng.random(self.n_components), size=self.n_components)
self.system_ = System(
self.label,
elements=[components],
interactions=[
RedesignInteraction(
'redesign',
components='components',
dependencies=tuple(map(tuple, dependencies.tolist())),
),
],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PartElement, fromElement
Interactions:
RedesignInteraction, fromInteraction
class PartElement(Element):
"""PartElement of a technology, described by its unit cost.
Args:
label:
The label of the agent or group.
cost:
The initial unit cost.
size:
The number of members, or `None` for one.
Examples:
>>> from skcomplex.systems.economics.innovation import PartElement
>>> PartElement('components', cost=0.5, size=5).size
5
"""
def __init__(
self,
label: str,
*,
cost: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
size: int | None = None,
) -> None:
super().__init__(label, size=size)
self.cost = cost
class RedesignInteraction(Interaction):
"""Attempt to cut the cost of a technology by redesigning its components.
It redesigns a random component and the components that depend on it. The redesigned components get new costs drawn
uniformly from `[0, 1]`, and the redesign is kept only if the total cost falls. `dependencies[i][j]` is 1 when a
change of component `j` requires a change of component `i`.
Args:
label:
The label of the interaction.
components:
The path of the group of components.
dependencies:
The design structure matrix.
Examples:
>>> from skcomplex.systems.economics.innovation import RedesignInteraction
>>> RedesignInteraction('redesign', components='components', dependencies=[[1.0]]).dependencies
[[1.0]]
"""
draws = True
law_classes = (UpdateLaw,)
def __init__(
self,
label: str,
*,
components: Role,
dependencies: Sequence[Sequence[float]] = (),
) -> None:
super().__init__(label)
self.components = components
self.dependencies = dependencies
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.redesign)]
def redesign(self, system: SystemView) -> None:
"""Propose new costs for a random component and its dependents.
They are kept if the total cost falls.
Args:
system:
The system.
"""
components = sorted(cast(list[PartView], system.get_agents('components')), key=lambda component: component.id)
cost = np.array([component.cost for component in components])
proposal, changed = RedesignInteraction._get_components(
cost,
np.asarray(self.dependencies, dtype=float),
system.rng,
)
if proposal.sum() >= cost.sum():
return
for index in changed:
components[index].cost = float(proposal[index])
@staticmethod
def _get_components(
cost: Array,
dependencies: Array,
rng: np.random.Generator,
) -> tuple[Array, npt.NDArray[np.intp]]:
"""Return the proposed costs of a redesign of a random component.
They include the components that depend on it.
"""
changed = np.flatnonzero(dependencies[:, int(rng.integers(len(cost)))])
proposal = cost.copy()
proposal[changed] = rng.random(len(changed))
return proposal, changed
Equations
The equations are those that symbolic returns for the system with its default parameters.