Esempio n. 1
0
    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