• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pattern.Pattern类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neurokernel.pattern.Pattern的典型用法代码示例。如果您正苦于以下问题:Python Pattern类的具体用法?Python Pattern怎么用?Python Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Pattern类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_dest_idx_dest_type

    def test_dest_idx_dest_type(self):
        p = Pattern('/[aaa,bbb][0:3]', '/[xxx,yyy][0:3]')
        p['/aaa[0]', '/yyy[0]'] = 1
        p['/aaa[0]', '/yyy[1]'] = 1
        p['/aaa[0]', '/yyy[2]'] = 1
        p['/xxx[0]', '/bbb[0]'] = 1
        p['/xxx[1]', '/bbb[1]'] = 1
        p['/xxx[2]', '/bbb[2]'] = 1
        p.interface['/aaa[0:3]', 'type'] = 'spike'
        p.interface['/yyy[0:3]', 'type'] = 'spike'
        self.assertItemsEqual(p.dest_idx(0, 1, dest_type='spike'), 
                              [('yyy', 0),
                               ('yyy', 1),
                               ('yyy', 2)])
        self.assertItemsEqual(p.dest_idx(0, 1, dest_type='gpot'), [])

        q = Pattern('/[aaa,bbb,ccc]', '/[www,xxx,yyy,zzz]')
        q['/aaa','/www'] = 1
        q['/aaa','/xxx'] = 1
        q['/yyy','/bbb'] = 1
        q['/zzz','/ccc'] = 1
        q.interface['/aaa'] = [0, 'in', 'spike']
        q.interface['/[www,xxx]'] = [1, 'out', 'spike']
        self.assertItemsEqual(q.dest_idx(0, 1, dest_type='spike'), 
                              [('www',),
                               ('xxx',)])
        self.assertItemsEqual(q.dest_idx(0, 1, dest_type='gpot'), [])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:27,代码来源:test_pattern.py


示例2: test_clear

 def test_clear(self):
     p = Pattern('/aaa[0:3]', '/bbb[0:3]')
     p['/aaa[0]', '/bbb[0]'] = 1
     p['/aaa[1]', '/bbb[1]'] = 1
     p['/aaa[2]', '/bbb[2]'] = 1
     p.clear()
     assert len(p) == 0
     assert len(p.interface) == 0
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:8,代码来源:test_pattern.py


示例3: create_pattern

def create_pattern(lpu1, lpu2):
    lpu1_sel = ','.join(['/'+'/'.join([str(i) for i in sel]) for sel in lpu1.interface.index.tolist()])
    lpu2_sel = ','.join(['/'+'/'.join([str(i) for i in sel]) for sel in lpu2.interface.index.tolist()])
    pat = Pattern(lpu1_sel, lpu2_sel)

    lpu1_sel_in_gpot = str(','.join( lpu1.interface.in_ports().gpot_ports().to_selectors() ))
    lpu1_sel_out_gpot = str(','.join( lpu1.interface.out_ports().gpot_ports().to_selectors() ))
    lpu2_sel_in_gpot = str(','.join( lpu2.interface.in_ports().gpot_ports().to_selectors() ))
    lpu2_sel_out_gpot = str(','.join( lpu2.interface.out_ports().gpot_ports().to_selectors() ))
    
    lpu1_sel_in_spike = str(','.join( lpu1.interface.in_ports().spike_ports().to_selectors() ))
    lpu1_sel_out_spike = str(','.join( lpu1.interface.out_ports().spike_ports().to_selectors() ))
    lpu2_sel_in_spike = str(','.join( lpu2.interface.in_ports().spike_ports().to_selectors() ))
    lpu2_sel_out_spike = str(','.join( lpu2.interface.out_ports().spike_ports().to_selectors() ))

    pat.interface[lpu1_sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
    pat.interface[lpu1_sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
    pat.interface[lpu2_sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
    pat.interface[lpu2_sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
    pat.interface[lpu1_sel_in_spike, 'io', 'type'] = ['in', 'spike']
    pat.interface[lpu1_sel_out_spike, 'io', 'type'] = ['out', 'spike']
    pat.interface[lpu2_sel_in_spike, 'io', 'type'] = ['in', 'spike']
    pat.interface[lpu2_sel_out_spike, 'io', 'type'] = ['out', 'spike']

    Neuron_list_12 = ['L1', 'L2', 'L3', 'L4', 'L5', 'T1']
    Neuron_list_21 = ['C2', 'C3']
    
    for i in range(768):
        for neuron in Neuron_list_12:
            pat['/lamina/cart'+str(i)+'/'+neuron, '/medulla/cart'+str(i)+'/'+neuron] = 1
        for neuron in Neuron_list_21:
            pat['/medulla/cart'+str(i)+'/'+neuron, '/lamina/cart'+str(i)+'/'+neuron] = 1
    with open('lam_med_pattern', 'wb') as pat_file:
        pickle.dump(pat, pat_file)
    return pat
开发者ID:MariyaS,项目名称:neurokernel,代码行数:35,代码来源:vision_configuration.py


示例4: test_connected_port_pairs

 def test_connected_port_pairs(self):
     p = Pattern('/aaa[0:3]', '/bbb[0:3]')
     p['/aaa[0]', '/bbb[2]'] = 1
     p['/aaa[1]', '/bbb[0]'] = 1
     p['/aaa[2]', '/bbb[1]'] = 1
     self.assertSequenceEqual(p.connected_port_pairs(),
                              [(('aaa', 0), ('bbb', 2)),
                               (('aaa', 1), ('bbb', 0)),
                               (('aaa', 2), ('bbb', 1))])
     self.assertSequenceEqual(p.connected_port_pairs(True),
                              [('/aaa/0', '/bbb/2'),
                               ('/aaa/1', '/bbb/0'),
                               ('/aaa/2', '/bbb/1')])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:13,代码来源:test_pattern.py


示例5: test_from_concat

    def test_from_concat(self):
        # Need to specify selectors for both interfaces in pattern:
        self.assertRaises(ValueError, Pattern.from_concat, '', '/[baz,qux]',
                          from_sel='', to_sel='/[baz,qux]', data=1)

        # Patterns with interfaces using selectors with 1 level:
        p = Pattern.from_concat('/[foo,bar]', '/[baz,qux]',
                                from_sel='/[foo,bar]', to_sel='/[baz,qux]',
                                data=1)
        df = pd.DataFrame(data=[1, 1],
                          index=pd.MultiIndex(levels=[['bar', 'foo'], ['baz', 'qux']],
                                              labels=[[1, 0], [0, 1]],
                                              names=['from_0', 'to_0'], dtype=object),
                          columns=['conn'], dtype=object)
        assert_frame_equal(p.data, df)

        # Patterns with interfaces using selectors with more than 1 level:
        p = Pattern.from_concat('/foo[0:2]', '/bar[0:2]',
                                from_sel='/foo[0:2]', to_sel='/bar[0:2]',
                                data=1)
        df = pd.DataFrame(data=[1, 1],
                          index=pd.MultiIndex(levels=[['foo'], [0, 1], ['bar'], [0, 1]],
                                              labels=[[0, 0], [0, 1], [0, 0], [0, 1]],
                                              names=['from_0', 'from_1', 'to_0', 'to_1'], 
                                              dtype=object),
                          columns=['conn'], dtype=object)
        assert_frame_equal(p.data, df)

        # Patterns where port types are specified:
        p = Pattern.from_concat('/foo[0:2]', '/bar[0:2]',
                                from_sel='/foo[0:2]', to_sel='/bar[0:2]',
                                gpot_sel='/foo[0],/bar[0]',
                                spike_sel='/foo[1:2],/bar/[1:2]',
                                data=1)
        df_int = pd.DataFrame({'interface': [0, 0, 1, 1],
                               'io': ['in', 'in', 'out', 'out'],
                               'type': ['gpot', 'spike', 'gpot', 'spike']},
                              index=pd.MultiIndex(levels=[['bar', 'foo'], [0, 1]],
                                                  labels=[[1, 1, 0, 0], [0, 1, 0, 1]],
                                                  names=[u'0', u'1'],
                                                  dtype=object),
                              dtype=object)
        df = pd.DataFrame(data=[1, 1],
                          index=pd.MultiIndex(levels=[['foo'], [0, 1], ['bar'], [0, 1]],
                                              labels=[[0, 0], [0, 1], [0, 0], [0, 1]],
                                              names=['from_0', 'from_1', 'to_0', 'to_1'], 
                                              dtype=object),
                          columns=['conn'],
                          dtype=object)
        assert_frame_equal(p.data, df)
        assert_frame_equal(p.interface.data, df_int)
开发者ID:CEPBEP,项目名称:neurokernel,代码行数:51,代码来源:test_pattern.py


示例6: test_create

 def test_create(self):
     p = Pattern('/foo[0:5]', '/bar[0:5]')
     p['/foo[0]', '/bar[0]'] = 1
     p['/foo[1]', '/bar[1]'] = 1
     p['/foo[1]', '/bar[2]'] = 1
     p['/bar[3]', '/foo[2]'] = 1
     p['/bar[3]', '/foo[3]'] = 1
     p['/bar[4]', '/foo[4]'] = 1
     assert_frame_equal(p.data, self.df_p)
     p.interface['/foo[0:2]', 'type'] = 'spike'
     p.interface['/bar[0:2]', 'type'] = 'spike'
     p.interface['/foo[2:5]', 'type'] = 'gpot'
     p.interface['/bar[3:5]', 'type'] = 'gpot'
     assert_frame_equal(p.interface.data, self.df_i)
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:14,代码来源:test_pattern.py


示例7: test_connected_ports

 def test_connected_ports(self):
     p = Pattern('/foo[0:3]', '/bar[0:3]')
     p['/foo[0]', '/bar[0]'] = 1
     p['/foo[1]', '/bar[1]'] = 1
     self.assertItemsEqual(p.connected_ports(tuples=True),
                           [('bar', 0),
                            ('bar', 1),
                            ('foo', 0),
                            ('foo', 1)])
     self.assertItemsEqual(p.connected_ports(0, True),
                           [('foo', 0),
                            ('foo', 1)])
     self.assertItemsEqual(p.connected_ports(1, True),
                           [('bar', 0),
                            ('bar', 1)])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:15,代码来源:test_pattern.py


示例8: test_from_graph

    def test_from_graph(self):
        p = Pattern('/foo[0:4]', '/bar[0:4]')
        p['/foo[0]', '/bar[0]'] = 1
        p['/foo[0]', '/bar[1]'] = 1
        p['/foo[1]', '/bar[2]'] = 1
        p['/bar[3]', '/foo[2]'] = 1
        p['/bar[3]', '/foo[3]'] = 1

        g = nx.DiGraph()
        g.add_node('/bar[0]', interface=1, io='out')
        g.add_node('/bar[1]', interface=1, io='out')
        g.add_node('/bar[2]', interface=1, io='out')
        g.add_node('/bar[3]', interface=1, io='in')
        g.add_node('/foo[0]', interface=0, io='in')
        g.add_node('/foo[1]', interface=0, io='in')
        g.add_node('/foo[2]', interface=0, io='out')
        g.add_node('/foo[3]', interface=0, io='out')
        g.add_edge('/foo[0]', '/bar[0]')
        g.add_edge('/foo[0]', '/bar[1]')
        g.add_edge('/foo[1]', '/bar[2]')
        g.add_edge('/bar[3]', '/foo[2]')
        g.add_edge('/bar[3]', '/foo[3]')

        pg = Pattern.from_graph(g)
        assert_frame_equal(pg.data.sort(), p.data.sort())
        assert_frame_equal(pg.interface.data.sort(), p.interface.data.sort())
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:26,代码来源:test_pattern.py


示例9: update_pattern_master_worker

    def update_pattern_master_worker(self, j, worker_num):
        indexes = self.get_worker_nodes(j, worker_num)
        
        master_selectors = self.get_master_selectors()
        worker_selectors = self.get_worker_selectors(j, worker_num)
        
        from_list = []
        to_list = []

        for i, ind in enumerate(indexes):
            col_m = ind // 6
            ind_m = 1 + (ind % 6)
            src = '/master/{}/buf{}'.format(col_m, ind_m)
            dest = '/ret/{}/in{}'.format(col_m, ind_m)
            from_list.append(src)
            to_list.append(dest)
            
            src = '/ret/{}/R{}'.format(col_m, ind_m)
            dest = '/master/{}/R{}'.format(col_m, ind_m)
            
            from_list.append(src)
            to_list.append(dest)

        pattern = Pattern.from_concat(','.join(master_selectors),
                                      ','.join(worker_selectors),
                                      from_sel = ','.join(from_list),
                                      to_sel = ','.join(to_list),
                                      gpot_sel = ','.join(from_list+to_list))
        return pattern
开发者ID:neurokernel,项目名称:retina,代码行数:29,代码来源:retina.py


示例10: test_src_idx_dest_ports

    def test_src_idx_dest_ports(self):
        p = Pattern('/[aaa,bbb][0:3]', '/[xxx,yyy][0:3]')
        p['/aaa[0]', '/yyy[0]'] = 1
        p['/aaa[0]', '/yyy[1]'] = 1
        p['/aaa[0]', '/yyy[2]'] = 1
        p['/xxx[0]', '/bbb[0]'] = 1
        p['/xxx[1]', '/bbb[1]'] = 1
        p['/xxx[2]', '/bbb[2]'] = 1
        self.assertItemsEqual(p.src_idx(0, 1, dest_ports='/yyy[0]'),
                              [('aaa', 0)])

        q = Pattern('/[aaa,bbb]', '/[www,xxx,yyy]')
        q['/aaa','/www'] = 1
        q['/aaa','/xxx'] = 1
        q['/bbb','/yyy'] = 1
        self.assertItemsEqual(q.src_idx(0, 1, dest_ports='/[www,xxx]'),
                              [('aaa',)])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:17,代码来源:test_pattern.py


示例11: test_split_multiindex

    def test_split_multiindex(self):
        idx = pd.MultiIndex(levels=[['a'], ['b', 'c'], ['d', 'e'], [0, 1, 2]],
                            labels=[[0, 0, 0, 0], [0, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 2]])
        idx0, idx1 = Pattern.split_multiindex(idx, slice(0, 2), slice(2, 4))
        assert_index_equal(idx0,
                           pd.MultiIndex(levels=[['a'], ['b', 'c']],
                                         labels=[[0, 0, 0, 0], [0, 0, 1, 1]]))
        assert_index_equal(idx1,
                           pd.MultiIndex(levels=[['d', 'e'], [0, 1, 2]],
                                         labels=[[0, 1, 0, 1], [0, 1, 1, 2]]))

        idx0, idx1 = Pattern.split_multiindex(idx, slice(0, 1), slice(1, 4))
        assert_index_equal(idx0,
                           pd.Index(['a', 'a', 'a', 'a']))
        assert_index_equal(idx1,
                           pd.MultiIndex(levels=[['b', 'c'], ['d', 'e'], [0, 1, 2]],
                                         labels=[[0, 0, 1, 1], [0, 1, 0, 1],
                                                 [0, 1, 1, 2]]))
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:18,代码来源:test_pattern.py


示例12: test_dest_idx_src_ports

    def test_dest_idx_src_ports(self):
        p = Pattern('/[aaa,bbb][0:3]', '/[xxx,yyy][0:3]')
        p['/aaa[0]', '/yyy[0]'] = 1
        p['/aaa[0]', '/yyy[1]'] = 1
        p['/aaa[0]', '/yyy[2]'] = 1
        p['/xxx[0]', '/bbb[0]'] = 1
        p['/xxx[1]', '/bbb[1]'] = 1
        p['/xxx[2]', '/bbb[2]'] = 1
        self.assertItemsEqual(p.dest_idx(0, 1, src_ports='/aaa[0]'),
                              [('yyy', 0),
                               ('yyy', 1),
                               ('yyy', 2)])

        q = Pattern('/[aaa,bbb]', '/[www,xxx,yyy]')
        q['/aaa','/www'] = 1
        q['/aaa','/xxx'] = 1
        q['/bbb','/yyy'] = 1
        self.assertItemsEqual(q.dest_idx(0, 1, src_ports='/aaa'),
                              [('www',),
                               ('xxx',)])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:20,代码来源:test_pattern.py


示例13: create_pattern

def create_pattern(n_dict_1, n_dict_2, save_as=None):
    """
    If `save_as` is not None, save the pattern as the specified file name.
    """

    lpu1_sel_in_gpot = plsel.Selector(LPU.extract_in_gpot(n_dict_1))
    lpu1_sel_out_gpot = plsel.Selector(LPU.extract_out_gpot(n_dict_1))
    lpu2_sel_in_gpot = plsel.Selector(LPU.extract_in_gpot(n_dict_2))
    lpu2_sel_out_gpot = plsel.Selector(LPU.extract_out_gpot(n_dict_2))

    lpu1_sel_in_spike = plsel.Selector(LPU.extract_in_spk(n_dict_1))
    lpu1_sel_out_spike = plsel.Selector(LPU.extract_out_spk(n_dict_1))
    lpu2_sel_in_spike = plsel.Selector(LPU.extract_in_spk(n_dict_2))
    lpu2_sel_out_spike = plsel.Selector(LPU.extract_out_spk(n_dict_2))

    lpu1_sel_out = plsel.Selector.union(lpu1_sel_out_gpot, lpu1_sel_out_spike)
    lpu2_sel_out = plsel.Selector.union(lpu2_sel_out_gpot, lpu2_sel_out_spike)
    lpu1_sel_in = plsel.Selector.union(lpu1_sel_in_gpot, lpu1_sel_in_spike)
    lpu2_sel_in = plsel.Selector.union(lpu2_sel_in_gpot, lpu2_sel_in_spike)

    lpu1_sel = plsel.Selector.union(lpu1_sel_out, lpu1_sel_in)
    lpu2_sel = plsel.Selector.union(lpu2_sel_out, lpu2_sel_in)

    pat = Pattern(lpu1_sel, lpu2_sel)

    pat.interface[lpu1_sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
    pat.interface[lpu1_sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
    pat.interface[lpu2_sel_in_gpot, 'io', 'type'] = ['in', 'gpot']
    pat.interface[lpu2_sel_out_gpot, 'io', 'type'] = ['out', 'gpot']
    pat.interface[lpu1_sel_in_spike, 'io', 'type'] = ['in', 'spike']
    pat.interface[lpu1_sel_out_spike, 'io', 'type'] = ['out', 'spike']
    pat.interface[lpu2_sel_in_spike, 'io', 'type'] = ['in', 'spike']
    pat.interface[lpu2_sel_out_spike, 'io', 'type'] = ['out', 'spike']

    Neuron_list_12 = ['L1', 'L2', 'L3', 'L4', 'L5', 'T1']
    Neuron_list_21 = ['C2', 'C3']
    
    for i in range(768):
        for neuron in Neuron_list_12:
            pat['/lamina/cart'+str(i)+'/'+neuron, '/medulla/cart'+str(i)+'/'+neuron] = 1
        for neuron in Neuron_list_21:
            pat['/medulla/cart'+str(i)+'/'+neuron, '/lamina/cart'+str(i)+'/'+neuron] = 1
    if save_as:
        with open(save_as, 'wb') as pat_file:
            pickle.dump(pat, pat_file)
    return pat
开发者ID:neurokernel,项目名称:sensory_int,代码行数:46,代码来源:vision_configuration.py


示例14: test_is_in_interfaces

    def test_is_in_interfaces(self):
        # Selectors with multiple levels:
        p = Pattern('/aaa/bbb', '/ccc/ddd')
        assert p.is_in_interfaces('/aaa/bbb') == True
        assert p.is_in_interfaces('/aaa') == False

        # Selectors with a single level:
        p = Pattern('/aaa', '/bbb')
        assert p.is_in_interfaces('/aaa') == True
        assert p.is_in_interfaces('/ccc') == False

        # Selectors comprising identifiers with different numbers of levels::
        p = Pattern('/aaa,/bbb[0]', '/ccc,/ddd[0]')
        assert p.is_in_interfaces('/aaa') == True
        assert p.is_in_interfaces('/ccc') == True
        assert p.is_in_interfaces('/ddd') == False
        assert p.is_in_interfaces('/ddd[0]') == True
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:17,代码来源:test_pattern.py


示例15: test_from_concat

    def test_from_concat(self):
        p = Pattern.from_concat('/[foo,bar]', '/[baz,qux]',
                                from_sel='/[foo,bar]', to_sel='/[baz,qux]',
                                data=1)
        df = pd.DataFrame(data=[1, 1],
                    index=pd.MultiIndex(levels=[['bar', 'foo'], ['baz', 'qux']],
                                        labels=[[1, 0], [0, 1]],
                                        names=['from_0', 'to_0'], dtype=object),
                    columns=['conn'])
        assert_frame_equal(p.data, df)

        p = Pattern.from_concat('/foo[0:2]', '/bar[0:2]',
                                from_sel='/foo[0:2]', to_sel='/bar[0:2]',
                                data=1)
        df = pd.DataFrame(data=[1, 1],
                index=pd.MultiIndex(levels=[['foo'], [0, 1], ['bar'], [0, 1]],
                                    labels=[[0, 0], [0, 1], [0, 0], [0, 1]],
                                    names=['from_0', 'from_1', 'to_0', 'to_1'], 
                                    dtype=object),
                    columns=['conn'])
        assert_frame_equal(p.data, df)
开发者ID:MariyaS,项目名称:neurokernel,代码行数:21,代码来源:test_pattern.py


示例16: test_in_ports

 def test_in_ports(self):
     p = Pattern('/foo[0:3]', '/bar[0:3]')
     p.interface['/foo[0]', 'io', 'type'] = ['in', 'spike']
     p.interface['/foo[1:3]', 'io', 'type'] = ['out', 'gpot']
     p.interface['/bar[0:2]', 'io', 'type'] = ['out', 'spike']
     p.interface['/bar[2]', 'io', 'type'] = ['in', 'gpot']
     self.assertItemsEqual(p.in_ports(0).to_tuples(),
                           [('foo', 0)])
     self.assertItemsEqual(p.in_ports(1).to_tuples(),
                           [('bar', 2)])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:10,代码来源:test_pattern.py


示例17: test_to_graph

    def test_to_graph(self):
        p = Pattern('/foo[0:4]', '/bar[0:4]')
        p['/foo[0]', '/bar[0]'] = 1
        p['/foo[0]', '/bar[1]'] = 1
        p['/foo[1]', '/bar[2]'] = 1
        p['/bar[3]', '/foo[2]'] = 1
        p['/bar[3]', '/foo[3]'] = 1
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar/0', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/1', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/2', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/3', {'interface': 1, 'io': 'in', 'type': ''}),
                               ('/foo/0', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/1', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/2', {'interface': 0, 'io': 'out', 'type': ''}),
                               ('/foo/3', {'interface': 0, 'io': 'out', 'type': ''})])
        self.assertItemsEqual(g.edges(data=True),
                              [('/foo/0', '/bar/0', {}),
                               ('/foo/0', '/bar/1', {}),
                               ('/foo/1', '/bar/2', {}),
                               ('/bar/3', '/foo/2', {}),
                               ('/bar/3', '/foo/3', {})])
开发者ID:Taaccoo-beta,项目名称:neurokernel,代码行数:24,代码来源:test_pattern.py


示例18: connect_retina_lamina

    def connect_retina_lamina(self, manager, ret_lpu, lam_lpu):
        #.values or .tolist()
        print('Initializing selectors')
        # some workarounds
        ret_sel = ','.join(['/retout/'+ str(sel[-1]) for sel in ret_lpu.interface.index.tolist()])
        lam_sel = ','.join(['/' + str(sel[0]) + '/' +  str(sel[1]) for sel in lam_lpu.interface.index.tolist()])
        
        print('Initializing pattern with selectors')
        
        pat = Pattern(ret_sel, lam_sel)
        ret_sel = ','.join(['/retout/'+ str(sel[-1]) for sel in ret_lpu.interface.index.tolist()])
        lam_sel_in = ','.join(['/retin/' + str(sel[-1]) for sel in lam_lpu.interface.index.tolist() if sel[0] == 'retin'])
        lam_sel_out = ','.join(['/lamout/' + str(sel[-1]) for sel in lam_lpu.interface.index.tolist() if not sel[0] == 'retin'])

        print('Setting selector attributes in pattern')
        pat.interface[ret_sel] = [0, 'in', 'gpot']
        pat.interface[lam_sel_in] = [1, 'out', 'gpot']
        pat.interface[lam_sel_out] = [1, 'in', 'gpot']

        for sel in lam_sel_in.split(','):
            pat[sel.replace('in', 'out'), sel] = 1
            
        print('Connecting LPUs with the pattern')
        manager.connect(ret_lpu, lam_lpu, pat, 0, 1)
开发者ID:Hanyu-Li,项目名称:neurokernel,代码行数:24,代码来源:eyeimpl.py


示例19: connect_retina_lamina

def connect_retina_lamina(config, i, retina, lamina, manager):
    '''
        The connections between Retina and Lamina follow
        the neural superposition rule of the fly's compound eye.
        See more information in NeurokernelRFC#2.

        Retina provides an interface to make this connection easier.
        --
        config: configuration dictionary like object
        i: identifier of eye in case more than one is used
        retina: retina array object
        lamina: lamina array object
        manager: manager object to which connection pattern will be added
    '''
    retina_id = get_retina_id(i)
    lamina_id = get_lamina_id(i)
    print('Connecting {} and {}'.format(retina_id, lamina_id))

    retina_selectors = retina.get_all_selectors()
    lamina_selectors = lamina.get_all_selectors()
    with Timer('creation of Pattern object'):
        from_list = []
        to_list = []

        # accounts neural superposition
        rulemap = retina.rulemap
        for ret_sel in retina_selectors:
            # format should be '/ret/<ommid>/<neuronname>'
            _, lpu, ommid, n_name = ret_sel.split('/')
            # find neighbor of neural superposition
            neighborid = rulemap.neighbor_for_photor(int(ommid), n_name)
            # format should be '/lam/<cartid>/<neuronname>'
            lam_sel = lamina.get_selector(neighborid, n_name)

            # setup connection from retina to lamina
            from_list.append(ret_sel)
            to_list.append(lam_sel)

        pattern = Pattern.from_concat(','.join(retina_selectors),
                                      ','.join(lamina_selectors),
                                      from_sel=','.join(from_list),
                                      to_sel=','.join(to_list),
                                      gpot_sel=','.join(from_list+to_list))
        nx.write_gexf(pattern.to_graph(), retina_id+'_'+lamina_id+'.gexf.gz',
                      prettyprint=True)

    with Timer('update of connections in Manager'):
        manager.connect(retina_id, lamina_id, pattern)
开发者ID:neurokernel,项目名称:retina-lamina,代码行数:48,代码来源:retlam_demo.py


示例20: create_pattern

def create_pattern(n_dict_1, n_dict_2, save_as=None):
    """
    If `save_as` is not None, save the pattern in GEXF format as the specified file name.
    """

    lpu1_sel_in_gpot = plsel.Selector(LPU.extract_in_gpot(n_dict_1))
    lpu1_sel_out_gpot = plsel.Selector(LPU.extract_out_gpot(n_dict_1))
    lpu2_sel_in_gpot = plsel.Selector(LPU.extract_in_gpot(n_dict_2))
    lpu2_sel_out_gpot = plsel.Selector(LPU.extract_out_gpot(n_dict_2))

    lpu1_sel_in_spike = plsel.Selector(LPU.extract_in_spk(n_dict_1))
    lpu1_sel_out_spike = plsel.Selector(LPU.extract_out_spk(n_dict_1))
    lpu2_sel_in_spike = plsel.Selector(LPU.extract_in_spk(n_dict_2))
    lpu2_sel_out_spike = plsel.Selector(LPU.extract_out_spk(n_dict_2))

    lpu1_sel_out = plsel.Selector.union(lpu1_sel_out_gpot, lpu1_sel_out_spike)
    lpu2_sel_out = plsel.Selector.union(lpu2_sel_out_gpot, lpu2_sel_out_spike)
    lpu1_sel_in = plsel.Selector.union(lpu1_sel_in_gpot, lpu1_sel_in_spike)
    lpu2_sel_in = plsel.Selector.union(lpu2_sel_in_gpot, lpu2_sel_in_spike)

    lpu1_sel = plsel.Selector.union(lpu1_sel_out, lpu1_sel_in)
    lpu2_sel = plsel.Selector.union(lpu2_sel_out, lpu2_sel_in)

    Neuron_list_12 = ["L1", "L2", "L3", "L4", "L5", "T1"]
    Neuron_list_21 = ["C2", "C3"]

    gpot_sel = plsel.Selector.union(lpu1_sel_out_gpot, lpu1_sel_in_gpot, lpu2_sel_out_gpot, lpu2_sel_in_gpot)
    spike_sel = plsel.Selector.union(lpu1_sel_out_spike, lpu1_sel_in_spike, lpu2_sel_out_spike, lpu2_sel_in_spike)

    Neuron_str_12 = "[" + ",".join(Neuron_list_12) + "]"
    Neuron_str_21 = "[" + ",".join(Neuron_list_21) + "]"
    cart_str = "[" + ",".join(["cart%i" % i for i in range(768)]) + "]"

    from_sel_12 = "/lamina" + cart_str + Neuron_str_12
    to_sel_12 = "/medulla" + cart_str + Neuron_str_12
    from_sel_21 = "/medulla" + cart_str + Neuron_str_21
    to_sel_21 = "/lamina" + cart_str + Neuron_str_21

    from_sel = from_sel_12 + "," + from_sel_21
    to_sel = to_sel_12 + "," + to_sel_21

    pat = Pattern.from_concat(
        lpu1_sel, lpu2_sel, from_sel=from_sel, to_sel=to_sel, gpot_sel=gpot_sel, spike_sel=spike_sel, data=1
    )

    if save_as:
        nx.write_gexf(pat.to_graph(), save_as, prettyprint=True)
    return pat
开发者ID:neurokernel,项目名称:vision,代码行数:48,代码来源:vision_configuration.py



注:本文中的neurokernel.pattern.Pattern类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python neurom.get函数代码示例发布时间:2022-05-27
下一篇:
Python pattern.Interface类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap