Exemple #1
0
    def weights(graph, elist=None, wlist=None, distribution="constant",
                parameters={}, noise_scale=None):
        '''
        Compute the weights of the graph's edges.
        @todo: take elist into account

        Parameters
        ----------
        graph : class:`~nngt.Graph` or subclass
            Graph the nodes belong to.
        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).
        distribution : class:`string`, optional (default: "constant")
            Type of distribution (choose among "constant", "uniform",
            "lognormal", "gaussian", "user_def", "lin_corr", "log_corr").
        parameters : class:`dict`, optional (default: {})
            Dictionary containing the distribution parameters.
        noise_scale : class:`int`, optional (default: None)
            Scale of the multiplicative Gaussian noise that should be applied
            on the weights.

        Returns
        -------
        new_weights : class:`scipy.sparse.lil_matrix`
            A sparse matrix containing *ONLY* the newly-computed weights.
        '''
        parameters["btype"] = parameters.get("btype", "edge")
        parameters["use_weights"] = parameters.get("use_weights", False)
        #~ elist = np.array(elist) if elist is not None else elist
        elist = None
        if wlist is not None:
            num_edges = graph.edge_nb() if elist is None else elist.shape[0]
            if len(wlist) != num_edges:
                raise InvalidArgument(
                    '''`wlist` must have one entry per edge. For graph {},
there are {} edges while {} values where provided'''.format(
                    graph.name, num_edges, len(wlist)))
        else:
            wlist = eprop_distribution(graph, distribution, elist=elist,
                                       **parameters)
        # add to the graph container
        bwlist = (np.max(wlist) - wlist if np.any(wlist)
                  else np.repeat(0, len(wlist)))
        graph.set_edge_attribute(
            WEIGHT, value_type="double", values=wlist, edges=elist)
        graph.set_edge_attribute(
            BWEIGHT, value_type="double", values=bwlist, edges=elist)
        return wlist
Exemple #2
0
 def weights(cls, graph, elist=None, wlist=None, distrib="constant",
             distrib_prop={}, correl=None, noise_scale=None):
     '''
     Compute the weights of the graph's edges.
     @todo: take elist into account
     
     Parameters
     ----------
     graph : class:`~nngt.Graph` or subclass
         Graph the nodes belong to.
     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: "constant")
         Type of distribution (choose among "constant", "uniform", 
         "lognormal", "gaussian", "user_def", "lin_corr", "log_corr").
     distrib_prop : class:`dict`, optional (default: {})
         Dictionary containing the distribution parameters.
     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.
     
     Returns
     -------
     new_weights : class:`scipy.sparse.lil_matrix`
         A sparse matrix containing *ONLY* the newly-computed weights.
     '''
     corr = correl
     if issubclass(correl.__class__, str):
         if correl == "betweenness":
             corr = graph.get_betweenness(False)[1]
         else:
             corre = graph[correl]
     if wlist is not None:
         num_edges = graph.edge_nb() if elist is None else max(elist.shape)
         if len(wlist) != num_edges:
             raise InvalidArgument("`dlist` must have one entry per edge.")
     else:
         wlist = eprop_distribution(graph, distrib, elist=elist,
                     correl_attribute=corr, **distrib_prop)
     # add to the graph container
     bwlist = wlist.max() - wlist if wlist.any() else []
     graph.set_edge_attribute(WEIGHT, value_type="double", values=wlist)
     graph.set_edge_attribute(BWEIGHT, value_type="double", values=bwlist)
     return wlist
Exemple #3
0
 def delays(graph, dlist=None, elist=None, distrib="constant",
            distrib_prop={}, correl=None, noise_scale=None):
     '''
     Compute the delays of the neuronal connections.
     
     Parameters
     ----------
     graph : class:`~nngt.Graph` or subclass
         Graph the nodes belong to.
     dlist : class:`numpy.array`, optional (default: None)
         List of user-defined delays).
     elist : class:`numpy.array`, optional (default: None)
         List of the edges which value should be updated.
     distrib : class:`string`, optional (default: "constant")
         Type of distribution (choose among "constant", "uniform", 
         "lognormal", "gaussian", "user_def", "lin_corr", "log_corr").
     distrib_prop : class:`dict`, optional (default: {})
         Dictionary containing the distribution parameters.
     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.
     
     Returns
     -------
     new_delays : class:`scipy.sparse.lil_matrix`
         A sparse matrix containing *ONLY* the newly-computed weights.
     '''
     corr = correl
     if issubclass(correl.__class__, str):
         if correl == "betweenness":
             corr = graph.get_betweenness(False)[1]
         else:
             corre = graph[correl]
     if dlist is not None:
         num_edges = graph.edge_nb() if elist is None else len(elist)
         if len(dlist) != num_edges:
             raise InvalidArgument("`dlist` must have one entry per edge.")
     else:
         dlist = eprop_distribution(graph, distrib, elist=elist,
                     correl_attribute=corr, **distrib_prop)
     # add to the graph container
     graph.set_edge_attribute(DELAY, value_type="double", values=dlist)
     return dlist
Exemple #4
0
    def delays(graph, dlist=None, elist=None, distribution="constant",
               parameters={}, noise_scale=None):
        '''
        Compute the delays of the neuronal connections.

        Parameters
        ----------
        graph : class:`~nngt.Graph` or subclass
            Graph the nodes belong to.
        dlist : class:`numpy.array`, optional (default: None)
            List of user-defined delays).
        elist : class:`numpy.array`, optional (default: None)
            List of the edges which value should be updated.
        distribution : class:`string`, optional (default: "constant")
            Type of distribution (choose among "constant", "uniform",
            "lognormal", "gaussian", "user_def", "lin_corr", "log_corr").
        parameters : class:`dict`, optional (default: {})
            Dictionary containing the distribution parameters.
        noise_scale : class:`int`, optional (default: None)
            Scale of the multiplicative Gaussian noise that should be applied
            on the weights.

        Returns
        -------
        new_delays : class:`scipy.sparse.lil_matrix`
            A sparse matrix containing *ONLY* the newly-computed weights.
        '''
        parameters["btype"] = parameters.get("btype", "edge")
        parameters["use_weights"] = parameters.get("use_weights", False)
        elist = np.array(elist) if elist is not None else elist
        if dlist is not None:
            num_edges = graph.edge_nb() if elist is None else elist.shape[0]
            if len(dlist) != num_edges:
                raise InvalidArgument("`dlist` must have one entry per edge.")
        else:
            dlist = eprop_distribution(graph, distribution, elist=elist,
                                       **parameters)
        # add to the graph container
        graph.set_edge_attribute(
            DELAY, value_type="double", values=dlist, edges=elist)
        return dlist