def __init__( self, conn_list, safe=True, verbose=False, column_names=None, callback=None): """ :param conn_list: \ a list of tuples, one tuple for each connection. Each tuple\ should contain: `(pre_idx, post_idx, p1, p2, ..., pn)` where\ `pre_idx` is the index (i.e. order in the Population, not the ID)\ of the presynaptic neuron, `post_idx` is the index of the\ postsynaptic neuron, and `p1`, `p2`, etc. are the synaptic\ parameters (e.g., weight, delay, plasticity parameters). :param column_names: \ the names of the parameters p1, p2, etc. If not provided, it is\ assumed the parameters are weight, delay (for\ backwards compatibility). :param safe: \ if True, check that weights and delays have valid values. If\ False, this check is skipped. :param callback: \ if given, a callable that display a progress bar on the terminal. """ CommonFromListConnector.__init__( self, conn_list=conn_list, safe=safe, verbose=verbose, column_names=column_names) Connector.__init__(self, safe=safe, callback=callback)
def __init__(self, cset, safe=True, callback=None): """ """ Connector.__init__(self, safe=safe, callback=callback) self.cset = cset arity = csa.arity(cset) assert arity in (0, 2), 'must specify mask or connection-set with arity 0 or 2'
def __init__(self, projection, weights=0.0, delays=None, allow_self_connections=True, space=Space(), safe=True): Connector.__init__(self, weights, delays, space, safe) if isinstance(projection.rng, random.NativeRNG): raise Exception("Use of NativeRNG not implemented.") else: self.rng = projection.rng self.N = projection.pre.size idx = numpy.arange(self.N * rank(), self.N * (rank() + 1)) self.M = num_processes() * self.N self.local = numpy.ones(self.N, bool) self.local_long = numpy.zeros(self.M, bool) self.local_long[idx] = True self.weights_generator = WeightGenerator(weights, self.local_long, projection, safe) self.delays_generator = DelayGenerator(delays, self.local_long, safe) self.probas_generator = ProbaGenerator( random.RandomDistribution('uniform', (0, 1), rng=self.rng), self.local_long) self.distance_matrix = DistanceMatrix(projection.pre.positions, self.space, self.local) self.projection = projection self.candidates = projection.pre.all_cells self.allow_self_connections = allow_self_connections
def _parameters_from_synapse_type(self, projection, distance_map=None): """ Obtain the parameters to be used for the connections from the projection's `synapse_type` attribute. Each parameter value is a `LazyArray`. """ if distance_map is None: distance_map = Connector._generate_distance_map(self, projection) parameter_space = projection.synapse_type.native_parameters # TODO: in the documentation, we claim that a parameter value can be # a list or 1D array of the same length as the number of connections. # We do not currently handle this scenario, although it is only # really useful for fixed-number connectors anyway. # Probably the best solution is to remove the parameter at this stage, # then set it after the connections have already been created. parameter_space.shape = (projection.pre.size, projection.post.size) # Remove randomly generated variables from the (host) parameter_space # if the user so chooses. We keep a copy of the removed (not expanded) # parameters in the Connector object pops = [] for name, map in parameter_space.items(): # if len(map.operations): # continue if ((isinstance(map.base_value, RandomDistribution) and isinstance(map.base_value.rng, NativeRNG)) or map.is_homogeneous): self.on_device_init_params[name] = map pops.append(name) for name in pops: parameter_space.pop(name) for name, map in parameter_space.items(): if callable(map.base_value): if isinstance(map.base_value, IndexBasedExpression): # Assumes map is a function of index and hence requires the projection to # determine its value. It and its index function are copied so as to be able # to set the projection without altering the connector, which would perhaps # not be expected from the 'connect' call. new_map = copy(map) new_map.base_value = copy(map.base_value) new_map.base_value.projection = projection parameter_space[name] = new_map else: # Assumes map is a function of distance parameter_space[name] = map(distance_map) return parameter_space
def __init__(self, projection, weights=0.0, delays=None, allow_self_connections=True, space=Space(), safe=True): Connector.__init__(self, weights, delays, space, safe) if isinstance(projection.rng, random.NativeRNG): raise Exception("Use of NativeRNG not implemented.") else: self.rng = projection.rng if self.delays is None: self.delays = projection._simulator.state.min_delay self.N = projection.pre.size mpi_rank = projection._simulator.state.mpi_rank num_processes = projection._simulator.state.num_processes idx = numpy.arange(self.N*mpi_rank, self.N*(mpi_rank+1), dtype=numpy.int) self.M = num_processes*self.N self.local = numpy.ones(self.N, bool) self.local_long = numpy.zeros(self.M, bool) self.local_long[idx] = True self.weights_generator = WeightGenerator(weights, self.local_long, projection, safe) self.delays_generator = DelayGenerator(self.delays, self.local_long, kernel=projection._simulator.state, safe=safe) self.probas_generator = ProbaGenerator(random.RandomDistribution('uniform',(0,1), rng=self.rng), self.local_long) self.distance_matrix = DistanceMatrix(projection.pre.positions, self.space, self.local) self.projection = projection self.candidates = projection.pre.all_cells self.allow_self_connections = allow_self_connections
def __init__(self, conn_list, safe=True, verbose=False, column_names=None, callback=None): """ :param conn_list: \ a list of tuples, one tuple for each connection. Each tuple\ should contain: `(pre_idx, post_idx, p1, p2, ..., pn)` where\ `pre_idx` is the index (i.e. order in the Population, not the ID)\ of the presynaptic neuron, `post_idx` is the index of the\ postsynaptic neuron, and `p1`, `p2`, etc. are the synaptic\ parameters (e.g., weight, delay, plasticity parameters). :param column_names: \ the names of the parameters p1, p2, etc. If not provided, it is\ assumed the parameters are weight, delay (for\ backwards compatibility). :param safe: \ if True, check that weights and delays have valid values. If\ False, this check is skipped. :param callback: \ if given, a callable that display a progress bar on the terminal. """ # pylint: disable=too-many-arguments if conn_list is None or not len(conn_list): raise InvalidParameterType( "The connection list for the FromListConnector must contain" " at least a list of tuples, each of which should contain at " "least: (pre_idx, post_idx)") conn_list = numpy.array(conn_list) n_columns = 0 if conn_list.size: n_columns = conn_list.shape[1] weights = None delays = None self._extra_conn_data = None if column_names is None: # if no column names, but more not the expected if n_columns == 4: column_names = ('pre_idx', 'post_idx', 'weight', 'delay') conn_list, weights, delays, self._extra_conn_data = \ self._split_conn_list(conn_list, column_names) elif n_columns != 2: raise TypeError("Argument 'column_names' is required.") else: # separate conn list to pre, source, weight, delay and the # other things conn_list, weights, delays, self._extra_conn_data = \ self._split_conn_list(conn_list, column_names) # verify that the rest of the parameters are constant, as we don't # support synapse params changing per atom yet self._verify_extra_data_meets_constraints() # build common from list CommonFromListConnector.__init__(self, conn_list=conn_list, safe=safe, verbose=verbose) Connector.__init__(self, safe=safe, callback=callback) # set weights or / and delays if given if weights is not None or delays is not None: self.set_weights_and_delays(weights, delays)