Exemple #1
0
 def setUpClass(self):
     self.karate = nx.karate_club_graph()
     self.measures_no_part = gm.calculate_global_measures(self.karate)
     self.totalpart = {x: x for x in list(self.karate.nodes)}
     self.measures_part = gm.calculate_global_measures(
         self.karate, partition=self.totalpart)
     self.extra_measure = {'hat': 'cap'}
Exemple #2
0
 def test_from_existing(self):
     assert (gm.calculate_global_measures(
         self.karate,
         partition=self.totalpart,
         existing_global_measures=self.measures_no_part) ==
             self.measures_part)
     measures_with_extra = self.measures_no_part
     measures_with_extra.update(self.extra_measure)
     assert (gm.calculate_global_measures(
         self.karate,
         partition=self.totalpart,
         existing_global_measures=measures_with_extra) ==
             self.measures_part.update(self.extra_measure))
Exemple #3
0
    def calculate_global_measures(self,
                                  force=False,
                                  seed=None,
                                  partition=True):
        '''
        Calculate global measures `average_clustering`,
        `average_shortest_path_length`, `assortativity`, `modularity`, and
        `efficiency` of G. The resulting dictionary of global measures can be
        accessed and manipulated as ``G.graph['global_measures']``

        Parameters
        ----------
        force : bool
            pass True to recalculate any global measures that have already
            been calculated
        partition : bool
            The "modularity" measure evaluates a graph partition.
            pass True to calculate the partition of each graph using
            :func:`BrainNetwork.partition`. Note that this won't recalculate
            a partition that exists.
            If False, modularity may not be calculated.


        Returns
        -------
        dict
            a dictionary of global network measures of G

        See Also
        --------
        :func:`calculate_global_measures`
        '''
        if partition:
            self.partition()
            partition = nx.get_node_attributes(self, name='module')
        else:
            partition = None

        if force:
            global_measures = calculate_global_measures(self,
                                                        partition=partition)
            self.graph['global_measures'] = global_measures
        else:
            global_measures = calculate_global_measures(
                self,
                partition=partition,
                existing_global_measures=self.graph.get('global_measures'))
            self.graph['global_measures'].update(global_measures)
        return self.graph['global_measures']