Ejemplo n.º 1
0
    def _test_lif_base(self, cls=nengo.LIF):
        """Test that the dynamic model approximately matches the rates"""
        rng = np.random.RandomState(85243)

        dt = 0.001
        d = 1
        n = 5000

        m = nengo.Model("")
        ins = Signal(0.5 * np.ones(d), name='ins')
        lif = cls(n)
        lif.set_gain_bias(max_rates=rng.uniform(low=10, high=200, size=n),
                          intercepts=rng.uniform(low=-1, high=1, size=n))
        m.operators = []
        b = Builder()
        b.model = m
        b._builders[cls](lif)
        m.operators += [DotInc(Signal(np.ones((n, d))), ins, lif.input_signal)]

        sim = self.Simulator(m, dt=dt, builder=testbuilder)

        t_final = 1.0
        spikes = np.zeros(n)
        for i in range(int(np.round(t_final / dt))):
            sim.step()
            spikes += sim.signals[lif.output_signal]

        math_rates = lif.rates(sim.signals[lif.input_signal] - lif.bias)
        sim_rates = spikes / t_final
        logger.debug("ME = %f", (sim_rates - math_rates).mean())
        logger.debug("RMSE = %f",
                     rms(sim_rates - math_rates) / (rms(math_rates) + 1e-20))
        self.assertTrue(np.sum(math_rates > 0) > 0.5*n,
                        "At least 50% of neurons must fire")
        self.assertTrue(np.allclose(sim_rates, math_rates, atol=1, rtol=0.02))
Ejemplo n.º 2
0
    def _test_lif_base(self, cls=LIF):
        """Test that the dynamic model approximately matches the rates"""
        rng = np.random.RandomState(85243)

        dt = 0.001
        d = 1
        n = 5e3

        m = nengo.Model("")
        ins = Signal(n=d, name='ins')
        lif = cls(n)
        lif.set_gain_bias(max_rates=rng.uniform(low=10, high=200, size=n),
                          intercepts=rng.uniform(low=-1, high=1, size=n))
        m.signals = [ins]
        m.operators = []
        b = Builder()
        b._builders[cls](lif, m, dt)
        m.operators += [
            DotInc(Constant(np.ones((n, d))), ins, lif.input_signal)
        ]

        sim = m.simulator(sim_class=self.Simulator, dt=dt, builder=testbuilder)
        sim.signals[ins] = 0.5 * np.ones(d)

        t_final = 1.0
        spikes = np.zeros(n)
        for i in xrange(int(np.round(t_final / dt))):
            sim.step()
            spikes += sim.signals[lif.output_signal]

        math_rates = lif.rates(sim.signals[lif.input_signal] - lif.bias)
        sim_rates = spikes / t_final
        logger.debug("ME = %f", (sim_rates - math_rates).mean())
        logger.debug("RMSE = %f",
                     rms(sim_rates - math_rates) / (rms(math_rates) + 1e-20))
        self.assertTrue(
            np.sum(math_rates > 0) > 0.5 * n,
            "At least 50% of neurons must fire")
        self.assertTrue(np.allclose(sim_rates, math_rates, atol=1, rtol=0.02))