Example #1
0
def ramp_input(c_start, c_end, duration, t_start=0, t_end=None, dt=None):
    """Get the gradually changed input current.

  Parameters
  ----------
  c_start : float
      The minimum (or maximum) current size.
  c_end : float
      The maximum (or minimum) current size.
  duration : int, float
      The total duration.
  t_start : float
      The ramped current start time-point.
  t_end : float
      The ramped current end time-point. Default is the None.
  dt : float, int, optional
      The numerical precision.

  Returns
  -------
  current_and_duration : tuple
      (The formatted current, total duration)
  """
    dt = math.get_dt() if dt is None else dt
    t_end = duration if t_end is None else t_end

    current = math.zeros(int(np.ceil(duration / dt)), dtype=math.float_)
    p1 = int(np.ceil(t_start / dt))
    p2 = int(np.ceil(t_end / dt))
    current[p1:p2] = math.array(math.linspace(c_start, c_end, p2 - p1),
                                dtype=math.float_)
    return current
  def __init__(self, num, tau=1., tau_v=50., k=1., a=0.3, A=0.2, J0=1.,
               z_min=-bm.pi, z_max=bm.pi, m=0.3):
    super(CANN1D, self).__init__(size=num)

    # parameters
    self.tau = tau  # The synaptic time constant
    self.tau_v = tau_v
    self.k = k  # Degree of the rescaled inhibition
    self.a = a  # Half-width of the range of excitatory connections
    self.A = A  # Magnitude of the external input
    self.J0 = J0  # maximum connection value
    self.m = m

    # feature space
    self.z_min = z_min
    self.z_max = z_max
    self.z_range = z_max - z_min
    self.x = bm.linspace(z_min, z_max, num)  # The encoded feature values
    self.rho = num / self.z_range  # The neural density
    self.dx = self.z_range / num  # The stimulus density

    # The connection matrix
    self.conn_mat = self.make_conn()

    # variables
    self.r = bm.Variable(bm.zeros(num))
    self.u = bm.Variable(bm.zeros(num))
    self.v = bm.Variable(bm.zeros(num))
    self.input = bm.Variable(bm.zeros(num))
Example #3
0
def visualize_fixed_points():
    fixed_points = np.load(fps_output_fn)

    bp.visualize.animate_1D(
        dynamical_vars={
            'ys': fixed_points,
            'xs': bm.linspace(-bm.pi, bm.pi, fixed_points.shape[1]),
            'legend': 'fixed point'
        },
        frame_step=1,
        frame_delay=100,
        show=True,
        # save_path='cann_fps.gif'
    )
Example #4
0
    def __init__(self,
                 num,
                 tau=1.,
                 k=8.1,
                 a=0.5,
                 A=10.,
                 J0=4.,
                 z_min=-bm.pi,
                 z_max=bm.pi,
                 **kwargs):
        super(CANN1D, self).__init__(size=num, **kwargs)

        # parameters
        self.tau = tau  # The synaptic time constant
        self.k = k  # Degree of the rescaled inhibition
        self.a = a  # Half-width of the range of excitatory connections
        self.A = A  # Magnitude of the external input
        self.J0 = J0  # maximum connection value

        # feature space
        self.z_min = z_min
        self.z_max = z_max
        self.z_range = z_max - z_min
        self.x = bm.linspace(z_min, z_max, num)  # The encoded feature values
        self.rho = num / self.z_range  # The neural density
        self.dx = self.z_range / num  # The stimulus density

        # variables
        self.u = bm.Variable(bm.zeros(num))
        self.input = bm.Variable(bm.zeros(num))

        # The connection matrix
        self.conn_mat = self.make_conn(self.x)

        # function
        self.integral = bp.odeint(self.derivative)
Example #5
0
    def __init__(self,
                 length,
                 tau=1.,
                 k=8.1,
                 a=0.5,
                 A=10.,
                 J0=4.,
                 z_min=-bm.pi,
                 z_max=bm.pi,
                 name=None):
        super(CANN2D, self).__init__(size=(length, length), name=name)

        # parameters
        self.length = length
        self.tau = tau  # The synaptic time constant
        self.k = k  # Degree of the rescaled inhibition
        self.a = a  # Half-width of the range of excitatory connections
        self.A = A  # Magnitude of the external input
        self.J0 = J0  # maximum connection value

        # feature space
        self.z_min = z_min
        self.z_max = z_max
        self.z_range = z_max - z_min
        self.x = bm.linspace(z_min, z_max,
                             length)  # The encoded feature values
        self.rho = length / self.z_range  # The neural density
        self.dx = self.z_range / length  # The stimulus density

        # The connections
        self.conn_mat = self.make_conn()

        # variables
        self.r = bm.Variable(bm.zeros((length, length)))
        self.u = bm.Variable(bm.zeros((length, length)))
        self.input = bm.Variable(bm.zeros((length, length)))
    Irec = bm.dot(self.conn_mat, self.r)
    self.u.value = self.u + (-self.u + Irec + self.input - self.v) / self.tau * _dt
    self.v.value = self.v + (-self.v + self.m * self.u) / self.tau_v * _dt
    self.input[:] = 0.


cann = CANN1D(num=512)

# Smooth tracking #
dur1, dur2, dur3 = 100., 2000., 500.
num1 = int(dur1 / bm.get_dt())
num2 = int(dur2 / bm.get_dt())
num3 = int(dur3 / bm.get_dt())
position = bm.zeros(num1 + num2 + num3)
final_pos = cann.a / cann.tau_v * 0.6 * dur2
position[num1: num1 + num2] = bm.linspace(0., final_pos, num2)
position[num1 + num2:] = final_pos
position = position.reshape((-1, 1))
Iext = cann.get_stimulus_by_pos(position)
runner = bp.StructRunner(cann,
                         inputs=('input', Iext, 'iter'),
                         monitors=['u', 'v'],
                         dyn_vars=cann.vars())
runner(dur1 + dur2 + dur3)
bp.visualize.animate_1D(
  dynamical_vars=[
    {'ys': runner.mon.u, 'xs': cann.x, 'legend': 'u'},
    {'ys': runner.mon.v, 'xs': cann.x, 'legend': 'v'},
    {'ys': Iext, 'xs': cann.x, 'legend': 'Iext'}
  ],
  frame_step=30,
Example #7
0
runner(dur1 + dur2 + dur3)
bp.visualize.animate_1D(
  dynamical_vars=[{'ys': runner.mon.u, 'xs': cann.x, 'legend': 'u'},
                  {'ys': Iext, 'xs': cann.x, 'legend': 'Iext'}],
  frame_step=5,
  frame_delay=50,
  show=True
)

# Smooth tracking #
dur1, dur2, dur3 = 10., 100., 20.
num1 = int(dur1 / bm.get_dt())
num2 = int(dur2 / bm.get_dt())
num3 = int(dur3 / bm.get_dt())
position = bm.zeros(num1 + num2 + num3)
position[num1: num1 + num2] = bm.linspace(0., 20., num2)
position[num1 + num2:] = 20.
position = position.reshape((-1, 1))
Iext = cann.get_stimulus_by_pos(position)
runner = bp.StructRunner(cann,
                         inputs=('input', Iext, 'iter'),
                         monitors=['u'],
                         dyn_vars=cann.vars())
runner(dur1 + dur2 + dur3)
bp.visualize.animate_1D(
  dynamical_vars=[{'ys': runner.mon.u, 'xs': cann.x, 'legend': 'u'},
                  {'ys': Iext, 'xs': cann.x, 'legend': 'Iext'}],
  frame_step=5,
  frame_delay=50,
  show=True,
)