Пример #1
0
 def set_weights(self, weight=None, elist=None, distribution=None,
                 parameters=None, noise_scale=None):
     '''
     Set the synaptic weights.
     ..todo ::
         take elist into account in Connections.weights
     
     Parameters
     ----------
     weight : float or class:`numpy.array`, optional (default: None)
         Value or list of the weights (for user defined weights).
     elist : class:`numpy.array`, optional (default: None)
         List of the edges (for user defined weights).
     distribution : class:`string`, optional (default: None)
         Type of distribution (choose among "constant", "uniform", 
         "gaussian", "lognormal", "lin_corr", "log_corr").
     parameters : dict, optional (default: {})
         Dictionary containing the properties of the weight distribution.
     noise_scale : class:`int`, optional (default: None)
         Scale of the multiplicative Gaussian noise that should be applied
         on the weights.
     '''
     if isinstance(weight, float):
         size = self.edge_nb() if elist is None else len(elist)
         weight = np.repeat(weight, size)
     elif not hasattr(weight, "__len__") and weight is not None:
         raise AttributeError('''Invalid `weight` value: must be either
                              float, array-like or None.''')
     if distribution is None:
         distribution = self._w["distribution"]
     if parameters is None:
         parameters = self._w
     Connections.weights(self, elist=elist, wlist=weight,
                         distribution=distribution, parameters=parameters,
                         noise_scale=noise_scale)
Пример #2
0
 def set_weights(self, elist=None, wlist=None, distrib=None,
                 distrib_prop=None, correl=None, noise_scale=None):
     '''
     Set the synaptic weights.
     @todo: take elist into account in Connections.weights
     
     Parameters
     ----------
     elist : class:`numpy.array`, optional (default: None)
         List of the edges (for user defined weights).
     wlist : class:`numpy.array`, optional (default: None)
         List of the weights (for user defined weights).
     distrib : class:`string`, optional (default: None)
         Type of distribution (choose among "constant", "uniform", 
         "gaussian", "lognormal", "lin_corr", "log_corr").
     distrib_prop : dict, optional (default: {})
         Dictoinary containing the properties of the weight distribution.
     correl : class:`string`, optional (default: None)
         Property to which the weights should be correlated.
     noise_scale : class:`int`, optional (default: None)
         Scale of the multiplicative Gaussian noise that should be applied
         on the weights.
     '''
     if distrib is None:
         distrib = self._w["distrib"]
     if distrib_prop is None:
         distrib_prop = (self._w["distrib_prop"] if "distrib_prop" in 
                         self._w.keys() else {})
     if correl is None:
         correl = self._w["correl"] if "correl" in self._w.keys() else None
     Connections.weights(self, elist=elist, wlist=wlist, distrib=distrib,
         correl=correl, distrib_prop=distrib_prop, noise_scale=noise_scale)
Пример #3
0
 def _init_bioproperties(self, population):
     ''' Set the population attribute and link each neuron to its group. '''
     if issubclass(population.__class__, NeuralPop):
         if population.is_valid:
             self._population = population
             nodes = population.size
             # create the delay attribute
             Connections.delays(self)
         else:
             raise AttributeError("NeuralPop is not valid (not all \
             neurons are associated to a group).")
     else:
         raise AttributeError("Expected NeuralPop but received \
                 {}".format(pop.__class__.__name__))
Пример #4
0
 def _init_spatial_properties(self, shape, positions=None, **kwargs):
     '''
     Create the positions of the neurons from the graph `shape` attribute
     and computes the connections distances.
     '''
     if shape is not None:
         shape.set_parent(self)
         self._shape = shape
     else:
         self._shape = Shape.rectangle(self,1,1)
     if positions is not None and positions.shape[1] != self.node_nb():
         raise InvalidArgument("Wrong number of neurons in `positions`.")
     b_rnd_pos = True if not self.node_nb() or positions is None else False
     self._pos = self._shape.rnd_distrib() if b_rnd_pos else positions
     Connections.distances(self)
Пример #5
0
 def set_delays(self, delay=None, elist=None, distribution=None,
                parameters=None, noise_scale=None):
     '''
     Set the delay for spike propagation between neurons.
     ..todo ::
         take elist into account in Connections.delays
     
     Parameters
     ----------
     delay : float or class:`numpy.array`, optional (default: None)
         Value or list of delays (for user defined delays).
     elist : class:`numpy.array`, optional (default: None)
         List of the edges (for user defined delays).
     distribution : class:`string`, optional (default: None)
         Type of distribution (choose among "constant", "uniform", 
         "gaussian", "lognormal", "lin_corr", "log_corr").
     parameters : dict, optional (default: {})
         Dictionary containing the properties of the delay distribution.
     noise_scale : class:`int`, optional (default: None)
         Scale of the multiplicative Gaussian noise that should be applied
         on the delays.
     '''
     if isinstance(delay, float):
         size = self.edge_nb() if elist is None else len(elist)
         delay = np.repeat(delay, size)
     elif not hasattr(delay, "__len__") and delay is not None:
         raise AttributeError('''Invalid `delay` value: must be either
                              float, array-like or None.''')
     if distribution is None:
         distribution = self._w["distribution"]
     if parameters is None:
         parameters = self._w
     return Connections.delays(self, elist=elist, dlist=delay,
                        distribution=distribution, parameters=parameters,
                        noise_scale=noise_scale)
Пример #6
0
    def make_network(graph, neural_pop):
        '''
        Turn a :class:`~nngt.Graph` object into a :class:`~nngt.Network`, or a
        :class:`~nngt.SpatialGraph` into a :class:`~nngt.SpatialNetwork`.

        Parameters
        ----------
        graph : :class:`~nngt.Graph` or :class:`~nngt.SpatialGraph`
            Graph to convert
        neural_pop : :class:`~nngt.NeuralPop`
            Population to associate to the new :class:`~nngt.Network`

        Notes
        -----
        In-place operation that directly converts the original graph.
        '''
        if isinstance(graph, SpatialGraph):
            graph.__class__ = SpatialNetwork
        else:
            graph.__class__ = Network
        graph.population = neural_pop
        Connections.delays(graph)
Пример #7
0
    def set_types(self, syn_type, nodes=None, fraction=None):
        '''
        Set the synaptic/connection types.

        .. warning ::
            The special "type" attribute cannot be modified when using graphs
            that inherit from the :class:`~nngt.Network` class. This is because
            for biological networks, neurons make only one kind of synapse,
            which is determined by the :class:`nngt.core.NeuralGroup` they
            belong to.

        Parameters
        ----------
        syn_type : int or string
            Type of the connection among 'excitatory' (also `1`) or
            'inhibitory' (also `-1`).
        nodes : int, float or list, optional (default: `None`)
            If `nodes` is an int, number of nodes of the required type that
            will be created in the graph (all connections from inhibitory nodes
            are inhibitory); if it is a float, ratio of `syn_type` nodes in the
            graph; if it is a list, ids of the `syn_type` nodes.
        fraction : float, optional (default: `None`)
            Fraction of the selected edges that will be set as `syn_type` (if
            `nodes` is not `None`, it is the fraction of the specified nodes'
            edges, otherwise it is the fraction of all edges in the graph).

        Returns
        -------
        t_list : :class:`numpy.ndarray`
            List of the types in an order that matches the `edges` attribute of
            the graph.
        '''
        inhib_nodes = nodes
        if syn_type == 'excitatory' or syn_type == 1:
            if issubclass(nodes.__class__, int):
                inhib_nodes = graph.node_nb() - nodes
            elif issubclass(nodes.__class__, float):
                inhib_nodes = 1./nodes
            elif hasattr(nodes, '__iter__'):
                inhib_nodes = list(range(graph.node_nb()))
                nodes.sort()
                for node in nodes[::-1]:
                    del inhib_nodes[node]
        return Connections.types(self, inhib_nodes, fraction)