Constructor
AgentModel()
Initializes the model with default parameters and no graph.
| Key | Value |
|---|---|
num_nodes | 3 |
graph_type | "complete" |
convergence_data_key | None |
convergence_std_dev | 100 |
Parameters
update_parameters(parameters)
Merges parameters into the model’s internal parameter store. Adds new keys and overwrites existing ones.
Args:
parameters(dict) — Key-value pairs to update.
delete_parameters(parameters=None)
Deletes custom parameter keys. If called with no arguments, resets the parameter store to its defaults.
Args:
parameters(list, optional) — List of parameter keys to delete. Defaults toNone.
True on success.
Raises: KeyError if a key is one of the four default parameters or does not exist.
list_parameters()
Returns a list of all current parameter keys.
Returns: list
model[key] / model[key] = value
Dictionary-style access for reading and setting individual parameters.
Graph
set_graph(graph)
Replaces the model’s internal graph with the provided NetworkX graph.
Args:
graph(nx.Graph) — A NetworkX graph object.
Exception if the argument is not a NetworkX graph.
get_graph()
Returns the model’s current NetworkX graph.
Returns: nx.Graph
The returned graph is the live internal object — mutations affect the model’s state directly.
Simulation setup
set_initial_data_function(initial_data_function)
Registers the function used to generate starting data for each node.
Args:
initial_data_function(Callable) — A function(model) -> dict.
set_timestep_function(timestep_function)
Registers the function called each timestep.
Args:
timestep_function(Callable) — A function(model) -> None.
initialize_graph()
Creates the graph topology (based on graph_type and num_nodes) and populates every node by calling initial_data_function.
Raises: Exception if initial_data_function is not set.
Running the simulation
timestep()
Executes one timestep by calling timestep_function(model).
Raises: Exception if timestep_function is not set.
run_to_convergence()
Repeatedly calls timestep() until convergence is detected or MAX_TIMESTEPS is reached.
Returns: int — The timestep at which the model converged.
Raises: Exception if convergence_data_key is not set.
is_converged(data_key, std_dev)
Checks whether the standard deviation of a node attribute is at or below a threshold.
Args:
data_key(str) — Node data key to evaluate.std_dev(float) — Convergence threshold.
bool
change_max_timesteps(timesteps)
Sets the upper bound on iterations for run_to_convergence(). Default is 100,000.
Args:
timesteps(int) — New maximum.