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
|
float
|
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
39 40 41 | |
LeastEffortInteraction(label, *, target, words)
Bases: Interaction
Probabilities of words that minimise the ratio of the mean cost to the entropy.
The mean cost is C and 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
|
Role
|
The path of the element that holds |
required |
words
|
Role
|
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
105 106 107 108 109 110 111 112 113 114 | |
MandelbrotLeastEffortSystem(n_words=200, *, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The word frequencies that minimise the mean cost of a language over its entropy.
They are 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). The system has
the states language.exponent, words.cost, and words.probability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_words
|
int
|
The number of words. |
200
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.social.language import MandelbrotLeastEffortSystem
>>> trajectory = MandelbrotLeastEffortSystem(50).prepare().simulate(until=1.0)
>>> round(float(trajectory.get_values('words.probability')[0].sum()), 6)
1.0
Source code in src/skcomplex/systems/social/language/_word_frequencies.py
163 164 165 166 167 168 169 170 171 172 | |
RandomTypewritingSystem(letters=5, *, space=0.2, keystrokes=1000, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Miller's random typewriting.
The random keystrokes of monkeys 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). The
system has the variable group words, which starts with the first word of the text.
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
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.social.language import RandomTypewritingSystem
>>> RandomTypewritingSystem().prepare().system_.elements[0].size
1
Source code in src/skcomplex/systems/social/language/_typewriting.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
TypedWordElement(label, *, count=1.0, length=1.0, code=1.0, size=None)
Bases: Element
Distinct word of a randomly typed text.
It holds 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 |
count
|
Annotated[object, NN]
|
The number of occurrences of the word. |
1.0
|
length
|
Annotated[object, NN]
|
The number of letters of the word. |
1.0
|
code
|
Annotated[object, NN]
|
The word as a number, its letters |
1.0
|
size
|
int | None
|
The number of words, or |
None
|
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
66 67 68 69 70 71 72 73 74 75 76 77 78 | |
TypedWordView
Bases: AgentViewProtocol, Protocol
View of a typed word of the random typewriting system.
Its states are attributes.
TypingInteraction(label, *, target, letters=5, space_bar=0.2, keystrokes=1000)
Bases: Interaction
Typing of Miller's monkeys.
The keystrokes are random, 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
|
Role
|
The path of the variable group of distinct words. |
required |
letters
|
Annotated[int, closed_open(1, oo)]
|
The number of letters of the typewriter. |
5
|
space_bar
|
Annotated[float, open(0, 1)]
|
The probability that a keystroke hits the space bar. |
0.2
|
keystrokes
|
Annotated[int, 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
WordElement(label, cost=1.0, probability=0.0, size=None)
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
|
object
|
The cost of the word. |
1.0
|
probability
|
object
|
The initial guess of the probability, which the equation replaces. |
0.0
|
size
|
int | None
|
The number of words, or |
None
|
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
68 69 70 71 72 73 74 75 76 77 | |