Skip to content

Commit b797770

Browse files
authored
Fix bug in fhn and hopf OC (#255)
* fix bug in OC of fhn and hopf for diffusive coupling * fix style fhn * fix style hopf * fix style fhn * fix style hopf
1 parent 0776d7a commit b797770

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

neurolib/control/optimal_control/oc_fhn/oc_fhn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def compute_hx(self):
9090
"""
9191
return compute_hx(
9292
self.model_params,
93+
self.model.params["K_gl"],
94+
self.model.params["Cmat"],
95+
self.model.params["coupling"],
9396
self.N,
9497
self.dim_vars,
9598
self.T,
@@ -106,7 +109,6 @@ def compute_hx_nw(self):
106109
return compute_hx_nw(
107110
self.model.params["K_gl"],
108111
self.model.params["Cmat"],
109-
self.model.params["coupling"],
110112
self.N,
111113
self.dim_vars,
112114
self.T,

neurolib/control/optimal_control/oc_hopf/oc_hopf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def compute_hx(self):
9090
"""
9191
return compute_hx(
9292
self.model_params,
93+
self.model.params["K_gl"],
94+
self.model.params["Cmat"],
95+
self.model.params["coupling"],
9396
self.N,
9497
self.dim_vars,
9598
self.T,
@@ -106,7 +109,6 @@ def compute_hx_nw(self):
106109
return compute_hx_nw(
107110
self.model.params["K_gl"],
108111
self.model.params["Cmat"],
109-
self.model.params["coupling"],
110112
self.N,
111113
self.dim_vars,
112114
self.T,

neurolib/models/fhn/timeIntegration.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ def jacobian_fhn(
287287
@numba.njit
288288
def compute_hx(
289289
model_params,
290+
K_gl,
291+
cmat,
292+
coupling,
290293
N,
291294
V,
292295
T,
@@ -295,8 +298,14 @@ def compute_hx(
295298
):
296299
"""Jacobians of FHN model wrt. its 'state_vars' at each time step.
297300
298-
:param model_params: Ordered tuple of parameters in the FHN Model in order
299-
:type model_params: tuple of float
301+
:param model_params: Ordered tuple of parameters in the FHN Model in order
302+
:type model_params: tuple of float
303+
:param K_gl: Model parameter of global coupling strength.
304+
:type K_gl: float
305+
:param cmat: Model parameter, connectivity matrix.
306+
:type cmat: ndarray
307+
:param coupling: Model parameter, which specifies the coupling type. E.g. "additive" or "diffusive".
308+
:type coupling: str
300309
:param N: Number of nodes in the network.
301310
:type N: int
302311
:param V: Number of system variables.
@@ -316,14 +325,17 @@ def compute_hx(
316325
for n in range(N): # Iterate through nodes.
317326
for t in range(T):
318327
hx[n, t, :, :] = jacobian_fhn(model_params, dyn_vars[n, sv["x"], t], V, sv)
328+
329+
if coupling == "diffusive":
330+
for l in range(N):
331+
hx[n, t, sv["x"], sv["x"]] += K_gl * cmat[n, l]
319332
return hx
320333

321334

322335
@numba.njit
323336
def compute_hx_nw(
324337
K_gl,
325338
cmat,
326-
coupling,
327339
N,
328340
V,
329341
T,
@@ -335,8 +347,6 @@ def compute_hx_nw(
335347
:type K_gl: float
336348
:param cmat: Model parameter, connectivity matrix.
337349
:type cmat: ndarray
338-
:param coupling: Model parameter, which specifies the coupling type. E.g. "additive" or "diffusive".
339-
:type coupling: str
340350
:param N: Number of nodes in the network.
341351
:type N: int
342352
:param V: Number of system variables.
@@ -353,9 +363,9 @@ def compute_hx_nw(
353363

354364
for n1 in range(N):
355365
for n2 in range(N):
356-
hx_nw[n1, n2, :, sv["x"], sv["x"]] = K_gl * cmat[n1, n2] # term corresponding to additive coupling
357-
if coupling == "diffusive":
358-
hx_nw[n1, n1, :, sv["x"], sv["x"]] += -K_gl * cmat[n1, n2]
366+
hx_nw[n1, n2, :, sv["x"], sv["x"]] = (
367+
K_gl * cmat[n1, n2]
368+
) # term corresponding to both diffusive and additive coupling
359369

360370
return -hx_nw
361371

neurolib/models/hopf/timeIntegration.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ def jacobian_hopf(
267267
@numba.njit
268268
def compute_hx(
269269
model_params,
270+
K_gl,
271+
cmat,
272+
coupling,
270273
N,
271274
V,
272275
T,
@@ -277,7 +280,13 @@ def compute_hx(
277280
278281
:param model_params: Ordered tuple of parameters in the Hopf Model in order
279282
:type model_params: tuple of float
280-
:param N: Number of network nodes.
283+
:param K_gl: Model parameter of global coupling strength.
284+
:type K_gl: float
285+
:param cmat: Model parameter, connectivity matrix.
286+
:type cmat: ndarray
287+
:param coupling: Model parameter, which specifies the coupling type. E.g. "additive" or "diffusive".
288+
:type coupling: str
289+
:param N: Number of nodes in the network.
281290
:type N: int
282291
:param V: Number of state variables.
283292
:type V: int
@@ -303,14 +312,17 @@ def compute_hx(
303312
dyn_vars[n, sv["y"], t],
304313
sv,
305314
)
315+
316+
if coupling == "diffusive":
317+
for l in range(N):
318+
hx[n, t, sv["x"], sv["x"]] += K_gl * cmat[n, l]
306319
return hx
307320

308321

309322
@numba.njit
310323
def compute_hx_nw(
311324
K_gl,
312325
cmat,
313-
coupling,
314326
N,
315327
V,
316328
T,
@@ -322,8 +334,6 @@ def compute_hx_nw(
322334
:type K_gl: float
323335
:param cmat: Model parameter, connectivity matrix.
324336
:type cmat: ndarray
325-
:param coupling: Model parameter, which specifies the coupling type. E.g. "additive" or "diffusive".
326-
:type coupling: str
327337
:param N: Number of nodes in the network.
328338
:type N: int
329339
:param V: Number of system variables.
@@ -340,9 +350,9 @@ def compute_hx_nw(
340350

341351
for n1 in range(N):
342352
for n2 in range(N):
343-
hx_nw[n1, n2, :, sv["x"], sv["x"]] = K_gl * cmat[n1, n2] # term corresponding to additive coupling
344-
if coupling == "diffusive":
345-
hx_nw[n1, n1, :, sv["x"], sv["x"]] += -K_gl * cmat[n1, n2]
353+
hx_nw[n1, n2, :, sv["x"], sv["x"]] = (
354+
K_gl * cmat[n1, n2]
355+
) # corresponding to both diffusive and additive coupling
346356

347357
return -hx_nw
348358

0 commit comments

Comments
 (0)