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)
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)
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.timestep = state.dt # NoisyCurrentSource has a parameter called "dt", so use "timestep" here state.current_sources.append(self) 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 _reset(self): # after a reset, need to adjust parameters for time offset updated_params = {} for name, value in self.parameter_space.items(): if name in ("start", "stop", "amplitude_times"): updated_params[name] = value if updated_params: state.set_status(self._device, updated_params) 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, np.ndarray): corrected = np.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 = np.insert(np.array(events['times']), 0, 0.0) i_arr = np.insert(np.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.timestep) i_arr = np.insert(i_arr[:-pad_length], 0, [0] * pad_length) return t_arr, i_arr