decent_bench.agent#
- class decent_bench.agent.Agent(agent_id: int, cost_function: CostFunction, activation_scheme: AgentActivationScheme)[source]#
Bases:
objectAgent with unique id, local cost function, and activation scheme.
- property cost_function: CostFunction#
Local cost function.
- property x: ndarray[tuple[Any, ...], dtype[float64]]#
Local optimization variable x.
- Raises:
RuntimeError – if x is retrieved before being set or initialized
- property received_messages: Mapping[Agent, ndarray[tuple[Any, ...], dtype[float64]]]#
Messages received by neighbors.
- property aux_vars: dict[str, ndarray[tuple[Any, ...], dtype[float64]]]#
Auxiliary optimization variables used by algorithms that require more variables than x.
- initialize(*, x: ndarray[tuple[Any, ...], dtype[float64]] | None = None, aux_vars: dict[str, ndarray[tuple[Any, ...], dtype[float64]]] | None = None, received_msgs: dict[Agent, ndarray[tuple[Any, ...], dtype[float64]]] | None = None) None[source]#
Initialize local variables and messages before running an algorithm.
- Parameters:
x – initial x
aux_vars – initial auxiliary variables
received_msgs – initial messages from neighbors
- class decent_bench.agent.AgentMetricsView(cost_function: CostFunction, x_per_iteration: list[ndarray[tuple[Any, ...], dtype[float64]]], n_evaluate_calls: int, n_gradient_calls: int, n_hessian_calls: int, n_proximal_calls: int, n_sent_messages: int, n_received_messages: int, n_sent_messages_dropped: int)[source]#
Bases:
objectImmutable view of agent that exposes useful properties for calculating metrics.
- cost_function: CostFunction#
- static from_agent(agent: Agent) AgentMetricsView[source]#
Create from agent.