@@ -72,7 +72,7 @@ y^{\mathrm e}_{\mathrm{src}} &= g_\mathrm{src}^{\mathrm e}(u^{\mathrm e}, y^{\ma
72
72
## Modelling dynamics in NetworkDynamics.jl
73
73
To model the vertex and edge dynamics we need to create a `VertexModel` and an `EdgeModel`, respectively.
74
74
75
- As a first step we need to install Julia and the necessary packages (`Graphs`, NetworkDynamics`, `OrdinaryDiffEqTsit5`,
75
+ As a first step we need to install Julia and the necessary packages (`Graphs`, ` NetworkDynamics`, `OrdinaryDiffEqTsit5`,
76
76
`StableRNGs` and `Plots`). Then we need to load them:
77
77
=#
78
78
@@ -137,7 +137,7 @@ nothing #hide #md
137
137
Just like above, the input arguments `v, esum, p, t` are mandatory for the syntax of vertex functions. The additional
138
138
input `dv` corresponding to the derivative of the vertex' state is mandatory for vertices described by ordinary
139
139
differential equations. The outputs of the vertex function are just a subset of the internal states. Therefore, we
140
- can use the [`StateMask`](@ref) helper function `g = StateMaks (1:1)` to access them.
140
+ can use the [`StateMask`](@ref) helper function `g = StateMask (1:1)` to access them.
141
141
=#
142
142
143
143
nd_diffusion_vertex = VertexModel (; f= diffusionvertex_f!, g= StateMask (1 : 1 ), dim= 1 )
@@ -180,23 +180,25 @@ ode_prob = ODEProblem(nd, x0, (0.0, 2.0))
180
180
# We test all ex styles #src
181
181
Main. test_execution_styles (ode_prob) # src
182
182
183
- # And then solve the network using ´ solve´ :
183
+ # And then solve the network using ` solve` :
184
184
sol = solve (ode_prob, Tsit5 ());
185
185
nothing # hide #md
186
186
187
187
#=
188
- We plot the results using the `plot` command, which takes three parameters as input `sol`, `idxs` and `fmt `.
188
+ We plot the results using the `plot` command, which takes two parameters as input `sol` and `idxs `.
189
189
The first parameter is the solved network `sol`.
190
190
The second parameter is `idxs`, which provides a set of indices. We can use "symbolic" indices, which specify specific
191
191
components and their symbols directly (see [Symbolic Indexing](@ref) for more details). In order to collect multiple
192
192
indices we can use the helper function [`vidxs`](@ref) and [`eidxs`](@ref), which help us collect all symbolic indices
193
- matching specific criteria. The third and last parameter is `fmt`, which provides the format of the generated plot, in
194
- this case that format being .png .
193
+ matching specific criteria.
194
+ Here, we want to plot **all** vertex states from the network .
195
195
=#
196
- plot (sol; idxs= vidxs (nd, :, :), fmt = :png )
196
+ plot (sol; idxs= vidxs (nd, :, :))
197
197
198
198
#=
199
- (@Hans can you provide a description of what we see in this plot? The y axis is missing so it is unclear to me.)
199
+ In the plot we see, how the individual vertex states evolve over time.
200
+ We start at a random configuration, and then develop towards an equilibrium where
201
+ all nodes have the same state, which is to be expected for a simple diffusion process.
200
202
201
203
## Two Dimensional Extension
202
204
@@ -218,38 +220,30 @@ nd_diffusion_vertex_2 = VertexModel(; f=diffusionvertex_f!, g=1:2, dim=2, sym=[:
218
220
nd_diffusion_edge_2 = EdgeModel (; g= AntiSymmetric (diffusionedge_g!), outsym= [:flow_x , :flow_ϕ ])
219
221
nd_2 = Network (g, nd_diffusion_vertex_2, nd_diffusion_edge_2)
220
222
221
- #= We define the first diffusion as x ~ $N(0,1)^\mathrm{2}$ and the second diffusion as ϕ ~ $N(0,1)$. So the propagation
223
+ #=
224
+ We define the first diffusion as x ~ $N(0,1)^\mathrm{2}$ and the second diffusion as ϕ ~ $N(0,1)$. So the propagation
222
225
of the diffusion from node 0 to node 2 is given by creating a vector:
223
226
=#
224
227
x0_2 = vec (transpose ([randn (rng, N) .^ 2 randn (rng, N)]))
225
- # (@Hans: is my explanation correct?)
226
228
227
- # We then define the [ ODEProblem](@ref)
229
+ # We then define the ` ODEProblem`:
228
230
ode_prob_2 = ODEProblem (nd_2, x0_2, (0.0 , 3.0 ))
229
231
Main. test_execution_styles (ode_prob_2) # src
230
232
231
233
# Then solve the network using:
232
234
sol_2 = solve (ode_prob_2, Tsit5 ());
233
235
234
236
# To plot the evolution of variables ϕ_i over time we use the command:
235
- plot (sol_2; idxs= vidxs (nd_2, :, :x ), fmt = :png )
237
+ plot (sol_2; idxs= vidxs (nd_2, :, :x ))
236
238
# [To write ϕ in the terminal type \phi and press TAB]
237
239
238
240
# Using the `eidxs` helper function we can also plot the evolution of the flow variables over time:
239
- plot (sol_2; idxs= eidxs (nd_2, :, :flow_x ), fmt= :png )
241
+ plot (sol_2; idxs= eidxs (nd_2, :, :flow_x ))
242
+ # As expected, the flows are nonzero first and go towards zero as we reach the equilibrium point.
240
243
241
244
242
245
#=
243
246
## Putting it all together
244
-
245
- (@Hans: when I am trying to run the script in the "Putting it all together" in a separate .jl file I am getting a
246
- UndefVarError: `AntiSymmetric` not defined in `Main`
247
- Suggestion: check for spelling errors or missing imports.
248
- Stacktrace:
249
- [1] top-level scope
250
- @ REPL[7]:1)
251
-
252
- and I have no idea why. Can you please check it? Because if someone copy-pastes it, it will not work for them)
253
247
=#
254
248
255
249
using Graphs
@@ -260,7 +254,7 @@ using Plots
260
254
nothing # hide
261
255
262
256
function diffusionedge_g! (e_dst, v_src, v_dst, p, t)
263
- # # e_dst, v_src, v_dst are arrays, hence we use the broadcasting operator
257
+ # # e_dst, v_src, v_dst are arrays, so we use the broadcasting operator .
264
258
e_dst .= v_src .- v_dst
265
259
nothing
266
260
end
@@ -269,7 +263,7 @@ nothing #hide #md
269
263
nd_diffusion_edge = EdgeModel (; g= AntiSymmetric (diffusionedge_g!), outsym= [:flow ])
270
264
271
265
function diffusionvertex_f! (dv, v, esum, p, t)
272
- # # dv, v and esum are arrays, hence we use the broadcasting operator .
266
+ # # dv, v and esum are arrays, so we use the broadcasting operator .
273
267
dv .= esum
274
268
nothing
275
269
end
@@ -300,8 +294,8 @@ x0_2 = vec(transpose([randn(rng, N) .^ 2 randn(rng, N)]))
300
294
ode_prob_2 = ODEProblem (nd_2, x0_2, (0.0 , 3.0 ))
301
295
Main. test_execution_styles (ode_prob_2) # src
302
296
sol_2 = solve (ode_prob_2, Tsit5 ());
303
- plot (sol_2; idxs= vidxs (nd_2, :, :x ), fmt = :png , xlabel = " x" , ylabel = " nd_2" ,)
304
- plot (sol_2; idxs= eidxs (nd_2, :, :flow_x ), fmt = :png )
297
+ plot (sol_2; idxs= vidxs (nd_2, :, :x ), xlabel = " x" , ylabel = " nd_2" ,)
298
+ plot (sol_2; idxs= eidxs (nd_2, :, :flow_x ))
305
299
306
300
307
301
0 commit comments