Exemplo n.º 1
0
    def test_helpers(self):
        """Test the circular convolution helper functions in Numpy"""
        rng = np.random.RandomState(43232)

        dims = 1000
        invert_a = True
        invert_b = False
        x = rng.randn(dims)
        y = rng.randn(dims)
        z0 = circconv(x, y, invert_a=invert_a, invert_b=invert_b)

        dims2 = 2 * dims - (2 if dims % 2 == 0 else 1)
        inA = CircularConvolution._input_transform(dims,
                                                   first=True,
                                                   invert=invert_a)
        inB = CircularConvolution._input_transform(dims,
                                                   first=False,
                                                   invert=invert_b)
        outC = CircularConvolution._output_transform(dims)

        XY = np.zeros((dims2, 2))
        XY += np.dot(inA.reshape(dims2, 2, dims), x)
        XY += np.dot(inB.reshape(dims2, 2, dims), y)

        C = XY[:, 0] * XY[:, 1]
        z1 = np.dot(outC, C)

        assert_allclose(self, logger, z0, z1)
Exemplo n.º 2
0
    def test_helpers(self):
        """Test the circular convolution helper functions in Numpy"""
        rng = np.random.RandomState(43232)

        dims = 1000
        invert_a = True
        invert_b = False
        x = rng.randn(dims)
        y = rng.randn(dims)
        z0 = circconv(x, y, invert_a=invert_a, invert_b=invert_b)

        dims2 = 2*dims - (2 if dims % 2 == 0 else 1)
        inA = nengo.networks.CircularConvolution._input_transform(
            dims, first=True, invert=invert_a)
        inB = nengo.networks.CircularConvolution._input_transform(
            dims, first=False, invert=invert_b)
        outC = nengo.networks.CircularConvolution._output_transform(dims)

        XY = np.zeros((dims2, 2))
        XY += np.dot(inA.reshape(dims2, 2, dims), x)
        XY += np.dot(inB.reshape(dims2, 2, dims), y)

        C = XY[:, 0] * XY[:, 1]
        z1 = np.dot(outC, C)

        assert_allclose(self, logger, z0, z1)
Exemplo n.º 3
0
    def test_circular(self):
        dt = 0.001
        m = nengo.Model("test_circular", seed=0)

        with m:
            a = nengo.Node(output=lambda t, x: x+1, dimensions=1)
            b = nengo.Node(output=lambda t, x: x+1, dimensions=1)
            nengo.Connection(a, b, filter=None)
            nengo.Connection(b, a, filter=None)

            a_p = nengo.Probe(a, 'output')
            b_p = nengo.Probe(b, 'output')

        sim = self.Simulator(m, dt=dt)
        runtime = 0.5
        sim.run(runtime)

        assert_allclose(self, logger, sim.data(a_p), sim.data(b_p))
Exemplo n.º 4
0
    def test_circular(self):
        dt = 0.001
        m = nengo.Model("test_circular", seed=0)

        m.add(Node("a", output=lambda x: x + 1))
        m.add(Node("b", output=lambda x: x + 1))
        m.connect("a", "b", filter=None)
        m.connect("b", "a", filter=None)

        m.probe("a")
        m.probe("b")

        sim = m.simulator(dt=dt, sim_class=self.Simulator)
        runtime = 0.5
        sim.run(runtime)

        a = sim.data("a")
        b = sim.data("b")
        assert_allclose(self, logger, a, b)
Exemplo n.º 5
0
    def test_circular(self):
        dt = 0.001
        m = nengo.Model("test_circular", seed=0)

        m.add(Node("a", output=lambda x:x+1))
        m.add(Node("b", output=lambda x:x+1))
        m.connect("a", "b", filter=None)
        m.connect("b", "a", filter=None)

        m.probe("a")
        m.probe("b")

        sim = m.simulator(dt=dt, sim_class=self.Simulator)
        runtime = 0.5
        sim.run(runtime)

        a = sim.data("a")
        b = sim.data("b")
        assert_allclose(self, logger, a, b)
Exemplo n.º 6
0
    def test_pyfunc(self):
        """Test Python Function nonlinearity"""

        dt = 0.001
        d = 3
        n_steps = 3
        n_trials = 3

        rng = np.random.RandomState(seed=987)

        for i in range(n_trials):
            A = rng.normal(size=(d, d))
            fn = lambda t, x: np.cos(np.dot(A, x))

            x = np.random.normal(size=d)

            m = nengo.Model("")
            ins = Signal(x, name='ins')
            pop = nengo.PythonFunction(fn=fn, n_in=d)
            m.operators = []
            b = Builder()
            b.model = m
            b.build_pyfunc(pop)
            m.operators += [
                DotInc(Signal(np.eye(d)), ins, pop.input_signal),
                ProdUpdate(
                    Signal(np.eye(d)), pop.output_signal, Signal(0), ins)
            ]

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

            p0 = np.zeros(d)
            s0 = np.array(x)
            for j in range(n_steps):
                tmp = p0
                p0 = fn(0, s0)
                s0 = tmp
                sim.step()
                assert_allclose(self, logger, s0, sim.signals[ins])
                assert_allclose(
                    self, logger, p0, sim.signals[pop.output_signal])