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

Python parameters.ParameterSpace类代码示例

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

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



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

示例1: test_create_with_list_of_lists

 def test_create_with_list_of_lists(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': [[1, 2, 3], [4, 5, 6]]},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence))  
开发者ID:Huitzilo,项目名称:PyNN,代码行数:7,代码来源:test_parameters.py


示例2: test_create_with_array_of_sequences

 def test_create_with_array_of_sequences(self):
     schema = {"a": Sequence}
     ps = ParameterSpace(
         {"a": np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence)}, schema, shape=(2,)
     )
     ps.evaluate()
     assert_array_equal(ps["a"], np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence))
开发者ID:JoelChavas,项目名称:PyNN,代码行数:7,代码来源:test_parameters.py


示例3: test_iteration

 def test_iteration(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     self.assertEqual(list(ps),
                      [{'a': 3, 'c': 5, 'b': 7},
                       {'a': 8, 'c': 11, 'b': 7},
                       {'a': 13, 'c': 14, 'b': 7}])
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:7,代码来源:test_parameters.py


示例4: test_create_with_tuple

 def test_create_with_tuple(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': (1, 2, 3)},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([1, 2, 3])], dtype=Sequence))
开发者ID:Huitzilo,项目名称:PyNN,代码行数:7,代码来源:test_parameters.py


示例5: test_evaluate_with_mask_2D

 def test_evaluate_with_mask_2D(self):
     ps2d = ParameterSpace(
         {"a": [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]], "b": 7, "c": lambda i, j: 3 * i - 2 * j}, shape=(2, 5)
     )
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     assert_array_equal(ps2d["a"], np.array([[3, 8, 13], [34, 89, 144]]))
     assert_array_equal(ps2d["c"], np.array([[-2, -6, -8], [1, -3, -5]]))
开发者ID:JoelChavas,项目名称:PyNN,代码行数:7,代码来源:test_parameters.py


示例6: test_iteration_items

 def test_iteration_items(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([3,  8, 13]),
                 'c': np.array([5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key, value in ps.items():
         assert_array_equal(expected[key], value)
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:8,代码来源:test_parameters.py


示例7: test_evaluate_with_mask

 def test_evaluate_with_mask(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([ 3,  8, 13]),
                 'c': np.array([ 5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key in expected:
         assert_array_equal(expected[key], ps[key])
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:8,代码来源:test_parameters.py


示例8: __init__

 def __init__(self, **parameters):
     self._device   = nest.Create(self.nest_name)
     self.cell_list = []
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:9,代码来源:electrodes.py


示例9: test_columnwise_iteration_single_column

 def test_columnwise_iteration_single_column(self):
     ps2d = ParameterSpace(
         {"a": [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]], "b": 7, "c": lambda i, j: 3 * i - 2 * j}, shape=(2, 5)
     )
     ps2d.evaluate(mask=(slice(None), 3))
     expected = [{"a": np.array([8, 89]), "b": np.array([7, 7]), "c": np.array([-6, -3])}]
     actual = list(ps2d.columns())
     for x, y in zip(actual, expected):
         for key in y:
             assert_array_equal(x[key], y[key])
开发者ID:JoelChavas,项目名称:PyNN,代码行数:10,代码来源:test_parameters.py


示例10: NestCurrentSource

class NestCurrentSource(BaseCurrentSource):
    """Base class for a nest source of current to be injected into a neuron."""

    def __init__(self, **parameters):
        self._device = nest.Create(self.nest_name)
        self.cell_list = []
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=(1,))
        if parameters:
            self.parameter_space.update(**parameters)

        self.min_delay = state.min_delay
        self.dt = state.dt

    def inject_into(self, cells):
        for id in cells:
            if id.local and not id.celltype.injectable:
                raise TypeError("Can't inject current into a spike source.")
        if isinstance(cells, (Population, PopulationView, Assembly)):
            self.cell_list = [cell for cell in cells]
        else:
            self.cell_list = cells
        nest.Connect(self._device, self.cell_list, syn_spec={"delay": state.min_delay})

    def _delay_correction(self, value):
        """
        A change in a device requires a min_delay to take effect at the target
        """
        corrected = value - self.min_delay
        # set negative times to zero
        if isinstance(value, numpy.ndarray):
            corrected = numpy.where(corrected > 0, corrected, 0.0)
        else:
            corrected = max(corrected, 0.0)
        return corrected

    def record(self):
        self.i_multimeter = nest.Create('multimeter', params={'record_from': ['I'], 'interval': state.dt})
        nest.Connect(self.i_multimeter, self._device)

    def _get_data(self):
        events = nest.GetStatus(self.i_multimeter)[0]['events']
        # Similar to recording.py: NEST does not record values at
        # the zeroth time step, so we add them here.
        t_arr = numpy.insert(numpy.array(events['times']), 0, 0.0)
        i_arr = numpy.insert(numpy.array(events['I']/1000.0), 0, 0.0)
        # NEST and pyNN have different concepts of current initiation times
        # To keep this consistent across simulators, we will have current
        # initiating at the electrode at t_start and effect on cell at next dt
        # This requires padding min_delay equivalent period with 0's
        pad_length = int(self.min_delay/self.dt)
        i_arr = numpy.insert(i_arr[:-pad_length], 0, [0]*pad_length)
        return t_arr, i_arr
开发者ID:antolikjan,项目名称:PyNN,代码行数:54,代码来源:electrodes.py


示例11: test_columnwise_iteration

 def test_columnwise_iteration(self):
     ps2d = ParameterSpace({'a': [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]],
                            'b': 7,
                            'c': lambda i, j: 3*i-2*j}, shape=(2, 5))
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     expected = [{'a': np.array([3, 34]), 'b': np.array([7, 7]), 'c': np.array([-2, 1])},
                 {'a': np.array([8, 89]), 'b': np.array([7, 7]), 'c': np.array([-6, -3])},
                 {'a': np.array([13, 144]), 'b': np.array([7, 7]), 'c': np.array([-8, -5])}]
     for x, y in zip(ps2d.columns(), expected):
         for key in y:
             assert_array_equal(x[key], y[key])
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:11,代码来源:test_parameters.py


示例12: BaseModelType

class BaseModelType(object):
    """Base class for standard and native cell and synapse model classes."""
    default_parameters = {}
    default_initial_values = {}
    parameter_checks = {}

    def __init__(self, **parameters):
        """
        `parameters` should be a mapping object, e.g. a dict
        """
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=None)
        if parameters:
            self.parameter_space.update(**parameters)

    def __repr__(self):
        return "%s(<parameters>)" % self.__class__.__name__  # should really include the parameters explicitly, to be unambiguous

    @classmethod
    def has_parameter(cls, name):
        """Does this model have a parameter with the given name?"""
        return name in cls.default_parameters

    @classmethod
    def get_parameter_names(cls):
        """Return the names of the parameters of this model."""
        return list(cls.default_parameters.keys())

    def get_schema(self):
        """
        Returns the model schema: i.e. a mapping of parameter names to allowed
        parameter types.
        """
        return dict((name, type(value))
                    for name, value in self.default_parameters.items())

    def describe(self, template='modeltype_default.txt', engine='default'):
        """
        Returns a human-readable description of the cell or synapse type.

        The output may be customized by specifying a different template
        togther with an associated template engine (see ``pyNN.descriptions``).

        If template is None, then a dictionary containing the template context
        will be returned.
        """
        context = {
            "name": self.__class__.__name__,
            "default_parameters": self.default_parameters,
            "default_initial_values": self.default_initial_values,
            "parameters": self.parameter_space._parameters,  # should add a describe() method to ParameterSpace
        }
        return descriptions.render(engine, template, context)
开发者ID:NeuralEnsemble,项目名称:PyNN,代码行数:54,代码来源:models.py


示例13: __init__

 def __init__(self, **parameters):
     super(StandardCurrentSource, self).__init__(**parameters)
     self.cell_list = []
     self.indices = []
     simulator.state.current_sources.append(self)
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
开发者ID:sanjayankur31,项目名称:PyNN,代码行数:11,代码来源:electrodes.py


示例14: __init__

 def __init__(self, **parameters):
     self._devices    = []
     self.cell_list   = []
     self._amplitudes = None
     self._times      = None
     self._h_iclamps  = {}
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:12,代码来源:electrodes.py


示例15: __init__

 def __init__(self, **parameters):
     super(StandardCurrentSource, self).__init__(**parameters)
     global current_sources
     self.cell_list = []
     self.indices   = []
     self.ind = len(current_sources) # Todo use self.indices instead...
     current_sources.append(self)
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
开发者ID:antolikjan,项目名称:PyNN,代码行数:13,代码来源:electrodes.py


示例16: __init__

 def __init__(self, **parameters):
     """
     `parameters` should be a mapping object, e.g. a dict
     """
     self.parameter_space = ParameterSpace(self.default_parameters,
                                           self.get_schema(),
                                           shape=None)
     if parameters:
         self.parameter_space.update(**parameters)
开发者ID:NeuralEnsemble,项目名称:PyNN,代码行数:9,代码来源:models.py


示例17: connect

    def connect(self, projection):
        """Connect-up a Projection."""
        logger.debug("conn_list (original) = \n%s", self.conn_list)
        if numpy.any(self.conn_list[:, 0] >= projection.pre.size):
            raise errors.ConnectionError("source index out of range")
        if (self.conn_list.shape[1] < 3 or self.conn_list.shape[1] > 4 or 
            (self.conn_list.shape[1] == 3 and projection.synapse_type.has_parameter('delay'))):
            raise errors.ConnectionError("incompatible number of columns for connection list requires "
                                         "4 (3 for synapse type without delay)")
        # need to do some profiling, to figure out the best way to do this:
        #  - order of sorting/filtering by local
        #  - use numpy.unique, or just do in1d(self.conn_list)?
        idx  = numpy.argsort(self.conn_list[:, 1])
        targets = numpy.unique(self.conn_list[:, 1]).astype(numpy.int)
        local = numpy.in1d(targets,
                           numpy.arange(projection.post.size)[projection.post._mask_local],
                           assume_unique=True)
        local_targets = targets[local]
        self.conn_list = self.conn_list[idx]
        left  = numpy.searchsorted(self.conn_list[:, 1], local_targets, 'left')
        right = numpy.searchsorted(self.conn_list[:, 1], local_targets, 'right')
        logger.debug("idx = %s", idx)
        logger.debug("targets = %s", targets)
        logger.debug("local_targets = %s", local_targets)
        logger.debug("conn_list (sorted by target) = \n%s", self.conn_list)
        logger.debug("left = %s", left)
        logger.debug("right = %s", right)

        schema = projection.synapse_type.get_schema()
        for tgt, l, r in zip(local_targets, left, right):
            sources = self.conn_list[l:r, 0].astype(numpy.int)
            param_dict = {'weight': self.conn_list[l:r, 2] }
            if self.conn_list.shape[1] == 4:
                param_dict['delay'] = self.conn_list[l:r, 3]
            connection_parameters = ParameterSpace(param_dict,
                                                   schema=schema,
                                                   shape=(r-l,))
            if isinstance(projection.synapse_type, StandardSynapseType):
                connection_parameters = projection.synapse_type.translate(
                                            connection_parameters)
            connection_parameters.evaluate()
            projection._convergent_connect(sources, tgt, **connection_parameters)
开发者ID:mikehulluk,项目名称:PyNN,代码行数:42,代码来源:connectors.py


示例18: __init__

    def __init__(self, **parameters):
        self._device = nest.Create(self.nest_name)
        self.cell_list = []
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=(1,))
        if parameters:
            self.parameter_space.update(**parameters)

        self.min_delay = state.min_delay
        self.dt = state.dt
开发者ID:antolikjan,项目名称:PyNN,代码行数:11,代码来源:electrodes.py


示例19: test_evaluate

 def test_evaluate(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8], 'b': 7, 'c': lambda i: 3*i+2}, shape=(4,))
     self.assertIsInstance(ps['c'], LazyArray)
     ps.evaluate()
     assert_array_equal(ps['c'], np.array([ 2,  5,  8, 11]))
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:5,代码来源:test_parameters.py


示例20: test_iteration

 def test_iteration(self):
     ps = ParameterSpace({"a": [2, 3, 5, 8, 13], "b": 7, "c": lambda i: 3 * i + 2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     self.assertEqual(list(ps), [{"a": 3, "c": 5, "b": 7}, {"a": 8, "c": 11, "b": 7}, {"a": 13, "c": 14, "b": 7}])
开发者ID:JoelChavas,项目名称:PyNN,代码行数:4,代码来源:test_parameters.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python spiNNaker.end函数代码示例发布时间:2022-05-25
下一篇:
Python parameters.LazyArray类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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