Beispiel #1
0
 def step_piecewise(t):
     ti = clip(
         np.searchsorted(tp, t + 0.5 * dt) - 1, -1,
         len(yp) - 1)
     if ti == -1:
         return np.zeros(shape_out)
     return np.ravel(yp[ti](t)) if callable(yp[ti]) else yp[ti]
Beispiel #2
0
    def step(self, dt, J, output, voltage, refractory_time):
        # look these up once to avoid repeated parameter accesses
        tau_rc = self.tau_rc
        min_voltage = self.min_voltage

        # reduce all refractory times by dt
        refractory_time -= dt

        # compute effective dt for each neuron, based on remaining time.
        # note that refractory times that have completed midway into this
        # timestep will be given a partial timestep, and moreover these will
        # be subtracted to zero at the next timestep (or reset by a spike)
        delta_t = clip((dt - refractory_time), 0, dt)

        # update voltage using discretized lowpass filter
        # since v(t) = v(0) + (J - v(0))*(1 - exp(-t/tau)) assuming
        # J is constant over the interval [t, t + dt)
        voltage -= (J - voltage) * np.expm1(-delta_t / tau_rc)

        # determine which neurons spiked (set them to 1/dt, else 0)
        spiked_mask = voltage > 1
        output[:] = spiked_mask * (self.amplitude / dt)

        # set v(0) = 1 and solve for t to compute the spike time
        t_spike = dt + tau_rc * np.log1p(-(voltage[spiked_mask] - 1) /
                                         (J[spiked_mask] - 1))

        # set spiked voltages to zero, refractory times to tau_ref, and
        # rectify negative voltages to a floor of min_voltage
        voltage[voltage < min_voltage] = min_voltage
        voltage[spiked_mask] = -1  #reset voltage
        refractory_time[spiked_mask] = self.tau_ref + t_spike
def np_calc(dt, J, output, voltage, refractory_time, adaptation, inhibition):
    """Implement the AdaptiveLIF nonlinearity."""

    J = J - adaptation

    # reduce all refractory times by dt
    refractory_time -= dt

    # compute effective dt for each neuron, based on remaining time.
    # note that refractory times that have completed midway into this
    # timestep will be given a partial timestep, and moreover these will
    # be subtracted to zero at the next timestep (or reset by a spike)
    delta_t = clip((dt - refractory_time), 0, dt)

    # update voltage using discretized lowpass filter
    # since v(t) = v(0) + (J - v(0))*(1 - exp(-t/tau)) assuming
    # J is constant over the interval [t, t + dt)
    voltage -= (J - voltage) * np.expm1(-delta_t / tau_rc)

    # determine which neurons spiked (set them to 1/dt, else 0)
    spiked_mask = voltage > 1
    output[:] = spiked_mask * (amplitude / dt)

    # if neuron that spiked had highest input but was still inhibited from a previous timestep
    voltage[inhibition != 0] = 0
    output[inhibition != 0] = 0
    spiked_mask[inhibition != 0] = False

    if np.count_nonzero(output) > 0:
        # inhibit all other neurons than one with highest input
        voltage[J != np.max(J)] = 0
        output[J != np.max(J)] = 0
        spiked_mask[J != np.max(J)] = False
        inhibition[(J != np.max(J)) & (inhibition == 0)] = tau_inhibition

    # set v(0) = 1 and solve for t to compute the spike time
    t_spike = dt + tau_rc * np.log1p(-(voltage[spiked_mask] - 1) /
                                     (J[spiked_mask] - 1))

    # set spiked voltages to zero, refractory times to tau_ref, and
    # rectify negative voltages to a floor of min_voltage
    voltage[voltage < min_voltage] = min_voltage
    voltage[spiked_mask] = 0
    refractory_time[spiked_mask] = tau_ref + t_spike

    adaptation += (dt / tau_n) * (inc_n * output - adaptation)

    inhibition[inhibition != 0] -= 1

    return J, output, voltage, refractory_time, adaptation, inhibition
Beispiel #4
0
def default_n_eval_points(n_neurons, dimensions):
    """A heuristic to determine an appropriate number of evaluation points.

    This is used by builders to generate a sufficiently large sample
    from a vector space in order to solve for accurate decoders.

    Parameters
    ----------
    n_neurons : int
        The number of neurons in the ensemble that will be sampled.
        For a connection, this would be the number of neurons in the
        ``pre`` ensemble.
    dimensions : int
        The number of dimensions in the ensemble that will be sampled.
        For a connection, this would be the number of dimensions in the
        ``pre`` ensemble.
    """
    from nengo.utils.numpy import clip  # pylint: disable=import-outside-toplevel

    return max(clip(500 * dimensions, 750, 2500), 2 * n_neurons)
Beispiel #5
0
 def sample(self, n, d=None, rng=np.random):
     shape = self._sample_shape(n, d)
     x = rng.exponential(self.scale, shape) + self.shift
     high = np.nextafter(self.high, np.asarray(-np.inf, dtype=x.dtype))
     return npext.clip(x, self.shift, high)
Beispiel #6
0
    def step(self, dt, J, output, voltage, refractory_time, adaptation,
             inhib):  #inhib
        self.T = round(self.T + dt, 3)

        if (np.max(J) != 0):
            J = np.divide(J, np.max(J)) * 1.5

        if math.isclose(math.fmod(self.T, 0.20), 0, abs_tol=1e-3):
            self.T = 0
            voltage[...] = 0
            refractory_time[...] = 0
            inhib[...] = 0
            output[...] = 0
            J[...] = 0

        # tInhibit = 10 MilliSecond
        # AdaptiveThresholdAdd = 0.05  millivolts
        # MembraneRefractoryDuration = = 1 MilliSecond
        #print("J",J,"voltage",voltage,output)

        J = J - adaptation
        # ----------------------------

        # look these up once to avoid repeated parameter accesses
        tau_rc = self.tau_rc
        min_voltage = self.min_voltage

        # reduce all refractory times by dt
        refractory_time -= dt

        # compute effective dt for each neuron, based on remaining time.
        # note that refractory times that have completed midway into this
        # timestep will be given a partial timestep, and moreover these will
        # be subtracted to zero at the next timestep (or reset by a spike)
        delta_t = clip((dt - refractory_time), 0, dt)

        # update voltage using discretized lowpass filter
        # since v(t) = v(0) + (J - v(0))*(1 - exp(-t/tau)) assuming
        # J is constant over the interval [t, t + dt)
        voltage -= (J - voltage) * np.expm1(-delta_t / tau_rc)

        # determine which neurons spiked (set them to 1/dt, else 0)
        spiked_mask = (voltage > self.spiking_threshold)
        output[:] = spiked_mask * (self.amplitude / dt)
        output[voltage != np.max(voltage)] = 0
        if (np.sum(output) > 1):
            voltage[voltage != np.max(voltage)] = 0
            output[voltage != np.max(voltage)] = 0
            spiked_mask[voltage != np.max(voltage)] = 0
            inhib[(voltage != np.max(voltage)) & (inhib == 0)] = 15  #10 | 2
        #print("voltage : ",voltage)
        #voltage[inhib != 0] = 0
        J[inhib != 0] = 0
        #print("\n",dt,J,inhib)
        # set v(0) = 1 and solve for t to compute the spike time
        t_spike = dt + tau_rc * np.log1p(
            -(voltage[spiked_mask] - self.spiking_threshold) /
            (J[spiked_mask] - self.spiking_threshold))

        # set spiked voltages to zero, refractory times to tau_ref, and
        # rectify negative voltages to a floor of min_voltage
        voltage[voltage < min_voltage] = min_voltage
        voltage[spiked_mask] = 0
        voltage[refractory_time > 0] = 0
        refractory_time[spiked_mask] = self.tau_ref + t_spike
        refractory_time[refractory_time < 0] = 0
        # ----------------------------

        adaptation += (dt / self.tau_n) * (self.inc_n * output - adaptation)

        #AdaptiveLIF.step(self, dt, J, output, voltage, refractory_time, adaptation)
        inhib[inhib != 0] += -1
Beispiel #7
0
 def heuristic(neurons, dims):
     return max(npext.clip(500 * dims, 750, 2500), 2 * neurons)