[2D] Decision Making Model with SlowPointFinder

[1]:
import brainpy as bp
import brainpy.math as bm

bp.math.enable_x64()
# bp.math.set_platform('cpu')
[2]:
# parameters
gamma = 0.641  # Saturation factor for gating variable
tau = 0.06  # Synaptic time constant [sec]
a = 270.
b = 108.
d = 0.154
[3]:
JE = 0.3725  # self-coupling strength [nA]
JI = -0.1137  # cross-coupling strength [nA]
JAext = 0.00117  # Stimulus input strength [nA]
[4]:
mu = 20.  # Stimulus firing rate [spikes/sec]
coh = 0.5  # Stimulus coherence [%]
Ib1 = 0.3297
Ib2 = 0.3297
[5]:
@bp.odeint
def int_s1(s1, t, s2, coh=0.5, mu=20.):
  I1 = JE * s1 + JI * s2 + Ib1 + JAext * mu * (1. + coh)
  r1 = (a * I1 - b) / (1. - bm.exp(-d * (a * I1 - b)))
  return - s1 / tau + (1. - s1) * gamma * r1
[6]:
@bp.odeint
def int_s2(s2, t, s1, coh=0.5, mu=20.):
  I2 = JE * s2 + JI * s1 + Ib2 + JAext * mu * (1. - coh)
  r2 = (a * I2 - b) / (1. - bm.exp(-d * (a * I2 - b)))
  return - s2 / tau + (1. - s2) * gamma * r2
[7]:
def cell(s):
  ds1 = int_s1.f(s[0], 0., s[1])
  ds2 = int_s2.f(s[1], 0., s[0])
  return bm.asarray([ds1, ds2])
[8]:
finder = bp.analysis.SlowPointFinder(f_cell=cell, f_type='continuous')
finder.find_fps_with_gd_method(
  candidates=bm.random.random((1000, 2)),
  tolerance=1e-5, num_batch=200,
  optimizer=bp.optim.Adam(lr=bp.optim.ExponentialDecay(0.01, 1, 0.9999)),
)
finder.filter_loss(1e-5)
finder.keep_unique()

print('fixed_points: ', finder.fixed_points)
print('losses:', finder.losses)
WARNING:jax._src.lib.xla_bridge:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
Optimizing with Adam(lr=ExponentialDecay(0.01, decay_steps=1, decay_rate=0.9999), last_call=-1), beta1=0.9, beta2=0.999, eps=1e-08) to find fixed points:
    Batches 1-200 in 0.53 sec, Training loss 0.0209022794
    Batches 201-400 in 0.39 sec, Training loss 0.0034664037
    Batches 401-600 in 0.40 sec, Training loss 0.0009952186
    Batches 601-800 in 1.03 sec, Training loss 0.0003619036
    Batches 801-1000 in 0.95 sec, Training loss 0.0001457642
    Batches 1001-1200 in 0.42 sec, Training loss 0.0000614027
    Batches 1201-1400 in 0.39 sec, Training loss 0.0000262476
    Batches 1401-1600 in 0.49 sec, Training loss 0.0000111700
    Batches 1601-1800 in 1.29 sec, Training loss 0.0000046670
    Stop optimization as mean training loss 0.0000046670 is below tolerance 0.0000100000.
Excluding fixed points with squared speed above tolerance 1e-05:
    Kept 957/1000 fixed points with tolerance under 1e-05.
Excluding non-unique fixed points:
    Kept 3/957 unique fixed points with uniqueness tolerance 0.025.
fixed_points:  [[0.70045189 0.00486431]
 [0.01394651 0.65738904]
 [0.28276323 0.40635171]]
losses: [2.16451334e-30 1.51498296e-28 3.08194113e-16]
[9]:
jac = finder.compute_jacobians(finder.fixed_points, plot=True, num_col=1)
../_images/dynamics_analysis_2d_decision_making_model_9_0.png