Esempio n. 1
0
    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
Esempio n. 2
0
    def connect(self, projection):
        """Connect-up a Projection."""
        if self.delays is None:
            self.delays = projection._simulator.state.min_delay
        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,
                kernel=projection._simulator.state,
                safe=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]
            homogeneous = numpy.isscalar(delays_generator.source)

            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._divergent_connect(src, [tgt], float(w), float(d),
                                              homogeneous)
                self.progression(count, projection._simulator.state.mpi_rank)
                count += 1
        else:
            raise errors.InvalidDimensionsError(
                "OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes."
            )