LVState#

class graph_tool.dynamics.LVState(g, w=1, r=1, sigma=0, mig=0, t0=0, s=None)[git][source]#

Bases: ContinuousStateBase

Generalized Lotka-Volterra model.

Parameters:
gGraph

Graph to be used for the dynamics

wEdgePropertyMap or float (optional, default: 1)

Coupling strength of each edge. If a scalar is given, it will be used for all edges.

rVertexPropertyMap or float (optional, default: 1)

Intrinsic birth or death rates. If a scalar is given, it will be used for all nodes.

sigmafloat (optional, default: .0)

Stochastic noise magnitude.

migVertexPropertyMap or float (optional, default: 0)

Constant migration rate, added to the time derivative of each node. If a scalar is given, it will be used for all nodes.

t0float (optional, default: 0)

Initial time.

sVertexPropertyMap (optional, default: None)

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

Notes

This implements a generalized Lotka-Volterra (gLV) dynamical system with demographic noise, i.e. each node has a variable \(s_i\), which evolves in time obeying the differential equation:

\[\frac{\mathrm{d}s_i}{\mathrm{d}t} = s_i\left(r_i + \sum_{j}A_{ij}w_{ij}s_j\right) + \sigma\sqrt{s_i}\xi_i(t),\]

where \(\xi_i(t)\) is a Gaussian white noise with zero mean and unit variance per unit time, i.e. \(\left<\xi_i(t)\xi_j(t')\right> = \delta_{ij}\delta(t-t')\) (implemented according to the Itô definition). The noise is only taken into account by solve_euler(), not by solve().

References

Examples

>>> g = gt.collection.data["karate"].copy()
>>> s = g.new_vp("double", vals=1 + 10 * np.random.random(g.num_vertices()))
>>> r = g.new_vp("double", val=-1)
>>> w = g.new_ep("double", vals=np.random.normal(0, .5, g.num_edges()))
>>> for v in g.vertices():
...     e = g.add_edge(v,v)
...     w[e] = -.7
>>> state = gt.LVState(g, s=s, r=r, w=w)
>>> ss = []
>>> ts = linspace(0, .4, 1000)
>>> for t in ts:
...     ret = state.solve(t, first_step=1e-6)
...     ss.append(state.get_state().fa.copy())
>>> figure(figsize=(6, 4))
<...>
>>> for v in g.vertices():
...    plot(ts, [s[int(v)] for s in ss])
[...]
>>> xlabel(r"Time")
Text(...)
>>> ylabel(r"$s_i$")
Text(...)
>>> tight_layout()
>>> savefig("karate-glv.svg")
../_images/karate-glv.svg

gLV dynamics on the Karate Club network.#

Methods

copy()

Return a copy of the state.

get_diff(dt)

Returns the current time derivative for all the nodes.

get_state()

Returns the internal VertexPropertyMap with the current state.

solve(t, *args, **kwargs)

Integrate the system up to time t.

solve_euler(t[, dt])

Integrate the system up to time t using a simple Euler's method (Euler-Maruyama for the noise terms) with step size dt.

copy()[git]#

Return a copy of the state.

get_diff(dt)[git]#

Returns the current time derivative for all the nodes. The parameter dt is the time interval in consideration, which is used only if the ODE has a stochastic component: if dt > 0, the noise term of each node is sampled with variance \(1/\mathrm{dt}\), so that the increment over the interval has variance proportional to dt, and if dt == 0 the noise term is omitted.

The returned array is a view of an internal buffer, which is overwritten by the next call.

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.

get_state()[git]#

Returns the internal VertexPropertyMap with the current state.

solve(t, *args, **kwargs)[git]#

Integrate the system up to time t. The remaining parameters are passed to scipy.integrate.solve_ivp(). This solver is not suitable for stochastic ODEs, since the noise terms are omitted.

solve_euler(t, dt=0.001)[git]#

Integrate the system up to time t using a simple Euler’s method (Euler-Maruyama for the noise terms) with step size dt. This solver is suitable for stochastic ODEs.

If the interval is not a multiple of dt, the step size is reduced to the nearest value that divides it evenly, so that the integration ends exactly at time t.