当前位置: 首页>>代码示例>>Python>>正文


Python pattern.Pattern类代码示例

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


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


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