def test_GetTargetNodesPositions(self):
        """Interface check for finding targets."""
        ldict = {'elements': ['iaf_neuron', 'iaf_psc_alpha'], 'rows': 3, 'columns':3,
                 'extent': [2., 2.], 'edge_wrap': True}
        cdict = {'connection_type': 'divergent', 
                 'mask': {'grid': {'rows':2, 'columns':2}}}     
        nest.ResetKernel()
        l = topo.CreateLayer(ldict)
        ian = [gid for gid in nest.GetLeaves(l)[0]
               if nest.GetStatus([gid], 'model')[0] == 'iaf_neuron']
        ipa = [gid for gid in nest.GetLeaves(l)[0]
               if nest.GetStatus([gid], 'model')[0] == 'iaf_psc_alpha']
        
        # connect ian -> all using static_synapse
        cdict.update({'sources': {'model': 'iaf_neuron'},
                      'synapse_model': 'static_synapse'})
        topo.ConnectLayers(l, l, cdict)
        for k in ['sources', 'synapse_model']: cdict.pop(k)
        
        # connect ipa -> ipa using stdp_synapse
        cdict.update({'sources': {'model': 'iaf_psc_alpha'},
                      'targets': {'model': 'iaf_psc_alpha'},
                      'synapse_model': 'stdp_synapse'})
        topo.ConnectLayers(l, l, cdict)
        for k in ['sources', 'targets', 'synapse_model']: cdict.pop(k)
        
        t = topo.GetTargetNodes(ian[:1], l)
        self.assertEqual(len(t), 1)

        p = topo.GetTargetPositions(ian[:1], l)
        self.assertEqual(len(p), 1)
        self.assertTrue(all([len(pp)==2 for pp in p[0]]))
        
        t = topo.GetTargetNodes(ian, l)
        self.assertEqual(len(t), len(ian))
        self.assertTrue(all([len(g)==8 for g in t])) # 2x2 mask x 2 neurons / element -> eight targets  

        p = topo.GetTargetPositions(ian, l)
        self.assertEqual(len(p), len(ian))
        

        t = topo.GetTargetNodes(ian, l, tgt_model='iaf_neuron')
        self.assertEqual(len(t), len(ian))
        self.assertTrue(all([len(g)==4 for g in t])) # 2x2 mask  -> four targets  

        t = topo.GetTargetNodes(ian, l, tgt_model='iaf_psc_alpha')
        self.assertEqual(len(t), len(ian))
        self.assertTrue(all([len(g)==4 for g in t])) # 2x2 mask  -> four targets  

        t = topo.GetTargetNodes(ipa, l)
        self.assertEqual(len(t), len(ipa))
        self.assertTrue(all([len(g)==4 for g in t])) # 2x2 mask  -> four targets  

        t = topo.GetTargetNodes(ipa, l, syn_model='static_synapse')
        self.assertEqual(len(t), len(ipa))
        self.assertTrue(all([len(g)==0 for g in t])) # no static syns  

        t = topo.GetTargetNodes(ipa, l, syn_model='stdp_synapse')
        self.assertEqual(len(t), len(ipa))
        self.assertTrue(all([len(g)==4 for g in t])) # 2x2 mask  -> four targets  
Example #2
0
def get_Relative_Weight(params, radius):

    # Create a fictional network and count the number of target connections
    layerProps = {
        'rows': params['N'],
        'columns': params['N'],
        'extent': [params['visSize'], params['visSize']],
        'edge_wrap': True,
        'elements': 'iaf_cond_exp'
    }

    l = tp.CreateLayer(layerProps)

    dict = {
        "connection_type": "convergent",
        "mask": {
            "circular": {
                "radius": radius
            }
        },
        "kernel": 1.0,
        "weights": {
            "gaussian": {
                "p_center": 1.0,
                "sigma": radius / 3.0
            }
        }
    }

    tp.ConnectLayers(l, l, dict)
    ctr = tp.FindCenterElement(l)
    targets = tp.GetTargetNodes(ctr, l)

    #    print ("Number of targets = ",len(targets[0]))

    conn = nest.GetConnections(ctr, targets[0])
    st = nest.GetStatus(conn)

    w = 0.0
    for n in np.arange(len(st)):
        w += st[n]['weight']

#    print ("Total weight = ",w)

    return w, len(targets[0])
Example #3
0
    def stat_connections(self, source_layer, type):
        import time
        import nest.topology as tp

        t = time.time()
        targets = tp.GetTargetNodes(source_layer.ids, self.layer_id)

        m = []
        for trg in targets:
            m.append(len(trg))
        print time.time() - t

        t = time.time()
        m = []
        for id in source_layer.ids:
            m.append(len(my_topology.GetTargetNodes([id], self.layer_id)[0]))
        print time.time() - t

        print len(m)
        mean = numpy.mean(numpy.array(m))
        std = numpy.std(numpy.array(m))
        return mean, std
Example #4
0
# l1_children is a work-around until NEST 3.0 is released
l1_children = nest.hl_api.GetChildren(l1)[0]

# extract position information, transpose to list of x, y and z positions
xpos, ypos, zpos = zip(*topo.GetPosition(l1_children))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xpos, ypos, zpos, s=15, facecolor='b', edgecolor='none')

# Gaussian connections in full volume [-0.75,0.75]**3
topo.ConnectLayers(l1, l1,
                   {'connection_type': 'divergent', 'allow_autapses': False,
                    'mask': {'volume': {'lower_left': [-0.75, -0.75, -0.75],
                                        'upper_right': [0.75, 0.75, 0.75]}},
                    'kernel': {'gaussian': {'p_center': 1., 'sigma': 0.25}}})

# show connections from center element
# sender shown in red, targets in green
ctr = topo.FindCenterElement(l1)
xtgt, ytgt, ztgt = zip(*topo.GetTargetPositions(ctr, l1)[0])
xctr, yctr, zctr = topo.GetPosition(ctr)[0]
ax.scatter([xctr], [yctr], [zctr], s=40, facecolor='r', edgecolor='none')
ax.scatter(xtgt, ytgt, ztgt, s=40, facecolor='g', edgecolor='g')

tgts = topo.GetTargetNodes(ctr, l1)[0]
d = topo.Distance(ctr, tgts)

plt.figure()
plt.hist(d, 25)
# plt.show()
Example #5
0
    'allow_multapses': False,
    'allow_autapses': False,
    'connection_type': 'convergent',
    'mask': {
        'rectangular': {
            'lower_left': [-0.5, -0.5],
            'upper_right': [0.5, 0.5]
        }
    },
    'kernel': 0.5,
    'sources': {
        'model': 'iaf_neuron'
    },
    'targets': {
        'model': 'iaf_neuron'
    }
}

tp.ConnectLayers(l, l, projections)
tp.ConnectLayers(l_dummy1, l, projections)
tp.ConnectLayers(l_dummy2, l, projections)

if nest.version() == 'NEST 2.0.0':
    sources = nest.GetChildren(l)
if nest.version() == 'NEST 2.2.1':
    sources = nest.GetChildren(l)[0]

t = time.time()
targets = tp.GetTargetNodes(sources, l)
print time.time() - t
Example #6
0
    'connection_type': 'convergent',
    'mask': {
        'rectangular': {
            'lower_left': [-0.5, -0.5],
            'upper_right': [0.5, 0.5]
        }
    },
    'kernel': 0.5,
    'sources': {
        'model': 'iaf_neuron'
    },
    'targets': {
        'model': 'iaf_neuron'
    }
}

tp.ConnectLayers(l, l, projections)
tp.ConnectLayers(l_dummy1, l, projections)
tp.ConnectLayers(l_dummy2, l, projections)
tp.ConnectLayers(l_dummy3, l, projections)
t = time.time()
targets = tp.GetTargetNodes(nest.GetChildren(l)[0], l)
m = []
for trg in targets:
    m.append(len(trg))

print time.time() - t
print len(m)
#print tp.FindCenterElement(l)
#print nest.GetChildren(l)
#print nest.GetLeaves(l)