def connect(self, projection): """Connect-up a Projection.""" if projection.pre.size == projection.post.size: N = projection.post.size local = projection.post._mask_local if isinstance(self.weights, basestring) or isinstance( self.delays, basestring): raise Exception( 'Expression for weights or delays is not supported for OneToOneConnector !' ) weights_generator = WeightGenerator(self.weights, local, projection, self.safe) delays_generator = DelayGenerator(self.delays, local, self.safe) weights = weights_generator.get(N) delays = delays_generator.get(N) self.progressbar(len(projection.post.local_cells)) count = 0 create = numpy.arange(0, N)[local] sources = projection.pre.all_cells[create] for tgt, src, w, d in zip(projection.post.local_cells, sources, weights, delays): # the float is in case the values are of type numpy.float64, which NEST chokes on projection.connection_manager.connect(src, [tgt], [float(w)], [float(d)]) self.progression(count) count += 1 else: raise errors.InvalidDimensionsError( "OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes." )
def connect(self, projection): """Connect-up a Projection.""" if projection.pre.dim == projection.post.dim: N = projection.post.size local = projection.post._mask_local.flatten() if isinstance(self.weights, basestring) or isinstance( self.delays, basestring): raise Exception( 'Expression for weights or delays is not supported for OneToOneConnector !' ) weights_generator = WeightGenerator(self.weights, local, projection, self.safe) delays_generator = DelayGenerator(self.delays, local, self.safe) weights = weights_generator.get(N) delays = delays_generator.get(N) self.progressbar(len(projection.post.local_cells)) count = 0 for tgt, w, d in zip(projection.post.local_cells, weights, delays): src = projection.pre.index(projection.post.id_to_index(tgt)) # the float is in case the values are of type numpy.float64, which NEST chokes on projection._divergent_connect(src, [tgt], float(w), float(d)) self.progression(count) count += 1 else: raise errors.InvalidDimensionsError( "OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes." )
def update(self, **parameters): """ Update the contents of the parameter space according to the `(key, value)` pairs in ``**parameters``. All values will be turned into lazy arrays. If the :class:`ParameterSpace` has a schema, the keys and the data types of the values will be checked against the schema. """ if self.schema: for name, value in parameters.items(): try: expected_dtype = self.schema[name] except KeyError: if self.component: model_name = self.component.__name__ else: model_name = 'unknown' raise errors.NonExistentParameterError( name, model_name, valid_parameter_names=self.schema.keys()) if issubclass(expected_dtype, ArrayParameter) and isinstance( value, collections.Sized): if len(value) == 0: value = ArrayParameter([]) elif not isinstance( value[0], ArrayParameter ): # may be a more generic way to do it, but for now this special-casing seems like the most robust approach if isinstance( value[0], collections.Sized): # e.g. list of tuples value = type(value)( [ArrayParameter(x) for x in value]) else: value = ArrayParameter(value) try: self._parameters[name] = LazyArray(value, shape=self._shape, dtype=expected_dtype) except (TypeError, errors.InvalidParameterValueError): raise errors.InvalidParameterValueError( "For parameter %s expected %s, got %s" % (name, expected_dtype, type(value))) except ValueError as err: raise errors.InvalidDimensionsError( err ) # maybe put the more specific error classes into lazyarray else: for name, value in parameters.items(): self._parameters[name] = LazyArray(value, shape=self._shape)