Skip to main content

Constructor

AgentModel()

Initializes the model with default parameters and no graph.
Default parameters on initialization:

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 to None.
Returns: 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.
Raises: 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.
Call initialize_graph() after setting all parameters and your initial data function. If using a custom graph via set_graph(), call set_graph() first — initialize_graph() will populate node data without rebuilding the topology.

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.
Returns: bool

change_max_timesteps(timesteps)

Sets the upper bound on iterations for run_to_convergence(). Default is 100,000. Args:
  • timesteps (int) — New maximum.