Skip to content

Base

Define the abstract base of every component of a system.

BaseComponent(label)

Bases: _BaseEstimator[ContextT]

An abstract component of a system, with a label, arguments, and tags.

The components of a system are its elements, interactions, spaces, and the system itself, such as the ball of Element('ball', values={'x': 10.0, 'm': 1.0}). Every component has a label and stores its arguments under their own names, so get_params, set_params, and clone work on it. Its method prepare(context) checks the arguments and sets the attributes that end in _, such as laws_ of an interaction. An element is prepared against the space of its system and an interaction against the elements its roles bind. Which values are states and which are parameters follows from the laws. get_tags returns what a component can do, read from its arguments alone, so the tags are known before prepare. A component whose rules draw random numbers that its laws do not show sets the class attribute draws. It is the base of the populations and contacts of an epidemic and of the accounts and payments of an economy.

Read more in the user guide, under Extend the library.

Parameters:

Name Type Description Default
label str

The name of the component, unique among the components of its system, such as 'ball'.

required
See Also

BaseConfig: The base of the engine classes, which run. BaseElement: The base of the components that hold values.

Examples:

>>> from skcomplex.core.components.base import BaseComponent
>>> from skcomplex.core.components.elements import Element
>>> ball = Element('ball', values={'x': 10.0, 'm': 1.0}).prepare()
>>> isinstance(ball, BaseComponent), ball.label
(True, 'ball')
Source code in src/skcomplex/core/components/base.py
69
70
def __init__(self, label: str) -> None:
    self.label = label

draws = False class-attribute

Whether the run of the component draws random numbers that the kinds of its laws do not show.

reparameterized = False class-attribute

Whether every draw of the component is a uniform, normal, or relaxed draw that JAX differentiates.

get_tags()

Return the capability tags of the component.

They come from its declarations and its arguments alone.

Returns:

Name Type Description
tags Tags

The tags of the component, known before it is prepared.

Examples:

A component whose rules draw random numbers declares it, so its randomness is stochastic:

>>> from skcomplex.core.components.elements import Element
>>> class WalkerElement(Element):
...     draws = True
>>> WalkerElement('walker').get_tags().randomness
'stochastic'
Source code in src/skcomplex/core/components/base.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def get_tags(self) -> Tags:
    """Return the capability tags of the component.

    They come from its declarations and its arguments alone.

    Returns:
        tags:
            The tags of the component, known before it is prepared.

    Examples:
        A component whose rules draw random numbers declares it, so its randomness is stochastic:

        >>> from skcomplex.core.components.elements import Element
        >>> class WalkerElement(Element):
        ...     draws = True
        >>> WalkerElement('walker').get_tags().randomness
        'stochastic'
    """
    tags = self._get_tags()
    tags = replace(tags, randomness='stochastic') if self._get_draws() else tags
    return replace(tags, reparameterized=True) if self.reparameterized else tags