本文整理汇总了Python中pyNN.parameters.ParameterSpace类的典型用法代码示例。如果您正苦于以下问题:Python ParameterSpace类的具体用法?Python ParameterSpace怎么用?Python ParameterSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParameterSpace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
示例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))
示例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}])
示例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))
示例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]]))
示例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)
示例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])
示例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)
示例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])
示例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
示例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])
示例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)
示例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)
示例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)
示例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)