LVState#
- class graph_tool.dynamics.LVState(g, w=1, r=1, sigma=0, mig=0, t0=0, s=None)[source]#
Bases:
ContinuousStateBase
Generalized Lotka-Volterra model.
- Parameters:
- g
Graph
Graph to be used for the dynamics
- w
EdgePropertyMap
orfloat
(optional, default:1
) Coupling strength of each edge. If a scalar is given, it will be used for all edges.
- r
VertexPropertyMap
orfloat
(optional, default:1
) Intrinsic birth or death rates. If a scalar is given, it will be used for all nodes.
- sigma
float
(optional, default:.0
) Stochastic noise magnitude.
- s
VertexPropertyMap
(optional, default:None
) Initial global state. If not provided, a random state will be chosen.
- g
Notes
This implements a generalized Lotka-Volterra (gLV) dynamical system with demographic noise, i.e. each node has an 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 noise with zero mean and unit variance (implemented according to the Itô definition).
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")
Methods
copy
()Return a copy of the state.
get_diff
(dt)Returns the current time derivative for all the nodes.
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 o time
t
using a simple Euler's method with step sizedt
.- copy()#
Return a copy of the state.
- get_diff(dt)#
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.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()#
Returns the internal
VertexPropertyMap
with the current state.
- solve(t, *args, **kwargs)#
Integrate the system up to time
t
. The remaining parameters are passed toscipy.integrate.solve_ivp()
. This solver is not suitable for stochastic ODEs.
- solve_euler(t, dt=0.001)#
Integrate the system up o time
t
using a simple Euler’s method with step sizedt
. This solver is suitable for stochastic ODEs.