Esempio n. 1
0
def csa_example():

    cs = csa.cset(csa.random(0.1), 10000.0, 1.0)

    pop1 = nest.LayoutNetwork("iaf_neuron", [16])
    pop2 = nest.LayoutNetwork("iaf_neuron", [16])

    nest.PrintNetwork(10)

    nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1})

    pg = nest.Create("poisson_generator", params={"rate": 80000.0})
    nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0)

    vm_params = {
        "record_to": ["memory"],
        "withgid": True,
        "withtime": True,
        "interval": 0.1
    }
    vm = nest.Create("voltmeter", params=vm_params)
    nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0])

    nest.Simulate(50.0)

    from nest import visualization
    allnodes = pg + nest.GetLeaves(pop1)[0] + nest.GetLeaves(pop2)[0] + vm
    visualization.plot_network(allnodes, "test_csa.png")

    if havePIL:
        im = Image.open("test_csa.png")
        im.show()

    from nest import voltage_trace
    voltage_trace.from_device(vm)
Esempio n. 2
0
    def test_CSA_OneToOne_params(self):
        """One-to-one connectivity"""

        nest.ResetKernel()

        n = 4  # number of neurons

        pop0 = nest.LayoutNetwork("iaf_neuron", [n])
        pop1 = nest.LayoutNetwork("iaf_neuron", [n])

        cs = csa.cset(csa.oneToOne, 10000.0, 1.0)

        nest.CGConnect(pop0, pop1, cs, {"weight": 0, "delay": 1})

        sources = nest.GetLeaves(pop0)[0]
        targets = nest.GetLeaves(pop1)[0]
        for i in xrange(n):
            conns = nest.GetStatus(nest.FindConnections([sources[i]]),
                                   'target')
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0], targets[i])

            conns = nest.GetStatus(nest.FindConnections([targets[i]]),
                                   'target')
            self.assertEqual(len(conns), 0)
Esempio n. 3
0
    def test_CSA_OneToOne_subnet_1d(self):
        """One-to-one connectivity with 1-dim subnets"""

        nest.ResetKernel()

        n = 4  # number of neurons

        pop0 = nest.LayoutNetwork("iaf_neuron", [n])
        pop1 = nest.LayoutNetwork("iaf_neuron", [n])

        cg = csa.cset(csa.oneToOne)

        nest.CGConnect(pop0, pop1, cg)

        sources = nest.GetLeaves(pop0)[0]
        targets = nest.GetLeaves(pop1)[0]
        for i in range(n):
            conns = nest.GetStatus(nest.FindConnections([sources[i]]),
                                   'target')
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0], targets[i])

            conns = nest.GetStatus(nest.FindConnections([targets[i]]),
                                   'target')
            self.assertEqual(len(conns), 0)
Esempio n. 4
0
    def test_libcsa_OneToOne_subnet_nd(self):
        """One-to-one connectivity with n-dim subnets"""

        nest.ResetKernel()

        n = 2  # number of neurons per dimension

        pop0 = nest.LayoutNetwork("iaf_neuron", [n, n])
        pop1 = nest.LayoutNetwork("iaf_neuron", [n, n])

        cg = libcsa.oneToOne

        self.assertRaisesRegex(nest.NESTError, "BadProperty", nest.CGConnect,
                               pop0, pop1, cg)
Esempio n. 5
0
    def test_GetNodes(self):
        """GetNodes"""

        nest.ResetKernel()
        model = 'iaf_psc_alpha'
        l = nest.LayoutNetwork(model, (2, 3))
        allNodes = tuple(range(2, 10))
        allSubnets = (2, 6)
        allLeaves = tuple(n for n in allNodes if n not in allSubnets)

        # test all
        self.assertEqual(nest.GetNodes(l), (allNodes, ))

        # test all with empty dict
        self.assertEqual(nest.GetNodes(l, properties={}), (allNodes, ))

        # test iteration over subnets
        self.assertEqual(nest.GetNodes(l + l), (allNodes, allNodes))

        # children of l are nodes
        self.assertEqual(nest.GetNodes(
            l, properties={'parent': l[0]}), (allSubnets, ))

        # local id of second intermediate subnet and middle nodes
        self.assertEqual(nest.GetNodes(
            l, properties={'local_id': 2}), ((4, 6, 8), ))

        # selection by model type
        self.assertEqual(nest.GetNodes(
            l, properties={'model': 'subnet'}), (allSubnets, ))
        self.assertEqual(nest.GetNodes(
            l, properties={'model': model}), (allLeaves, ))
Esempio n. 6
0
    def test_GetLeaves(self):
        """GetLeaves"""

        nest.ResetKernel()
        model = 'iaf_psc_alpha'
        l = nest.LayoutNetwork(model, (2, 3))
        allLeaves = (3, 4, 5, 7, 8, 9)

        # test all
        self.assertEqual(nest.GetLeaves(l), (allLeaves, ))

        # test all with empty dict
        self.assertEqual(nest.GetLeaves(l, properties={}), (allLeaves, ))

        # test iteration over subnets
        self.assertEqual(nest.GetLeaves(l + l), (allLeaves, allLeaves))

        # children of l are not leaves, should yield empty
        self.assertEqual(nest.GetLeaves(
            l, properties={'parent': l[0]}), (tuple(), ))

        # local id of middle nodes
        self.assertEqual(nest.GetLeaves(
            l, properties={'local_id': 2}), ((4, 8), ))

        # selection by model type
        self.assertEqual(nest.GetLeaves(
            l, properties={'model': model}), (allLeaves, ))
Esempio n. 7
0
    def test_GetChildren(self):
        """GetChildren"""

        nest.ResetKernel()
        model = 'iaf_psc_alpha'
        l = nest.LayoutNetwork(model, (2, 3))
        topKids = (2, 6)
        kids2 = (3, 4, 5)
        kids6 = (7, 8, 9)

        # test top level
        self.assertEqual(nest.GetChildren(l), (topKids, ))

        # test underlying level
        self.assertEqual(nest.GetChildren((2, 6)), (kids2, kids6))

        # test with empty dict
        self.assertEqual(nest.GetChildren(l, properties={}), (topKids, ))

        # local id of middle nodes
        self.assertEqual(nest.GetChildren(
            (2, 6), properties={'local_id': 2}), ((4, ), (8, )))

        # selection by model type
        self.assertEqual(nest.GetChildren(
            l, properties={'model': 'subnet'}), (topKids, ))
        self.assertEqual(nest.GetChildren(
            (2, ), properties={'model': 'subnet'}), (tuple(), ))
        self.assertEqual(nest.GetChildren(
            (2, ), properties={'model': model}), (kids2, ))
Esempio n. 8
0
    def test_GetNodes(self):
        """GetNodes"""

        nest.ResetKernel()
        model = 'iaf_neuron'
        l = nest.LayoutNetwork(model, [2, 3])
        allNodes = range(2, 10)
        allSubnets = [2, 6]
        allLeaves = [n for n in allNodes if n not in allSubnets]

        # test all
        self.assertEqual(nest.GetNodes(l), [allNodes])

        # test all with empty dict
        self.assertEqual(nest.GetNodes(l, properties={}), [allNodes])

        # test iteration over subnets
        self.assertEqual(nest.GetNodes(l + l), [allNodes, allNodes])

        # children of l are nodes
        self.assertEqual(nest.GetNodes(l, properties={'parent': l[0]}),
                         [allSubnets])

        # local id of second intermediate subnet and middle nodes
        self.assertEqual(nest.GetNodes(l, properties={'local_id': 2}),
                         [[4, 6, 8]])

        # selection by model type
        self.assertEqual(nest.GetNodes(l, properties={'model': 'subnet'}),
                         [allSubnets])
        self.assertEqual(nest.GetNodes(l, properties={'model': model}),
                         [allLeaves])
Esempio n. 9
0
    def test_GetLeaves(self):
        """GetLeaves"""

        nest.ResetKernel()
        model = 'iaf_neuron'
        l = nest.LayoutNetwork(model, [2, 3])
        allLeaves = [3, 4, 5, 7, 8, 9]

        # test all
        self.assertEqual(nest.GetLeaves(l), [allLeaves])

        # test all with empty dict
        self.assertEqual(nest.GetLeaves(l, properties={}), [allLeaves])

        # test iteration over subnets
        self.assertEqual(nest.GetLeaves(l + l), [allLeaves, allLeaves])

        # children of l are not leaves, should yield empty
        self.assertEqual(nest.GetLeaves(l, properties={'parent': l[0]}), [[]])

        # local id of middle nodes
        self.assertEqual(nest.GetLeaves(l, properties={'local_id': 2}),
                         [[4, 8]])

        # selection by model type
        self.assertEqual(nest.GetLeaves(l, properties={'model': model}),
                         [allLeaves])
Esempio n. 10
0
    def test_GetChildren(self):
        """GetChildren"""

        nest.ResetKernel()
        model = 'iaf_neuron'
        l = nest.LayoutNetwork(model, [2, 3])
        topKids = [2, 6]
        kids2 = [3, 4, 5]
        kids6 = [7, 8, 9]

        # test top level
        self.assertEqual(nest.GetChildren(l), [topKids])

        # test underlying level
        self.assertEqual(nest.GetChildren([2, 6]), [kids2, kids6])

        # test with empty dict
        self.assertEqual(nest.GetChildren(l, properties={}), [topKids])

        # local id of middle nodes
        self.assertEqual(nest.GetChildren([2, 6], properties={'local_id': 2}),
                         [[4], [8]])

        # selection by model type
        self.assertEqual(nest.GetChildren(l, properties={'model': 'subnet'}),
                         [topKids])
        self.assertEqual(nest.GetChildren([2], properties={'model': 'subnet'}),
                         [[]])
        self.assertEqual(nest.GetChildren([2], properties={'model': model}),
                         [kids2])
Esempio n. 11
0
def csa_example():

    cs = csa.cset(csa.random(0.1), 10000.0, 1.0)

    # This does not work yet, as the implementation does not yet
    # support nested subnets.
    #
    #pop1 = nest.LayoutNetwork("iaf_neuron", [4,4])
    #pop2 = nest.LayoutNetwork("iaf_neuron", [4,4])

    pop1 = nest.LayoutNetwork("iaf_neuron", [16])
    pop2 = nest.LayoutNetwork("iaf_neuron", [16])

    nest.PrintNetwork(10)

    nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1})

    pg = nest.Create("poisson_generator", params={"rate": 80000.0})
    nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0)

    vm = nest.Create("voltmeter",
                     params={
                         "record_to": ["memory"],
                         "withgid": True,
                         "withtime": True,
                         "interval": 0.1
                     })
    nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0])

    nest.Simulate(50.0)

    # Not yet supported in NEST
    #from nest import visualization
    #allnodes = [pg, nest.GetLeaves(pop1)[0], nest.GetLeaves(pop2)[0], vm]
    #visualization.plot_network(allnodes, "test_csa.png", "png", plot_modelnames=True

    #if havePIL:
    #    im = Image.open("test_csa.png")
    #    im.show()

    from nest import voltage_trace
    voltage_trace.from_device(vm)