Beispiel #1
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 #2
0
        def connect(self, projection):
            """Connect-up a Projection."""

            presynaptic_cells = projection.pre.all_cells.astype('int64')
            postsynaptic_cells = projection.post.all_cells.astype('int64')

            if csa.arity(self.cset) == 2:
                param_map = {'weight': 0, 'delay': 1}
                nest.CGConnect(presynaptic_cells, postsynaptic_cells, self.cset,
                               param_map, projection.nest_synapse_model)
            else:
                nest.CGConnect(presynaptic_cells, postsynaptic_cells, self.cset,
                               model=projection.nest_synapse_model)

            projection._connections = None  # reset the caching of the connection list, since this will have to be recalculated
            projection._sources.extend(presynaptic_cells)
Beispiel #3
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 #4
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 #5
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 #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].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)
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)
    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 _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 _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
            })
Beispiel #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)
Beispiel #12
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)
    def test_libcsa_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 = libcsa.oneToOne

        nest.CGConnect(sources, targets, cg)

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

            conns = nest.GetStatus(nest.GetConnections([targets[i]]), 'target')
            self.assertEqual(len(conns), 0)
Beispiel #14
0
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})
"""
Finally, we use the `PlotTargets` function to show all targets in
``pop2`` starting at the center neuron of ``pop1``.
"""

topo.PlotTargets(topo.FindCenterElement(pop1), pop2)
"""
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.
"""

nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1})
"""
Finally, we use the `PlotTargets` function to show all targets in
``pop2`` starting at the center neuron of ``pop1``.
"""

topo.PlotTargets(topo.FindCenterElement(pop1), pop2)
Beispiel #16
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.
"""

nest.CGConnect(pre, post, cs, {"weight": 0, "delay": 1})
"""
To stimulate the network, we create a `poisson_generator` and set it
up to fire with a rate of 100000 spikes per second. It is connected to
the neurons of the pre-synaptic population.
"""

pg = nest.Create("poisson_generator", params={"rate": 100000.0})
nest.Connect(pg, pre, "all_to_all")
"""
To measure and record the membrane potentials of the neurons, we
create a `voltmeter` and connect it to all post-synaptic nodes.
"""

vm = nest.Create("voltmeter")
nest.Connect(vm, post, "all_to_all")
Beispiel #17
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))