KirmanState#

class graph_tool.dynamics.KirmanState(g, d=0.1, c1=0.001, c2=0.001, s=None)[source]#

Bases: DiscreteStateBase

Kirman’s “ant colony” model.

Parameters:
gGraph

Graph to be used for the dynamics

dfloat (optional, default: .1)

Strategy infection probability.

c1float (optional, default: .001)

Spontaneous transition probability to first strategy.

c2float (optional, default: .001)

Spontaneous transition probability to second strategy.

sVertexPropertyMap (optional, default: None)

Initial global state. If not provided, a random state will be chosen.

Notes

This implements Kirman’s “ant colony” model [kirman_ants_1993] on a network.

If a node \(i\) is updated at time \(t\), the transition to state \(s_i(t+1) \in \{0,1\}\) is done as follows:

  1. If \(s_i(t) = 0\), we have \(s_i(t) = 1\) with probability \(c_1\).

  2. Otherwise if \(s_i(t) = 1\), we have \(s_i(t) = 0\) with probability \(c_2\).

  3. Otherwise we have \(s_i(t+1) = 1 - s_i(t)\) with probability

    \[1 - (1-d)^{\sum_jA_{ij}(1-\delta_{s_i(t), s_j(t)})}\]
  4. Otherwise we have \(s_i(t+1) = s_i(t)\).

References

[kirman_ants_1993]

A. Kirman, “Ants, Rationality, and Recruitment”, The Quarterly Journal of Economics 108, 137 (1993), DOI: 10.2307/2118498 [sci-hub, @tor].

Examples

>>> g = gt.GraphView(gt.collection.data["polblogs"].copy(), directed=False)
>>> gt.remove_parallel_edges(g)
>>> g = gt.extract_largest_component(g, prune=True)
>>> state = gt.KirmanState(g)
>>> ret = state.iterate_sync(niter=1000)
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=state.s,
...               output="kirman.svg")
<...>
../_images/kirman.svg

State of Kirman’s model on a political blog network.#

Methods

copy()

Return a copy of the state.

get_active()

Returns list of "active" nodes, for states where this concept is used.

get_state()

Returns the internal VertexPropertyMap with the current state.

iterate_async([niter])

Updates nodes asynchronously (i.e. single vertex chosen randomly), niter number of times.

iterate_sync([niter])

Updates nodes synchronously (i.e. a full "sweep" of all nodes in parallel), niter number of times.

reset_active()

Resets list of "active" nodes, for states where this concept is used.

set_active(active)

Sets the list of "active" nodes, for states where this concept is used.

copy()#

Return a copy of the state.

get_active()#

Returns list of “active” nodes, for states where this concept is used.

get_state()#

Returns the internal VertexPropertyMap with the current state.

iterate_async(niter=1)#

Updates nodes asynchronously (i.e. single vertex chosen randomly), niter number of times. This function returns the number of nodes that changed state.

iterate_sync(niter=1)#

Updates nodes synchronously (i.e. a full “sweep” of all nodes in parallel), niter number of times. This function returns the number of nodes that changed state.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

reset_active()#

Resets list of “active” nodes, for states where this concept is used.

set_active(active)#

Sets the list of “active” nodes, for states where this concept is used.