code: def _modularity(
      self, membership, weights=None, resolution=1, directed=True
  ):
      """Calculates the modularity score of the graph with respect to a given
      clustering.
  
      The modularity of a graph w.r.t. some division measures how good the
      division is, or how separated are the different vertex types from each
      other. It's defined as M{Q=1/(2m)*sum(Aij-gamma*ki*kj/(2m)delta(ci,cj),i,j)}.
      M{m} is the number of edges, M{Aij} is the element of the M{A}
      adjacency matrix in row M{i} and column M{j}, M{ki} is the degree of
      node M{i}, M{kj} is the degree of node M{j}, and M{Ci} and C{cj} are
      the types of the two vertices (M{i} and M{j}), and M{gamma} is a resolution
      parameter that defaults to 1 for the classical definition of modularity.
      M{delta(x,y)} is one iff M{x=y}, 0 otherwise.
  
      If edge weights are given, the definition of modularity is modified as
      follows: M{Aij} becomes the weight of the corresponding edge, M{ki}
      is the total weight of edges adjacent to vertex M{i}, M{kj} is the
      total weight of edges adjacent to vertex M{j} and M{m} is the total
      edge weight in the graph.
  
      B{Reference}: MEJ Newman and M Girvan: Finding and evaluating community
      structure in networks. I{Phys Rev E} 69 026113, 2004.
  
      @param membership: a membership list or a L{VertexClustering} object
      @param weights: optional edge weights or C{None} if all edges are
        weighed equally. Attribute names are also allowed.
      @param resolution: the resolution parameter I{gamma} in the formula above.
        The classical definition of modularity is retrieved when the resolution
        parameter is set to 1.
      @param directed: whether to consider edge directions if the graph is directed.
        C{True} will use the directed variant of the modularity measure where the
        in- and out-degrees of nodes are treated separately; C{False} will treat
        directed graphs as undirected.
      @return: the modularity score
      """
      if isinstance(membership, VertexClustering):
          if membership.graph != self:
              raise ValueError(
                  "clustering object belongs to another graph"
              )
          return GraphBase.modularity(
              self, membership.membership, weights, resolution, directed
          )
      else:
          return GraphBase.modularity(
              self, membership, weights, resolution, directed
          )
  
file_path: python-igraph/src/igraph/community.py
imports: from igraph._igraph import GraphBase
  from igraph.clustering import VertexDendrogram, VertexClustering
  from igraph.utils import deprecated
  from typing import List, Sequence, Tuple
label_desc: Use image node_id 12 for calling a global function with example usage: _modularity(membership, weights, resolution, directed) and returns: GraphBase, GraphBase