Types
Define the types of the core, such as targets of laws and agent protocols.
AgentViewProtocol
Bases: Protocol
A protocol of an agent as the agent rules of an interaction see it.
An agent rule is a Python function rule(agent, system) that runs for each member of a group at each step, and the
agent it receives gives its id, its group, its place, its neighbours, and its values, and lets the rule move it,
remove it, or create new agents, such as agent.move_to(cell). Values are plain attributes, such as agent.x, and
a primed value is read with agent.get_value("x'"). It describes a trader in a market, an animal in a flock, and a
voter in a network.
Read more in the user guide, under Agents.
See Also
SystemViewProtocol: The system as agent rules see it. UpdateLaw: Runs an agent rule.
Examples:
>>> from skcomplex.core.components.types import AgentViewProtocol
>>> hasattr(AgentViewProtocol, 'move_to'), hasattr(AgentViewProtocol, 'get_neighbors')
(True, True)
alive
property
Whether the agent has not been removed.
group
property
Path of the group of the agent.
group_label
property
Label of the agent's group, the last part of its path.
id
property
Unique id of the agent.
location
property
Grid coordinates, network node, or position of the agent.
location_key
property
Location of the agent as a key.
It equals the coordinates neighbor_cells gives for its cell or node.
create(group=None, location=None, **values)
Create an agent of a group.
By default it is the agent's own group at the agent's location.
Source code in src/skcomplex/core/components/types.py
126 127 128 129 130 | |
get_agents_here(group=None)
Return the other agents of the agent's cell or node.
They are of every group or of the group of a path.
Source code in src/skcomplex/core/components/types.py
84 85 86 87 88 | |
get_displacement_to(other)
Return the vector from the agent to another agent or a location.
On a torus it is the shortest one.
Source code in src/skcomplex/core/components/types.py
90 91 92 93 94 | |
get_distance_to(other)
Return the distance to another agent or a location.
On a network it is the number of hops.
Source code in src/skcomplex/core/components/types.py
96 97 98 99 100 | |
get_lags(state, window=None)
Return the past values of a state of the agent at the ends of the last steps.
The last one comes last.
Source code in src/skcomplex/core/components/types.py
138 139 140 141 142 | |
get_neighbor_cells()
Return the coordinates of the cells or nodes around the agent's cell or node.
They are hashable as location keys.
Source code in src/skcomplex/core/components/types.py
78 79 80 81 82 | |
get_neighbors(radius=None, layer=None, group=None, over=None)
Return the other agents in the neighbouring cells or nodes, or nearby in space.
They are of every group or of the group of a path.
Source code in src/skcomplex/core/components/types.py
102 103 104 105 106 107 108 109 110 111 112 | |
get_referenced(state)
Return the member of another group that a reference state of the agent names.
The result is None when there is none.
Source code in src/skcomplex/core/components/types.py
132 133 134 135 136 | |
get_regions_here(layer)
Return the indices of the regions of a continuous space layer with the agent.
Source code in src/skcomplex/core/components/types.py
114 115 | |
get_value(name)
Return a value of the agent by the name users read, such as x'.
Source code in src/skcomplex/core/components/types.py
144 145 | |
move_to(location)
Move the agent to a cell, a node, or a position.
It can also move to a uniform point inside a polygon.
Source code in src/skcomplex/core/components/types.py
117 118 119 120 121 | |
remove()
Remove the agent from the system.
Source code in src/skcomplex/core/components/types.py
123 124 | |
set_value(name, value)
Set a state of the agent by the name users read, such as x'.
Source code in src/skcomplex/core/components/types.py
147 148 | |
SystemViewProtocol
Bases: Protocol
A protocol of a system as the agent rules of an interaction see it.
An agent rule is a Python function rule(agent, system), and the system it receives gives the agents of every
group, the random numbers of the run, a storage that lasts the whole run, the parameters, the time, and the fields
of a space, such as system.get_agents('sheep') or system.rng.random(). It describes the market of the traders,
the pasture of a flock, and the network of the voters.
Read more in the user guide, under Agents.
See Also
AgentViewProtocol: An agent as agent rules see it. UpdateLaw: Runs an agent rule.
Examples:
>>> from skcomplex.core.components.types import SystemViewProtocol
>>> hasattr(SystemViewProtocol, 'get_agents'), hasattr(SystemViewProtocol, 'rng')
(True, True)
dimensions
property
Extent of the agent space per axis.
It counts cells of a lattice or lengths of a continuous space, and is None otherwise.
inputs
property
Values of the states of other partitions at the last synchronisation point.
They are keyed by dotted name.
parameters
property
Current values of every parameter by dotted name.
rng
property
Random number generator of the system.
round
property
Index of the current round of a repeated phase, 0 outside repeated phases.
storage
property
Mutable mapping private to the owner of the rule.
It persists across the steps of one run.
time
property
Time of the system.
It includes the fraction of the step that the visits of a phase reached.
torus
property
Whether the agent space wraps around at its edges.
count(name)
Return the number of agents of a group, a role of the owner or a path.
Source code in src/skcomplex/core/components/types.py
237 238 | |
create(group, location=None, **values)
Create an agent of a group, a role of the owner or a path.
It is created at a location, or by default at a random place.
Source code in src/skcomplex/core/components/types.py
261 262 263 264 265 | |
deposit(name, cell, amount)
Add an amount to a field state at a cell or node.
The state is given by path or as <role>.<state>.
Source code in src/skcomplex/core/components/types.py
255 256 257 258 259 | |
draw(name, distribution, **arguments)
Return a value drawn by name from a distribution, which runs record and replay.
The distribution is 'uniform' with low and high, 'normal' with mean and deviation, 'bernoulli'
with p, 'categorical' with weights, or a scipy.stats distribution with its keywords.
Source code in src/skcomplex/core/components/types.py
176 177 178 179 180 181 | |
get_agents(name)
Return the agents of a group bound to a role of the owner or of a group by path.
Source code in src/skcomplex/core/components/types.py
190 191 | |
get_composition(name, state)
Return the number of agents by value of a state.
The agents are those of a group, a role of the owner or a path.
Source code in src/skcomplex/core/components/types.py
280 281 282 283 284 | |
get_field(name, cell)
Return the value of a field state at a cell or node.
The state is given by path or as <role>.<state>.
Source code in src/skcomplex/core/components/types.py
249 250 251 252 253 | |
get_groups(name)
Return the paths of the groups a role of the owner binds, or of a group by path.
Source code in src/skcomplex/core/components/types.py
204 205 | |
get_history(name, window=None)
Return the past values of a reporter or of an observable.
The values of an observable are those at the end of every earlier step.
Source code in src/skcomplex/core/components/types.py
274 275 276 277 278 | |
get_observable(name)
Return the current value of an observable of the system.
An example is an aggregate of a group.
Source code in src/skcomplex/core/components/types.py
243 244 245 246 247 | |
get_occupancy(name)
Return the number of agents by the key of their location.
The agents are those of a group, a role of the owner or a path.
Source code in src/skcomplex/core/components/types.py
286 287 288 289 290 | |
get_parameter(name)
Return the current value of a parameter of the owner.
Source code in src/skcomplex/core/components/types.py
213 214 | |
get_random_empty_cell()
Return the coordinates of a random empty cell of the grid or network.
Source code in src/skcomplex/core/components/types.py
240 241 | |
get_region(layer, index)
Return the polygon of a region of a layer of the continuous space.
Source code in src/skcomplex/core/components/types.py
210 211 | |
get_regions(layer)
Return the number of regions of a layer of the continuous space.
Source code in src/skcomplex/core/components/types.py
207 208 | |
report(name, value)
Publish a value of the owner as the reporter <owner>.<name>.
Source code in src/skcomplex/core/components/types.py
292 293 | |
set_parameter(name, value)
Set a parameter of any group or interaction during the run.
The change is recorded in the trajectory.
Source code in src/skcomplex/core/components/types.py
220 221 222 223 224 | |