Consensus Algorithms

Consensus

class disropt.algorithms.consensus.Consensus(agent, initial_condition, enable_log=False)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Consensus Algorithm [OlSa07]

From the perspective of agent \(i\) the algorithm works as follows. For \(k=0,1,\dots\)

\[x_i^{k+1} = \sum_{j=1}^N w_{ij} x_j^k\]

where \(x_i\in\mathbb{R}^n\). The weight matrix \(W=[w_{ij}]\) should be doubly-stochastic in order to have convergence to the average of the local initial conditions. If \(W\) is row-stochastic convergence is still attained but at a different point. Other type of matrices can be used, but convergence is not guaranteed. Also time-varying graphs can be adopted.

Parameters
  • agent (Agent) – agent to execute the algorithm

  • initial_condition (numpy.ndarray) – initial condition

  • enable_log (bool) – True for enabling log

agent

agent to execute the algorithm

Type

Agent

x0

initial condition

Type

numpy.ndarray

x

current value of the local solution

Type

numpy.ndarray

shape

shape of the variable

Type

tuple

x_neigh

dictionary containing the local solution of the (in-)neighbors

Type

dict

enable_log

True for enabling log

Type

bool

get_result()[source]

Return the actual value of x

Returns

value of x

Return type

numpy.ndarray

iterate_run(**kwargs)[source]

Run a single iterate of the algorithm

run(iterations=100, verbose=False, **kwargs)[source]

Run the algorithm for a given number of iterations

Parameters
  • iterations (int) – Number of iterations. Defaults to 100.

  • verbose (bool) – If True print some information during the evolution of the algorithm. Defaults to False.

AsynchronousConsensus

class disropt.algorithms.consensus.AsynchronousConsensus(agent, initial_condition, enable_log=False, force_sleep=False, maximum_sleep=0.01, sleep_type='random', force_computation_time=False, maximum_computation_time=0.01, computation_time_type='random', force_unreliable_links=False, link_failure_probability=0)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Asynchronous Consensus Algorithm

From the perspective of agent \(i\) the algorithm works as follows. When agent \(i\) gets awake it updates its local solution as

\[x_i \gets \sum_{j\in\mathcal{N}_i} w_{ij} x_{j\mid i}\]

where \(\mathcal{N}_i\) is the current set of in-neighbors and \(x_{j\mid i},j\in\mathcal{N}_i\) is the local copy of \(x_j\) available at node \(i\) (which can be outdated, due to asynchrony, computation time and link failures).

Parameters
  • agent (Agent) – agent to execute the algorithm

  • initial_condition (ndarray) – initial condition

  • enable_log (bool) – True for enabling log. Defaults to False.

  • force_sleep (bool) – True if one wanst to force sleep after the computation phase. Defaults to False.

  • maximum_sleep (float) – Maximum allowed sleep. Defaults to 0.01.

  • sleep_type (str) – Type of sleep time(“constant”, “random”). Defaults to “random”.

  • force_computation_time (bool) – True if one want sto force length computation phase. Defaults to False.

  • maximum_computation_time (float) – Maximum allowed computation time. Defaults to 0.01.

  • computation_time_type (str) – Type of computation time (“constant”, “random”). Defaults to “random”.

  • force_unreliable_links (bool) – True if one wants to force unreliable links. Defaults to False.

  • link_failure_probability (float) – Probability of incoming links failure. Defaults to 0.

agent

agent to execute the algorithm

Type

Agent

x0

initial condition

Type

numpy.ndarray

x

current value of the local solution

Type

numpy.ndarray

shape

shape of the variable

Type

tuple

x_neigh

dictionary containing the local solution of the (in-)neighbors

Type

dict

enable_log

True for enabling log

Type

bool

timestamp_sequence_awake

list of timestamps at which node get awake

Type

list

timestamp_sequence_sleep

list of timestamps at which node go to sleep

Type

list

force_sleep

True if one wanst to force sleep after the computation phase. Defaults to False.

maximum_sleep

Maximum allowed sleep. Defaults to 0.01.

sleep_type

Type of sleep time(“constant”, “random”). Defaults to “random”.

force_computation_time

True if one want sto force length computation phase. Defaults to False.

maximum_computation_time

Maximum allowed computation time. Defaults to 0.01.

computation_time_type

Type of computation time (“constant”, “random”). Defaults to “random”.

True if one wants to force unreliable links. Defaults to False.

Probability of incoming links failure. Defaults to 0.

get_result()[source]

Return the actual value of x

Returns

value of x

Return type

numpy.ndarray

iterate_run(**kwargs)[source]

Run a single iterate

run(running_time=5.0)[source]

Run the asynchronous consensus algorithm for a certain amount of time

Parameters

running_time (float) – Total run time. Defaults to 5.0.

Returns

timestamp_sequence_awake, timestamp_sequence_sleep, sequence

Return type

tuple

BlockConsensus

class disropt.algorithms.consensus.BlockConsensus(agent, initial_condition, enable_log=False, blocks_list=None, probabilities=None, awakening_probability=1.0)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Block-wise consensus [FaNo19]

At each iteration, the agent can update its local estimate or not at each iteration according to a certain probability (awakening_probability). From the perspective of agent \(i\) the algorithm works as follows. At iteration \(k\) if the agent is awake, it selects a random block \(\ell_i^k\) of its local solution and updates

\[\begin{split}x_{i,\ell}^{k+1} = \begin{cases} \sum_{j\in\mathcal{N}_i} w_{ij} x_{j\mid i,\ell}^k & \text{if} \ell = \ell_i^k \\ x_{i,\ell}^{k} & \text{otherwise} \end{cases}\end{split}\]

where \(\mathcal{N}_i\) is the current set of in-neighbors and \(x_{j\mid i},j\in\mathcal{N}_i\) is the local copy of \(x_j\) available at node \(i\) and \(x_{i,\ell}\) denotes the \(\ell\)-th block of \(x_i\). Otherwise \(x_{i}^{k+1}=x_i^k\).

Parameters
  • agent (Agent) – agent to execute the algorithm

  • initial_condition (ndarray) – initial condition

  • enable_log (bool) – True for enabling log

  • blocks_list (Optional[List[Tuple]]) – the list of blocks (list of tuples)

  • probabilities (Optional[List[float]]) – list of probabilities of drawing each block

  • awakening_probability (float) – probability of getting awake at each iteration

get_result()[source]

Return the actual value of x

Returns

value of x

Return type

numpy.ndarray

iterate_run(**kwargs)[source]

Run a single iterate of the algorithm

run(iterations=100, verbose=False)[source]

Run the algorithm for a given number of iterations

Parameters
  • iterations (int) – Number of iterations. Defaults to 100.

  • verbose (bool) – If True print some information during the evolution of the algorithm. Defaults to False.

PushSumConsensus

class disropt.algorithms.consensus.PushSumConsensus(agent, initial_condition, enable_log=False)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Push-Sum Consensus Algorithm

From the perspective of agent \(i\) the algorithm works as follows. For \(k=0,1,\dots\)

\[ \begin{align}\begin{aligned}x_i^{k+1} &= \sum_{j=1}^N w_{ij} x_j^k\\y_i^{k+1} &= \sum_{j=1}^N w_{ij} y_j^k\\z_i^{k+1} &= \frac{x_i^{k+1}}{y_i^{k+1}}\end{aligned}\end{align} \]

where \(x_i\in\mathbb{R}^n\). The weight matrix \(W=[w_{ij}]\) should be column-stochastic in order to let \(z_i^k\) converge to the average of the local initial conditions. Also time-varying graphs can be adopted.

Parameters
  • agent (Agent) – agent to execute the algorithm

  • initial_condition (numpy.ndarray) – initial condition

  • enable_log (bool) – True for enabling log

agent

agent to execute the algorithm

Type

Agent

z0

initial condition

Type

numpy.ndarray

z

current value of the local solution

Type

numpy.ndarray

shape

shape of the variable

Type

tuple

x_neigh

dictionary containing the x values of the (in-)neighbors

Type

dict

y_neigh

dictionary containing the y values of the (in-)neighbors

Type

dict

enable_log

True for enabling log

Type

bool

get_result()[source]

Return the actual value of x

Returns

value of x

Return type

numpy.ndarray

iterate_run(**kwargs)[source]

Run a single iterate of the algorithm

run(iterations=100, verbose=False, **kwargs)[source]

Run the algorithm for a given number of iterations

Parameters
  • iterations (int) – Number of iterations. Defaults to 100.

  • verbose (bool) – If True print some information during the evolution of the algorithm. Defaults to False.

References

OlSa07

Olfati-Saber, Reza; J. Alex Fax; and Richard M. Murray: Consensus and cooperation in networked multi-agent systems: Proceedings of the IEEE 95.1 (2007): 215-233.