LinearState#
- class graph_tool.dynamics.LinearState(g, w=1, sigma=0, t0=0, s=None)[source]#
Bases:
ContinuousStateBase
Linear dynamical system with noise.
- 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.
- 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 linear dynamical system with 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} = \sum_{j}A_{ij}w_{ij}s_j + \sigma\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", np.random.normal(0, 1, g.num_vertices())) >>> w = g.new_ep("double", vals=np.random.normal(0, .1, g.num_edges())) >>> state = gt.LinearState(g, s=s, w=w) >>> ss = [] >>> ts = linspace(0, 10, 1000) >>> for t in ts: ... ret = state.solve(t, first_step=0.0001) ... 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-linear.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.