Skip to content

Language

Language: the statistics of words from the economy of their use.

LanguageElement(label, exponent=1.0)

Bases: Element

Language with the exponent lambda of its word frequencies.

Parameters:

Name Type Description Default
label str

The label of the language.

required
exponent Annotated[float, StateSpec()]

The initial guess of the exponent, from which it is solved.

1.0

Examples:

>>> from skcomplex.models.social.language import LanguageElement
>>> LanguageElement('language').exponent
1.0
Source code in src/skcomplex/models/social/language/_language.py
28
29
30
def __init__(self, label: str, exponent: Annotated[float, StateSpec()] = 1.0) -> None:
    super().__init__(label)
    self.exponent = exponent

LeastEffortInteraction(label, *, target, words)

Bases: Interaction

Probabilities of words that minimise the ratio of the mean cost C to the entropy H.

The probabilities that are stationary for C / H on the simplex are p_i = exp(-lambda c_i) / Z, for which H = lambda C + ln Z. The ratio is stationary in lambda where H = lambda C, that is where ln Z = 0, which solves the exponent. The sum reduces in log space.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Annotated[str, RoleSpec()]

The path of the element that holds exponent.

required
words Annotated[str, RoleSpec()]

The path of the group of words, which hold cost and probability.

required

Examples:

>>> from skcomplex.models.social.language import LeastEffortInteraction
>>> LeastEffortInteraction('effort', target='language', words='words').words
'words'
Source code in src/skcomplex/models/social/language/_least_effort.py
42
43
44
45
46
47
48
49
50
51
def __init__(
    self,
    label: str,
    *,
    target: Annotated[str, RoleSpec()],
    words: Annotated[str, RoleSpec()],
) -> None:
    super().__init__(label)
    self.target = target
    self.words = words

WordElement(label, cost=1.0, probability=0.0)

Bases: Element

Word with a quenched cost and the probability of its use.

Parameters:

Name Type Description Default
label str

The label of the word or the group.

required
cost Annotated[float, StateSpec()]

The cost of the word.

1.0
probability Annotated[float, StateSpec()]

The initial guess of the probability, which the equation replaces.

0.0

Examples:

>>> from skcomplex.models.social.language import WordElement
>>> WordElement('word', cost=1.0).cost
1.0
Source code in src/skcomplex/models/social/language/_word.py
31
32
33
34
35
36
37
38
39
def __init__(
    self,
    label: str,
    cost: Annotated[float, StateSpec()] = 1.0,
    probability: Annotated[float, StateSpec()] = 0.0,
) -> None:
    super().__init__(label)
    self.cost = cost
    self.probability = probability

mandelbrot_least_effort(n_words=200)

Return the word frequencies that minimise the mean cost of a language over its entropy, a power law of rank.

A word of rank i costs log(i + 1), the length of its code, so the probabilities are (i + 1)^-lambda, where lambda makes them sum to 1 (Giordano 2024 §6, after Mandelbrot 1953).

Parameters:

Name Type Description Default
n_words int

The number of words.

200

Returns:

Name Type Description
system System

The model, with the states language.exponent, words.cost, and words.probability.

Examples:

>>> from skcomplex.engine.runtime import Simulation
>>> from skcomplex.models.social.language import mandelbrot_least_effort
>>> trajectory = Simulation(mandelbrot_least_effort(50)).check().prepare().run(1.0).trajectory_
>>> round(float(trajectory.values('words.probability')[0].sum()), 6)
1.0
Source code in src/skcomplex/models/social/language/_word_frequencies.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@register_model(
    field='social/language',
    tags=('power law', 'least effort', 'entropy', 'static'),
    references=('Giordano 2024, arXiv 2407.02181', 'Mandelbrot 1953'),
)
def mandelbrot_least_effort(n_words: int = 200) -> System:
    """Return the word frequencies that minimise the mean cost of a language over its entropy, a power law of rank.

    A word of rank `i` costs `log(i + 1)`, the length of its code, so the probabilities are `(i + 1)^-lambda`, where
    `lambda` makes them sum to 1 (Giordano 2024 §6, after Mandelbrot 1953).

    Args:
        n_words:
            The number of words.

    Returns:
        system:
            The model, with the states `language.exponent`, `words.cost`, and `words.probability`.

    Examples:
        >>> from skcomplex.engine.runtime import Simulation
        >>> from skcomplex.models.social.language import mandelbrot_least_effort
        >>> trajectory = Simulation(mandelbrot_least_effort(50)).check().prepare().run(1.0).trajectory_
        >>> round(float(trajectory.values('words.probability')[0].sum()), 6)
        1.0
    """
    costs = np.log(np.arange(1, n_words + 1) + 1.0)
    visual = VisualSpec('histograms', {'color_by': 'probability'})
    words = GroupElement('words', element=WordElement, size=n_words, values={'cost': costs}, visual=visual)
    effort = LeastEffortInteraction('effort', target='language', words='words')
    return System(elements=[words, LanguageElement('language')], interactions=[effort], time=StaticTime())