Learning
Learning realizations shared by the economics packages.
They are the scores of options that agents learn from realized payoffs.
PayoffLearningInteraction(label, *, target, scores, payoff, rate=0.1, rule='average', phase=None, chosen=None, schedule=None)
Bases: Interaction
Payoff learning of the scores of options.
Economics names it reinforcement learning of payoffs, as in fictitious play and the attractions of
experience-weighted learning. Each score moves towards the payoff its option realized in the step. Every step, the
score s_k of option k of every member moves towards the realized payoff P_k at the rate a, s_k <- s_k + a
(P_k - s_k), so a score is an exponentially weighted mean of past payoffs, and the last payoff at the rate 1, by
the rule 'average'. By the rule 'cumulative' the score adds the payoff, s_k <- s_k + P_k, so it is the sum of
past payoffs, such as a virtual score. Without a schedule it sets update laws, and payoff(namespace, k) returns
the payoff of option k as a symbolic expression, where namespace.target holds the states and parameters of the
group. With a schedule it sets one rule that walks the agents of the group in that order, and payoff(agent,
system, k) returns the payoff as a number, so it can read the agent and the history and storage of the system view.
Its scores may then be the components of one vector state, one per option, and a group of one member holds scores
that several groups share. With chosen, the name of a state that holds the index of the option a member chose,
only the score of that option moves, and the payoff of the other options is not read. Every agent reinforces at
once under the schedule 'synchronous', one after the other in their order or in a new random order every step
under 'sequential' or 'random-sequential', and each in its own activation under 'member', together with the
rules of its element and the other member interactions, in the order the system lists them, such as after a choice
and a transfer in one visit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the element or group whose members hold the scores. |
required |
scores
|
str | Sequence[str]
|
The names of the states that hold the score of every option, in the order of the options, or with a schedule the name of one vector state whose components are the scores. |
required |
payoff
|
Callable[..., float | Expression]
|
The function |
required |
rate
|
Annotated[float, closed(0, 1)]
|
The rate |
0.1
|
rule
|
str
|
|
'average'
|
phase
|
str | None
|
The phase of the step the rule of a schedule runs in, or |
None
|
chosen
|
str | None
|
The name of the state that holds the index of the option a member chose, so only its score moves, or
|
None
|
schedule
|
str | None
|
The order in which a rule walks the agents, |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The rule or the schedule is unknown, there are no scores, or the payoff is not callable. |
Examples:
>>> from skcomplex.systems.economics.common.learning import PayoffLearningInteraction
>>> reinforcement = PayoffLearningInteraction(
... 'reinforcement', target='learners', scores=('first', 'second'), payoff=lambda s, k: k, rate=0.5
... )
>>> reinforcement.rate
0.5
>>> PayoffLearningInteraction(
... 'virtual', target='players', scores='scores', payoff=lambda a, m, k: k, rule='cumulative',
... schedule='synchronous',
... ).rule
'cumulative'
>>> PayoffLearningInteraction(
... 'satisfaction', target='customers', scores=('s1', 's2'), payoff=lambda a, m, k: 1.0, chosen='shop',
... schedule='member',
... ).chosen
'shop'
Source code in src/skcomplex/systems/economics/common/learning/_payoff_learning.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
update(system)
Move the scores of every agent by the schedule.
Under 'synchronous' every agent reads the scores at the start of the rule, and otherwise the agents move one
after the other, in their order or in a new random order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemViewProtocol
|
The system view of the learning. |
required |
Source code in src/skcomplex/systems/economics/common/learning/_payoff_learning.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |