def _connect(self):
        '''Connect populations.'''

        finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t))
        if self._fan == 'in':
            self._cs = csa.cset(csa.random(fanIn=self._C) * finite_set)
        else:
            self._cs = csa.cset(csa.random(fanOut=self._C) * finite_set)
    def _connect(self):
        '''Connect populations.'''

        finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t))
        if self._fan == 'in':
            cs = csa.cset(csa.random(fanIn=self._C) * finite_set)
        else:
            cs = csa.cset(csa.random(fanOut=self._C) * finite_set)
        nest.CGConnect(self._source_pop, self._target_pop, csa.cset(cs))
    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)
    def test_CSA_cgnext(self):
        """cgnext"""

        nest.ResetKernel()

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

        nest.sli_push(cs)
        nest.sli_run('dup')
        nest.sli_push(numpy.array([0, 1, 2, 3]))
        nest.sli_push(numpy.array([0, 1, 2, 3]))
        nest.sli_run('cgsetmask')
        nest.sli_run('dup')
        nest.sli_run('cgstart')
        for i in range(4):
            nest.sli_run('dup')
            nest.sli_run('cgnext')
            self.assertEqual(nest.sli_pop(), True)
            self.assertEqual(nest.sli_pop(), d)
            self.assertEqual(nest.sli_pop(), w)
            self.assertEqual(nest.sli_pop(), i)
            self.assertEqual(nest.sli_pop(), i)
        nest.sli_run('cgnext')
        self.assertEqual(nest.sli_pop(), False)
Beispiel #5
0
    def test_CSA_OneToOne_params(self):
        """One-to-one connectivity using CGConnect with paramters"""

        nest.ResetKernel()

        n_neurons = 4
        weight = 10000.0
        delay = 2.0

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a connection set with values for weight and delay
        cs = csa.cset(csa.oneToOne, weight, delay)

        # Connect sources and targets using the connection set cs and
        # a parameter map mapping weight to position 0 in the value
        # set and delay to position 1
        nest.CGConnect(sources, targets, cs, {"weight": 0, "delay": 1})

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets, weights and delays
            conns = nest.GetStatus(nest.GetConnections(sources[i]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i].get('global_id'))
            self.assertEqual(conns[0]["weight"], weight)
            self.assertEqual(conns[0]["delay"], delay)

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections(targets[i]))
            self.assertEqual(len(conns), 0)
Beispiel #6
0
    def test_CSA_OneToOne_tuples(self):
        """One-to-one connectivity using CGConnect with id tuples"""

        nest.ResetKernel()

        n_neurons = 4

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)

        # Connect sources and targets using the connection set
        # cs. This will internally call the variant of CGConnect that
        # takes lists
        nest.CGConnect(sources, targets, cg)

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets
            conns = nest.GetStatus(nest.GetConnections([sources[i]]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i])

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections([targets[i]]))
            self.assertEqual(len(conns), 0)
Beispiel #7
0
    def test_CSA_cgnext(self):
        """cgnext"""

        nest.ResetKernel()

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

        nest.sli_push(cs)
        nest.sli_run('dup')
        nest.sli_push(numpy.array([0, 1, 2, 3]))
        nest.sli_push(numpy.array([0, 1, 2, 3]))
        nest.sli_run('cgsetmask')
        nest.sli_run('dup')
        nest.sli_run('cgstart')
        for i in range(4):
            nest.sli_run('dup')
            nest.sli_run('cgnext')
            self.assertEqual(nest.sli_pop(), True)
            self.assertEqual(nest.sli_pop(), d)
            self.assertEqual(nest.sli_pop(), w)
            self.assertEqual(nest.sli_pop(), i)
            self.assertEqual(nest.sli_pop(), i)
        nest.sli_run('cgnext')
        self.assertEqual(nest.sli_pop(), False)
Beispiel #8
0
    def test_CSA_OneToOne_params(self):
        """One-to-one connectivity using CGConnect with paramters"""

        nest.ResetKernel()

        n_neurons = 4
        weight = 10000.0
        delay = 2.0

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a connection set with values for weight and delay
        cs = csa.cset(csa.oneToOne, weight, delay)

        # Connect sources and targets using the connection set cs and
        # a parameter map mapping weight to position 0 in the value
        # set and delay to position 1
        nest.CGConnect(sources, targets, cs, {"weight": 0, "delay": 1})

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets, weights and delays
            conns = nest.GetStatus(nest.GetConnections([sources[i]]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i])
            self.assertEqual(conns[0]["weight"], weight)
            self.assertEqual(conns[0]["delay"], delay)

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections([targets[i]]))
            self.assertEqual(len(conns), 0)
    def test_Conngen_OneToOne_params(self):
        """One-to-one connectivity using conngen Connect with parameters"""

        nest.ResetKernel()

        n_neurons = 4
        weight = 10000.0
        delay = 2.0

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a connection set with values for weight and delay
        cg = csa.cset(csa.oneToOne, weight, delay)

        # Connect sources and targets using the connection set cs and
        # a parameter map mapping weight to position 0 in the value
        # set and delay to position 1
        params_map = {"weight": 0, "delay": 1}
        connspec = {"rule": "conngen", "cg": cg, "params_map": params_map}
        nest.Connect(sources, targets, connspec)

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets, weights and delays
            conns = nest.GetConnections(sources[i])
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns.target, targets[i].get('global_id'))
            self.assertEqual(conns.weight, weight)
            self.assertEqual(conns.delay, delay)

            # We expect the targets to have no connections at all
            conns = nest.GetConnections(targets[i])
            self.assertEqual(len(conns), 0)
    def test_Conngen_error_weight_and_delay_in_synspec_and_conngen(self):
        """
        Error handling for conflicting weight/delay in conngen Connect
        """

        nest.ResetKernel()

        cg = csa.cset(csa.oneToOne, 10000.0, 2.0)
        params_map = {"weight": 0, "delay": 1}
        connspec = {"rule": "conngen", "cg": cg, "params_map": params_map}

        synspec_w = {'weight': 10.0}
        synspec_d = {'delay': 10.0}
        synspec_wd = {'weight': 10.0, 'delay': 10.0}

        n_neurons = 4

        pop = nest.Create("iaf_psc_alpha", n_neurons)

        self.assertRaisesRegex(nest.kernel.NESTError, "BadProperty",
                               nest.Connect, pop, pop, connspec, synspec_w)

        self.assertRaisesRegex(nest.kernel.NESTError, "BadProperty",
                               nest.Connect, pop, pop, connspec, synspec_d)

        self.assertRaisesRegex(nest.kernel.NESTError, "BadProperty",
                               nest.Connect, pop, pop, connspec, synspec_wd)
Beispiel #11
0
    def test_CSA_OneToOne_intvectors(self):
        """One-to-one connectivity using CGConnect with id intvectors"""

        nest.ResetKernel()

        n_neurons = 4

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)

        # Connect sources and targets (both converted to NumPy arrays)
        # using the connection set cs. This will internally call the
        # variant of CGConnect that takes intvector instead of lists
        nest.CGConnect(numpy.array(sources), numpy.array(targets), cg)

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets
            conns = nest.GetStatus(nest.GetConnections(sources[i]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i].get('global_id'))

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections(targets[i]))
            self.assertEqual(len(conns), 0)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
0
    def test_CSA_cgnext(self):
        """cgnext"""

        nest.ResetKernel()

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

        kernel.pushsli(cs)
        kernel.runsli('dup')
        kernel.pushsli(numpy.array([0, 1, 2, 3]))
        kernel.pushsli(numpy.array([0, 1, 2, 3]))
        kernel.runsli('cgsetmask_cg_a_a')
        kernel.runsli('dup')
        kernel.runsli('cgstart')
        for i in xrange(4):
            kernel.runsli('dup')
            kernel.runsli('cgnext')
            self.assertEqual(kernel.popsli(), True)
            self.assertEqual(kernel.popsli(), d)
            self.assertEqual(kernel.popsli(), w)
            self.assertEqual(kernel.popsli(), i)
            self.assertEqual(kernel.popsli(), i)
        kernel.runsli('cgnext')
        self.assertEqual(kernel.popsli(), False)
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)
Beispiel #16
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)
    def test_Conngen_OneToOne_synmodel(self):
        """One-to-one connectivity using conngen Connect and synapse_model"""

        nest.ResetKernel()

        n_neurons = 4
        synmodel = "stdp_synapse"
        tau_plus = 10.0

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)

        # Connect with a non-standard synapse model
        connspec = {"rule": "conngen", "cg": cg}
        synspec = {'synapse_model': synmodel, "tau_plus": tau_plus}
        nest.Connect(sources, targets, connspec, synspec)

        for i in range(n_neurons):
            # We expect all connections to have the correct targets
            # and the non-standard synapse model set
            conns = nest.GetConnections(sources[i])
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns.target, targets[i].get('global_id'))
            self.assertEqual(conns.synapse_model, synmodel)
            self.assertEqual(conns.tau_plus, tau_plus)

            # We expect the targets to have no connections at all
            conns = nest.GetConnections(targets[i])
            self.assertEqual(len(conns), 0)
Beispiel #18
0
    def test_CSA_OneToOne_synmodel(self):
        """One-to-one connectivity using CGConnect with synmodel"""

        nest.ResetKernel()

        n_neurons = 4
        synmodel = "stdp_synapse"

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cs = csa.cset(csa.oneToOne)

        # Connect with a non-standard synapse model
        nest.CGConnect(sources, targets, cs, model=synmodel)

        for i in range(n_neurons):
            # We expect all connections to have the correct targets
            # and the non-standard synapse model set
            conns = nest.GetStatus(nest.GetConnections([sources[i]]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i])
            self.assertEqual(conns[0]["synapse_model"], synmodel)

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections([targets[i]]))
            self.assertEqual(len(conns), 0)
Beispiel #19
0
    def test_CSA_OneToOne_tuples(self):
        """One-to-one connectivity using CGConnect with id tuples"""

        nest.ResetKernel()

        n_neurons = 4

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)

        # Connect sources and targets using the connection set
        # cs. This will internally call the variant of CGConnect that
        # takes lists
        nest.CGConnect(sources, targets, cg)

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets
            conns = nest.GetStatus(nest.GetConnections(sources[i]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i].get('global_id'))

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections(targets[i]))
            self.assertEqual(len(conns), 0)
Beispiel #20
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 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)
Beispiel #21
0
    def test_CSA_OneToOne_synmodel(self):
        """One-to-one connectivity using CGConnect with synmodel"""

        nest.ResetKernel()

        n_neurons = 4
        synmodel = "stdp_synapse"

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cs = csa.cset(csa.oneToOne)

        # Connect with a non-standard synapse model
        nest.CGConnect(sources, targets, cs, model=synmodel)

        for i in range(n_neurons):
            # We expect all connections to have the correct targets
            # and the non-standard synapse model set
            conns = nest.GetStatus(nest.GetConnections(sources[i]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i].get('global_id'))
            self.assertEqual(conns[0]["synapse_model"], synmodel)

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections(targets[i]))
            self.assertEqual(len(conns), 0)
Beispiel #22
0
    def test_CSA_OneToOne_intvectors(self):
        """One-to-one connectivity using CGConnect with id intvectors"""

        nest.ResetKernel()

        n_neurons = 4

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)

        # Connect sources and targets (both converted to NumPy arrays)
        # using the connection set cs. This will internally call the
        # variant of CGConnect that takes intvector instead of lists
        nest.CGConnect(numpy.array(sources), numpy.array(targets), cg)

        for i in range(n_neurons):
            # We expect all connections from sources to have the
            # correct targets
            conns = nest.GetStatus(nest.GetConnections([sources[i]]))
            self.assertEqual(len(conns), 1)
            self.assertEqual(conns[0]["target"], targets[i])

            # We expect the targets to have no connections at all
            conns = nest.GetStatus(nest.GetConnections([targets[i]]))
            self.assertEqual(len(conns), 0)
Beispiel #23
0
    def test_CSA_cgnext(self):
        """cgnext"""

        nest.ResetKernel()

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

        kernel.pushsli(cs)
        kernel.runsli('dup')
        kernel.pushsli(numpy.array([0,1,2,3]))
        kernel.pushsli(numpy.array([0,1,2,3]))
        kernel.runsli('cgsetmask_cg_a_a')
        kernel.runsli('dup')
        kernel.runsli('cgstart')
        for i in xrange(4):
            kernel.runsli('dup')
            kernel.runsli('cgnext')
            self.assertEqual(kernel.popsli(), True)
            self.assertEqual(kernel.popsli(), d)
            self.assertEqual(kernel.popsli(), w)
            self.assertEqual(kernel.popsli(), i)
            self.assertEqual(kernel.popsli(), i)
        kernel.runsli('cgnext')
        self.assertEqual(kernel.popsli(), False)
    def _connect(self):
        '''Connect populations.'''

        sigma = self._params['sigma']
        cutoff = self._max_dist
        self._cs = csa.cset(
            csa.cross([0], xrange(self._N - 1)) *
            (csa.random * (csa.gaussian(sigma, cutoff) * self._d)), 1.0, 1.0)
Beispiel #25
0
    def test_CSA_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 = csa.cset(csa.oneToOne)

        self.assertRaisesRegex(nest.NESTError, "BadProperty", nest.CGConnect, pop0, pop1, cg)
Beispiel #26
0
    def test_CSA_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 = csa.cset(csa.oneToOne)

        self.assertRaisesRegex(nest.NESTError, "BadProperty", nest.CGConnect,
                               pop0, pop1, cg)
Beispiel #27
0
    def test_CSA_error_unknown_nodes(self):
        """Error handling of CGConnect in case of unknown nodes"""

        nest.ResetKernel()

        # Create a plain connection set
        cs = csa.cset(csa.oneToOne)

        nonnodes = [1, 2, 3]

        # We expect CGConnect to fail with an UnknownNode exception if
        # unknown nodes are given
        self.assertRaisesRegex(nest.NESTError, "UnknownNode",
                               nest.CGConnect, nonnodes, nonnodes, cs)
Beispiel #28
0
    def test_CSA_error_unknown_nodes(self):
        """Error handling of CGConnect in case of unknown nodes"""

        nest.ResetKernel()

        # Create a plain connection set
        cs = csa.cset(csa.oneToOne)

        nonnodes = [1, 2, 3]

        # We expect CGConnect to fail with an UnknownNode exception if
        # unknown nodes are given
        self.assertRaisesRegex(nest.kernel.NESTError, "UnknownNode",
                               nest.CGConnect, nonnodes, nonnodes, cs)
    def test_Conngen_error_collocated_synapses(self):
        """
        Error handling for collocated synapses in conngen Connect
        """

        nest.ResetKernel()

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)
        connspec = {"rule": "conngen", "cg": cg}
        synspec = nest.CollocatedSynapses({'weight': -2.}, {'weight': 2.})

        pop = nest.Create('iaf_psc_alpha', 3)

        self.assertRaisesRegex(nest.kernel.NESTError, "BadProperty",
                               nest.Connect, pop, pop, connspec, synspec)
    def _connect(self):
        '''Connect populations.'''

        g1 = self._geometryFunction(self._ls)
        g2 = self._geometryFunction(self._lt)
        d = csa.euclidMetric2d(g1, g2)
        sigma = self._params['sigma']
        cutoff = self._max_dist
        cs = csa.cset(
            csa.cross([0], xrange(self._N - 1)) *
            (csa.random * (csa.gaussian(sigma, cutoff) * d)), 1.0, 1.0)
        nest.CGConnect(
            nest.GetLeaves(self._ls)[0],
            nest.GetLeaves(self._lt)[0], cs, {
                'weight': 0,
                'delay': 1
            })
    def test_Conngen_error_unknown_synapse(self):
        """
        Error handling for unknown synapse model in conngen Connect
        """

        nest.ResetKernel()

        # Create a plain connection set
        cg = csa.cset(csa.oneToOne)
        connspec = {"rule": "conngen", "cg": cg}
        synspec = {'synapse_model': "fantasy_synapse"}

        n_neurons = 4

        pop = nest.Create("iaf_psc_alpha", n_neurons)

        self.assertRaisesRegex(nest.kernel.NESTError, "UnknownSynapseType",
                               nest.Connect, pop, pop, connspec, synspec)
Beispiel #32
0
    def test_CSA_error_unknown_synapse(self):
        """Error handling of CGConnect in case of unknown synapse model"""

        nest.ResetKernel()

        # Create a plain connection set
        cs = csa.cset(csa.oneToOne)

        n_neurons = 4

        sources = nest.Create("iaf_psc_alpha", n_neurons)
        targets = nest.Create("iaf_psc_alpha", n_neurons)

        # We expect CGConnect to fail with an UnknownSynapseType
        # exception if an unknown synapse model is given
        self.assertRaisesRegex(nest.NESTError, "UnknownSynapseType",
                               nest.CGConnect, sources, targets, cs,
                               model="nonexistent_synapse")
Beispiel #33
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)
Beispiel #34
0
    def test_CSA_OneToOne_idrange(self):
        """One-to-one connectivity with id ranges"""

        nest.ResetKernel()

        n = 4 # number of neurons

        sources = nest.Create("iaf_neuron", n)
        targets = nest.Create("iaf_neuron", n)

        cg = csa.cset(csa.oneToOne)

        nest.CGConnect (sources, targets, cg)

        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)
Beispiel #35
0
def csa_topology_example():

    # layers have 20x20 neurons and extent 1 x 1
    pop1 = topo.CreateLayer({'elements': 'iaf_neuron',
                             'rows': 20, 'columns': 20})
    pop2 = topo.CreateLayer({'elements': 'iaf_neuron',
                             'rows': 20, 'columns': 20})

    # create CSA-style geometry functions and metric
    g1 = geometryFunction(pop1)
    g2 = geometryFunction(pop2)
    d = csa.euclidMetric2d(g1, g2)

    # Gaussian connectivity profile, sigma = 0.2, cutoff at 0.5
    cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0)

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

    # show targets of center neuron
    topo.PlotTargets(topo.FindCenterElement(pop1), pop2)
Beispiel #36
0
    def test_CSA_OneToOne_idrange(self):
        """One-to-one connectivity with id ranges"""

        nest.ResetKernel()

        n = 4  # number of neurons

        sources = nest.Create("iaf_neuron", n)
        targets = nest.Create("iaf_neuron", n)

        cg = csa.cset(csa.oneToOne)

        nest.CGConnect(sources, targets, cg)

        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)
Beispiel #37
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)
Beispiel #38
0
    import csa
    haveCSA = True
except ImportError:
    print("This example requires CSA to be installed in order to run.\n"
          + "Please make sure you compiled NEST using --with-libneurosim=PATH\n"
          + "and CSA and libneurosim are available from PYTHONPATH.")
    import sys
    sys.exit()

"""
To set up the connectivity, We create a ``random`` connection set
with a probability of 0.1 and two associated values (10000.0 and 1.0)
used as weight and delay, respectively.
"""

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

"""
Using the `Create` command from PyNEST, we create the neurons of
the pre- and postsynaptic populations, each of which containing 16
neurons.
"""

pre = nest.Create("iaf_neuron", 16)
post = nest.Create("iaf_neuron", 16)

"""
We can now connect the populations using the `CGConnect` function.
It takes the IDs of pre- and postsynaptic neurons (``pre`` and
``post``), the connection set (``cs``) and a dictionary that maps
the parameters weight and delay to positions in the value set
Beispiel #39
0
})
"""
For each layer, we create a CSA-style geometry function and a CSA
metric based on them.
"""

g1 = geometryFunction(pop1)
g2 = geometryFunction(pop2)
d = csa.euclidMetric2d(g1, g2)
"""
The connection set ``cs`` describes a Gaussian connectivity profile
with sigma = 0.2 and cutoff at 0.5, and two values (10000.0 and 1.0)
used as weight and delay, respectively.
"""

cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0)
"""
We can now connect the populations using the `CGConnect` function.
It takes the IDs of pre- and postsynaptic neurons (``pop1`` and
``pop2``), the connection set (``cs``) and a dictionary that maps
the parameters weight and delay to positions in the value set
associated with the connection set.
"""

# This is a work-around until NEST 3.0 is released. It will issue a deprecation
# warning.
pop1_gids = nest.GetLeaves(pop1)[0]
pop2_gids = nest.GetLeaves(pop2)[0]

nest.CGConnect(pop1_gids, pop2_gids, cs, {"weight": 0, "delay": 1})
"""
Beispiel #40
0
exc_cells = all_cells[:n_exc]
inh_cells = all_cells[n_exc:]
if benchmark == "COBA":
    ext_stim = Population(20, SpikeSourcePoisson, {'rate' : rate, 'duration' : stim_dur}, label="expoisson")
    rconn = 0.01
    ext_conn = FixedProbabilityConnector(rconn, weights=0.1)

print "%s Initialising membrane potential to random values..." % node_id
rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
uniformDistr = RandomDistribution('uniform', [v_reset,v_thresh], rng=rng)
all_cells.initialize('v', uniformDistr)

print "%s Connecting populations..." % node_id
#exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay)
#inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay)
exc_conn = CSAConnector(csa.cset (csa.random (pconn), w_exc, delay))
inh_conn = CSAConnector(csa.cset (csa.random (pconn), w_inh, delay))

connections={}
connections['exc'] = Projection(exc_cells, all_cells, exc_conn, target='excitatory', rng=rng)
connections['inh'] = Projection(inh_cells, all_cells, inh_conn, target='inhibitory', rng=rng)
if (benchmark == "COBA"):
    connections['ext'] = Projection(ext_stim, all_cells, ext_conn, target='excitatory')

# === Setup recording ==========================================================
print "%s Setting up recording..." % node_id
all_cells.record()
vrecord_list = [exc_cells[0],exc_cells[1]]
exc_cells.record_v(vrecord_list)

buildCPUTime = timer.diff()
Beispiel #41
0
    import csa
    haveCSA = True
except ImportError:
    print(
        "This example requires CSA to be installed in order to run.\n" +
        "Please make sure you compiled NEST using --with-libneurosim=PATH\n" +
        "and CSA and libneurosim are available from PYTHONPATH.")
    import sys
    sys.exit()
"""
To set up the connectivity, We create a ``random`` connection set
with a probability of 0.1 and two associated values (10000.0 and 1.0)
used as weight and delay, respectively.
"""

cs = csa.cset(csa.random(0.1), 10000.0, 1.0)
"""
Using the `Create` command from PyNEST, we create the neurons of
the pre- and postsynaptic populations, each of which containing 16
neurons.
"""

pre = nest.Create("iaf_neuron", 16)
post = nest.Create("iaf_neuron", 16)
"""
We can now connect the populations using the `CGConnect` function.
It takes the IDs of pre- and postsynaptic neurons (``pre`` and
``post``), the connection set (``cs``) and a dictionary that maps
the parameters weight and delay to positions in the value set
associated with the connection set.
"""
Beispiel #42
0
    ext_conn = sim.FixedProbabilityConnector(rconn)
    ext_syn = sim.StaticSynapse(weight=0.1)

print("%s Initialising membrane potential to random values..." % node_id)
rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
uniformDistr = RandomDistribution('uniform', low=v_reset, high=v_thresh, rng=rng)
if options.use_views:
    all_cells.initialize(v=uniformDistr)
else:
    exc_cells.initialize(v=uniformDistr)
    inh_cells.initialize(v=uniformDistr)

print("%s Connecting populations..." % node_id)
progress_bar = ProgressBar(width=20)
if options.use_csa:
    connector = CSAConnector(csa.cset(csa.random(pconn)))
else:
    connector = sim.FixedProbabilityConnector(pconn, rng=rng, callback=progress_bar)
exc_syn = sim.StaticSynapse(weight=w_exc, delay=delay)
inh_syn = sim.StaticSynapse(weight=w_inh, delay=delay)

connections = {}
if options.use_views or options.use_assembly:
    connections['exc'] = sim.Projection(exc_cells, all_cells, connector, exc_syn, receptor_type='excitatory')
    connections['inh'] = sim.Projection(inh_cells, all_cells, connector, inh_syn, receptor_type='inhibitory')
    if (options.benchmark == "COBA"):
        connections['ext'] = sim.Projection(ext_stim, all_cells, ext_conn, ext_syn, receptor_type='excitatory')
else:
    connections['e2e'] = sim.Projection(exc_cells, exc_cells, connector, exc_syn, receptor_type='excitatory')
    connections['e2i'] = sim.Projection(exc_cells, inh_cells, connector, exc_syn, receptor_type='excitatory')
    connections['i2e'] = sim.Projection(inh_cells, exc_cells, connector, inh_syn, receptor_type='inhibitory')
"""
For each layer, we create a CSA-style geometry function and a CSA
metric based on them.
"""

g1 = geometryFunction(pop1)
g2 = geometryFunction(pop2)
d = csa.euclidMetric2d(g1, g2)

"""
The connection set ``cs`` describes a Gaussian connectivity profile
with sigma = 0.2 and cutoff at 0.5, and two values (10000.0 and 1.0)
used as weight and delay, respectively.
"""

cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0)

"""
We can now connect the populations using the `CGConnect` function.
It takes the IDs of pre- and postsynaptic neurons (``pop1`` and
``pop2``), the connection set (``cs``) and a dictionary that maps
the parameters weight and delay to positions in the value set
associated with the connection set.
"""

# This is a work-around until NEST 3.0 is released. It will issue a deprecation
# warning.
pop1_gids = nest.GetLeaves(pop1)[0]
pop2_gids = nest.GetLeaves(pop2)[0]

nest.CGConnect(pop1_gids, pop2_gids, cs, {"weight": 0, "delay": 1})
Beispiel #44
0
    def _connect(self):
        '''Connect populations.'''

        finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t))
        cs = csa.cset(csa.random(p=self._p) * finite_set)
        nest.CGConnect(self._source_pop, self._target_pop, csa.cset(cs))
Beispiel #45
0
print("%s Initialising membrane potential to random values..." % node_id)
rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
uniformDistr = RandomDistribution('uniform',
                                  low=v_reset,
                                  high=v_thresh,
                                  rng=rng)
if options.use_views:
    all_cells.initialize(v=uniformDistr)
else:
    exc_cells.initialize(v=uniformDistr)
    inh_cells.initialize(v=uniformDistr)

print("%s Connecting populations..." % node_id)
progress_bar = ProgressBar(width=20)
if options.use_csa:
    connector = sim.CSAConnector(csa.cset(csa.random(pconn)))
else:
    connector = sim.FixedProbabilityConnector(pconn,
                                              rng=rng,
                                              callback=progress_bar)
exc_syn = sim.StaticSynapse(weight=w_exc, delay=delay)
inh_syn = sim.StaticSynapse(weight=w_inh, delay=delay)

connections = {}
if options.use_views or options.use_assembly:
    connections['exc'] = sim.Projection(exc_cells,
                                        all_cells,
                                        connector,
                                        exc_syn,
                                        receptor_type='excitatory')
    connections['inh'] = sim.Projection(inh_cells,
    def _connect(self):
        '''Connect populations.'''

        finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t))
        self._cs = csa.cset(csa.random(p=self._p) * finite_set)
Beispiel #47
0
                              'rate': rate,
                              'duration': stim_dur
                          },
                          label="expoisson")
    rconn = 0.01
    ext_conn = FixedProbabilityConnector(rconn, weights=0.1)

print "%s Initialising membrane potential to random values..." % node_id
rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
uniformDistr = RandomDistribution('uniform', [v_reset, v_thresh], rng=rng)
all_cells.initialize('v', uniformDistr)

print "%s Connecting populations..." % node_id
#exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay)
#inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay)
exc_conn = CSAConnector(csa.cset(csa.random(pconn), w_exc, delay))
inh_conn = CSAConnector(csa.cset(csa.random(pconn), w_inh, delay))

connections = {}
connections['exc'] = Projection(exc_cells,
                                all_cells,
                                exc_conn,
                                target='excitatory',
                                rng=rng)
connections['inh'] = Projection(inh_cells,
                                all_cells,
                                inh_conn,
                                target='inhibitory',
                                rng=rng)
if (benchmark == "COBA"):
    connections['ext'] = Projection(ext_stim,
Beispiel #48
0
    ext_stim = Population(20, SpikeSourcePoisson(rate=rate, duration=stim_dur), label="expoisson")
    rconn = 0.01
    ext_conn = FixedProbabilityConnector(rconn)
    syn = StaticSynapse(weight=0.1)

print "%s Initialising membrane potential to random values..." % node_id
rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
uniformDistr = RandomDistribution('uniform', low=v_reset, high=v_thresh, rng=rng)
all_cells.initialize(v=uniformDistr)

print "%s Connecting populations..." % node_id
#exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay)
#inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay)
exc_syn = StaticSynapse(weight=w_exc, delay=delay)
inh_syn = StaticSynapse(weight=w_inh, delay=delay)
exc_conn = CSAConnector(csa.cset (csa.random (pconn)))
inh_conn = CSAConnector(csa.cset (csa.random (pconn)))

connections={}
connections['exc'] = Projection(exc_cells, all_cells, exc_conn, exc_syn, receptor_type='excitatory')
connections['inh'] = Projection(inh_cells, all_cells, inh_conn, inh_syn, receptor_type='inhibitory')
if (benchmark == "COBA"):
    connections['ext'] = Projection(ext_stim, all_cells, ext_conn, syn, receptor_type='excitatory')

# === Setup recording ==========================================================
print "%s Setting up recording..." % node_id
all_cells.record('spikes')
exc_cells[0:2].record('v')

buildCPUTime = timer.diff()
Beispiel #49
0
print "Process with rank %d running on %s" % (node, socket.gethostname())


rng = NumpyRNG(seed=seed, parallel_safe=True)

print "[%d] Creating populations" % node
n_spikes = int(2*tstop*input_rate/1000.0)
spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential',
                                            [1000.0/input_rate], mask_local=False))

input_population  = Population(10, SpikeSourceArray, {'spike_times': spike_times }, label="input")
output_population = Population(10, IF_curr_exp, cell_params, label="output")

g=csa.grid2d(3)
d=csa.euclidMetric2d(g,g)
connector = CSAConnector(csa.cset(csa.random(0.5), csa.gaussian(0.1,1.0)*d, 1.0))

projection = Projection(input_population, output_population, connector, rng=rng)

file_stem = "Results/simpleRandomNetwork_np%d_%s" % (num_processes(), simulator_name)
projection.saveConnections('%s.conn' % file_stem)

output_population.record_v()

print "[%d] Running simulation" % node
run(tstop)

print "[%d] Writing Vm to disk" % node
output_population.print_v('%s.v' % file_stem)

print "[%d] Finishing" % node