def test_lif_rate(n_elements):
    """Test the `lif_rate` nonlinearity"""
    rng = np.random
    dt = 1e-3

    n_neurons = [123459, 23456, 34567]
    J = RA([rng.normal(loc=1, scale=10, size=n) for n in n_neurons])
    R = RA([np.zeros(n) for n in n_neurons])

    ref = 2e-3
    taus = list(rng.uniform(low=15e-3, high=80e-3, size=len(n_neurons)))

    queue = cl.CommandQueue(ctx)
    clJ = CLRA(queue, J)
    clR = CLRA(queue, R)
    clTau = CLRA(queue, RA(taus))

    # simulate host
    nls = [LIFRate(tau_ref=ref, tau_rc=taus[i])
           for i, n in enumerate(n_neurons)]
    for i, nl in enumerate(nls):
        nl.step_math(dt, J[i], R[i])

    # simulate device
    plan = plan_lif_rate(queue, clJ, clR, ref, clTau, dt=dt,
                         n_elements=n_elements)
    plan()

    rate_sum = np.sum([np.sum(r) for r in R])
    if rate_sum < 1.0:
        logger.warn("LIF rate was not tested above the firing threshold!")
    assert ra.allclose(J, clJ.to_host())
    assert ra.allclose(R, clR.to_host())
Example #2
0
 def _plan_AdaptiveLIFRate(self, ops):
     dt = self.model.dt
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     N = self.all_data[[self.sidx[op.states[0]] for op in ops]]
     ref = self.RaggedArray(
         [op.neurons.tau_ref * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     tau = self.RaggedArray(
         [op.neurons.tau_rc * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     amp = self.RaggedArray(
         [op.neurons.amplitude * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     tau_n = self.RaggedArray(
         [op.neurons.tau_n * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     inc_n = self.RaggedArray(
         [op.neurons.inc_n * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     return [
         plan_lif_rate(self.queue,
                       dt,
                       J,
                       R,
                       ref,
                       tau,
                       amp,
                       N=N,
                       tau_n=tau_n,
                       inc_n=inc_n)
     ]
Example #3
0
def test_lif_rate(ctx, blockify):
    """Test the `lif_rate` nonlinearity"""
    rng = np.random
    dt = 1e-3

    n_neurons = [123459, 23456, 34567]
    J = RA([rng.normal(loc=1, scale=10, size=n) for n in n_neurons])
    R = RA([np.zeros(n) for n in n_neurons])

    ref = 2e-3
    taus = list(rng.uniform(low=15e-3, high=80e-3, size=len(n_neurons)))

    queue = cl.CommandQueue(ctx)
    clJ = CLRA(queue, J)
    clR = CLRA(queue, R)
    clTaus = CLRA(queue, RA([t * np.ones(n) for t, n in zip(taus, n_neurons)]))

    # simulate host
    nls = [nengo.LIFRate(tau_ref=ref, tau_rc=taus[i])
           for i, n in enumerate(n_neurons)]
    for i, nl in enumerate(nls):
        nl.step_math(dt, J[i], R[i])

    # simulate device
    plan = plan_lif_rate(queue, dt, clJ, clR, ref, clTaus, blockify=blockify)
    plan()

    rate_sum = np.sum([np.sum(r) for r in R])
    if rate_sum < 1.0:
        logger.warn("LIF rate was not tested above the firing threshold!")
    assert ra.allclose(J, clJ.to_host())
    assert ra.allclose(R, clR.to_host())
Example #4
0
 def plan_SimLIFRate(self, ops):
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     ref = self.RaggedArray([op.nl.tau_ref for op in ops])
     tau = self.RaggedArray([op.nl.tau_rc for op in ops])
     dt = self.model.dt
     return [plan_lif_rate(self.queue, J, R, ref, tau, dt,
                           tag="lif_rate", n_elements=10)]
Example #5
0
 def _plan_LIFRate(self, ops):
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     ref = self.RaggedArray([op.neurons.tau_ref * np.ones(op.J.size)
                             for op in ops], dtype=J.dtype)
     tau = self.RaggedArray([op.neurons.tau_rc * np.ones(op.J.size)
                             for op in ops], dtype=J.dtype)
     dt = self.model.dt
     return [plan_lif_rate(self.queue, J, R, ref, tau, dt)]
Example #6
0
 def _plan_LIFRate(self, ops):
     dt = self.model.dt
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     ref = self.RaggedArray(
         [np.array(op.neurons.tau_ref, dtype=J.dtype) for op in ops])
     tau = self.RaggedArray(
         [np.array(op.neurons.tau_rc, dtype=J.dtype) for op in ops])
     return [plan_lif_rate(self.queue, dt, J, R, ref, tau, n_elements=2)]
Example #7
0
 def _plan_LIFRate(self, ops):
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     ref = self.RaggedArray(
         [op.neurons.tau_ref * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     tau = self.RaggedArray(
         [op.neurons.tau_rc * np.ones(op.J.size) for op in ops],
         dtype=J.dtype)
     dt = self.model.dt
     return [plan_lif_rate(self.queue, J, R, ref, tau, dt)]
Example #8
0
 def _plan_AdaptiveLIFRate(self, ops):
     dt = self.model.dt
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     N = self.all_data[[self.sidx[op.states[0]] for op in ops]]
     ref = self.RaggedArray(
         [np.array(op.neurons.tau_ref, dtype=J.dtype) for op in ops])
     tau = self.RaggedArray(
         [np.array(op.neurons.tau_rc, dtype=J.dtype) for op in ops])
     tau_n = self.RaggedArray(
         [np.array(op.neurons.tau_n, dtype=J.dtype) for op in ops])
     inc_n = self.RaggedArray(
         [np.array(op.neurons.inc_n, dtype=J.dtype) for op in ops])
     return [plan_lif_rate(self.queue, dt, J, R, ref, tau,
                           N=N, tau_n=tau_n, inc_n=inc_n, n_elements=2)]
Example #9
0
 def _plan_AdaptiveLIFRate(self, ops):
     dt = self.model.dt
     J = self.all_data[[self.sidx[op.J] for op in ops]]
     R = self.all_data[[self.sidx[op.output] for op in ops]]
     N = self.all_data[[self.sidx[op.states[0]] for op in ops]]
     ref = self.RaggedArray([op.neurons.tau_ref * np.ones(op.J.size)
                             for op in ops], dtype=J.dtype)
     tau = self.RaggedArray([op.neurons.tau_rc * np.ones(op.J.size)
                             for op in ops], dtype=J.dtype)
     tau_n = self.RaggedArray([op.neurons.tau_n * np.ones(op.J.size)
                               for op in ops], dtype=J.dtype)
     inc_n = self.RaggedArray([op.neurons.inc_n * np.ones(op.J.size)
                               for op in ops], dtype=J.dtype)
     return [plan_lif_rate(self.queue, dt, J, R, ref, tau,
                           N=N, tau_n=tau_n, inc_n=inc_n)]