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.systems.social.language import LanguageElement
>>> LanguageElement('language').exponent
1.0
Source code in src/skcomplex/systems/social/language/_word_frequencies.py
40 41 42 | |
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 |
required |
words
|
Annotated[str, RoleSpec()]
|
The path of the group of words, which hold |
required |
Examples:
>>> from skcomplex.systems.social.language import LeastEffortInteraction
>>> LeastEffortInteraction('effort', target='language', words='words').words
'words'
Source code in src/skcomplex/systems/social/language/_word_frequencies.py
98 99 100 101 102 103 104 105 106 107 | |
TypedWordElement(label, visual=None, *, count=1.0, length=1.0, code=1.0)
Bases: Element
Distinct word of a randomly typed text, with its number of occurrences and its number of letters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the word or the group. |
required |
visual
|
VisualSpec | None
|
How the agent is drawn, or |
None
|
count
|
Annotated[float, StateSpec(domain=NN)]
|
The number of occurrences of the word. |
1.0
|
length
|
Annotated[float, StateSpec(domain=NN)]
|
The number of letters of the word. |
1.0
|
code
|
Annotated[float, StateSpec(domain=NN)]
|
The word as a number, its letters |
1.0
|
Examples:
>>> from skcomplex.systems.social.language import TypedWordElement
>>> TypedWordElement('word', length=3.0).length
3.0
Source code in src/skcomplex/systems/social/language/_typewriting.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
TypedWordView(agent, stepper)
Bases: AgentView
View of a typed word of the random typewriting system, with its states as attributes.
Source code in src/skcomplex/core/engine/solvers/_mesa.py
559 560 561 | |
TypingInteraction(label, *, target, letters=5, space_bar=0.2, keystrokes=1000)
Bases: Interaction
Typing of Miller's monkeys, random keystrokes on a typewriter with a number of letters and a space bar.
Every keystroke hits the space bar with the probability space_bar, and otherwise one of the letters letters,
uniformly. The space bar ends the word typed since the last space, a new distinct word or one more occurrence of
an earlier one, and a space after a space types no word. A word is held as its code, its letters k_1, ..., k_L
from 0 read as the digits k_i + 1 of base letters, so distinct words have distinct codes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Annotated[str, RoleSpec()]
|
The path of the variable group of distinct words. |
required |
letters
|
Annotated[int, ParameterSpec(domain=closed_open(1, oo))]
|
The number of letters of the typewriter. |
5
|
space_bar
|
Annotated[float, ParameterSpec(domain=open(0, 1))]
|
The probability that a keystroke hits the space bar. |
0.2
|
keystrokes
|
Annotated[int, ParameterSpec(domain=NN)]
|
The number of keystrokes per step. |
1000
|
Examples:
>>> from skcomplex.systems.social.language import TypingInteraction
>>> TypingInteraction('typing', target='words').letters
5
Source code in src/skcomplex/systems/social/language/_typewriting.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
type_keys(system)
Type the keystrokes of one step and count the words they end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system. |
required |
Source code in src/skcomplex/systems/social/language/_typewriting.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
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.systems.social.language import WordElement
>>> WordElement('word', cost=1.0).cost
1.0
Source code in src/skcomplex/systems/social/language/_word_frequencies.py
64 65 66 67 68 69 70 71 72 | |
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 system, with the states |
Examples:
>>> from skcomplex.core.engine.runtime import Simulation
>>> from skcomplex.systems.social.language import mandelbrot_least_effort
>>> trajectory = Simulation(mandelbrot_least_effort(50)).prepare().run(1.0).trajectory_
>>> round(float(trajectory.values('words.probability')[0].sum()), 6)
1.0
Source code in src/skcomplex/systems/social/language/_word_frequencies.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
random_typewriting(letters=5, *, space=0.2, keystrokes=1000, random_state=0)
Return Miller's random typewriting, monkeys whose random keystrokes give Zipf's law of word frequencies.
A typewriter has letters letters and a space bar hit with the probability q = space, and every space ends a
word. A word of L letters has the probability q ((1 - q) / letters)^L, so its frequency falls exponentially
with its length, while the number of distinct words of length L grows exponentially as letters^L. The two
exponentials give a power law of the frequency of the word of rank r, r^(-alpha) with
alpha = 1 - log(1 - q) / log(letters) (Thurner et al. 2018 section 3.3.6.2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
letters
|
int
|
The number of letters of the typewriter. |
5
|
space
|
float
|
The probability that a keystroke hits the space bar. |
0.2
|
keystrokes
|
int
|
The number of keystrokes per step. |
1000
|
random_state
|
int | Generator | None
|
The seed or generator of the first word of the text. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the variable group |
Examples:
>>> from skcomplex.systems.social.language import random_typewriting
>>> random_typewriting().elements[0].prepare().size_
1
Source code in src/skcomplex/systems/social/language/_typewriting.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |