Actors List
Bases: List[Link]
, Generic[Link]
A list of actors in an agent-based model.
Source code in abses/sequences.py
to_dict ¶
Convert all actors in this list to a dictionary like {breed: ActorList}.
Returns:
Type | Description |
---|---|
Dict[str, ActorsList[Link]]
|
key is the breed of actors, and values are corresponding actors. |
Source code in abses/sequences.py
select ¶
Returns a new :class:ActorList
based on selection
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection |
Optional[Selection]
|
List with same length as the agent list. Positions that return True will be selected. |
None
|
geo_type |
Optional[GeoType]
|
Type of Actors' Geometry. |
None
|
Returns:
Type | Description |
---|---|
ActorsList[Link]
|
A subset containing. |
Source code in abses/sequences.py
ids ¶
Subsets ActorsList by a ids
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
Iterable[UniqueID] | UniqueID
|
an iterable id list. List[id], ID is an attr of agent obj. |
required |
Returns:
Name | Type | Description |
---|---|---|
ActorList |
ActorsList[Link]
|
A subset of origin agents list. |
Source code in abses/sequences.py
better ¶
Selects the elements of the sequence that are better than a given value or actor based on a specified metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
str
|
The name of the attribute to use as the metric for comparison. |
required |
than |
Optional[Union[Number, Actor]]
|
The value or actor to compare against. If None, selects the elements with the highest value for the specified metric. If a number, selects the elements with a value greater than the specified number. If an Actor, selects the elements with a value greater than the specified Actor's value for the specified metric. |
None
|
Returns:
Type | Description |
---|---|
ActorsList[Link]
|
A new sequence containing the selected elements. |
Raises:
Type | Description |
---|---|
ABSESpyError
|
If the |
Notes
This method compares the values of the specified metric for all elements in the sequence and selects the elements that are better than the specified value or actor. The comparison is based on the greater than operator (>) for numbers and the difference between the values for actors.
Source code in abses/sequences.py
update ¶
Update the specified attribute of each agent in the sequence with the corresponding value in the given iterable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The name of the attribute to update. |
required |
values |
Iterable[Any]
|
An iterable of values to update the attribute with. Must be the same length as the sequence. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the length of the values iterable does not match the length of the sequence. |
Source code in abses/sequences.py
split ¶
Split agents into N+1 groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
NDArray[Any]
|
indexes [size=N] denotes where to split. |
required |
Returns:
Type | Description |
---|---|
List[ActorsList[Link]]
|
np.ndarray: N+1 groups: agents array |
Source code in abses/sequences.py
array ¶
Convert the specified attribute of all actors to a numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The name of the attribute to convert to a numpy array. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
A numpy array containing the specified attribute of all actors. |
Source code in abses/sequences.py
trigger ¶
Call a method with the given name on all actors in the sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func_name |
str
|
The name of the method to call on each actor. |
required |
*args |
Any
|
Positional arguments to pass to the method. |
()
|
**kwargs |
Any
|
Keyword arguments to pass to the method. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
An array of the results of calling the method on each actor. |
Source code in abses/sequences.py
apply ¶
Apply ufunc to all actors in the sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ufunc |
Callable
|
The function to apply to each actor. |
required |
*args |
Any
|
Positional arguments to pass to the function. |
()
|
**kwargs |
Any
|
Keyword arguments to pass to the function. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
An array of the results of applying the function to each actor. |
Source code in abses/sequences.py
get ¶
Retrieve the attribute of an either specified or randomly chosen agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The name of the attribute to retrieve. |
required |
how |
HOW
|
The method to use to retrieve the attribute. Can be either "only" or "random". |
'only'
|
Returns:
Type | Description |
---|---|
Any
|
The attribute of the specified agent. |
Source code in abses/sequences.py
set ¶
Set the attribute of all agents in the sequence to the specified value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The name of the attribute to set. |
required |
value |
Any
|
The value to set the attribute to. |
required |
Source code in abses/sequences.py
item ¶
Retrieve one agent if possible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
how |
HOW
|
The method to use to retrieve the agent. Can be either "only", "item", or "random". If "only", it will return the only agent in the container. In this case, the container must have only one agent. If more than one or no agent is found, it will raise an error. If "item", it will return the agent at the given index. If "random", it will return a randomly chosen agent. |
'item'
|
index |
int
|
The index of the agent to retrieve. |
0
|
Returns:
Type | Description |
---|---|
Optional[Link]
|
The agent if found, otherwise None. |
Source code in abses/sequences.py
summary ¶
Returns a summarized dataframe of the actors.