<commit_before># -*- coding: utf-8 -*-

import numpy as np
import networkx as nx

def get_base_modularity_matrix(network):
    '''
        Obtain the modularity matrix for the whole network

        Parameters
        ----------
        network : nx.Graph or nx.DiGraph
            The network of interest

        Returns
        -------
        np.matrix
            The modularity matrix for `network`

        Raises
        ------
        TypeError
            When the input `network` does not fit either nx.Graph or nx.DiGraph
    '''

    if type(network) == nx.Graph:
        return nx.modularity_matrix(network)
    elif type(network) == nx.DiGraph:
        return nx.directed_modularity_matrix(network)
    else:
        raise TypeError('Graph type not supported. Use either nx.Graph or nx.Digraph')

def _get_delta_Q(X, a):
    '''
        Calculate the detal modularity
        .. math::
            \deltaQ = s^T \cdot \^{B_{g}} \cdot s

        Parameters
        ----------
        X : np.matrix
            B_hat_g
        a : np.matrix
            s, which is the membership vector

        Returns
        -------
        float
            The corresponding ΔQ
    '''
    return np.dot(np.dot(a.T, X), a)[0, 0]

def get_modularity(network, community_dict):
    '''
        Calculate the modularity

        Undirected:
        .. math::
            Q = \frac{1}{2m}\sum_{i,j} \(A_ij - \frac{k_i k_j}{2m}\) * \detal_(c_i, c_j)
        Directed:
        .. math::
            Q = \frac{1}{m}\sum_{i,j} \(A_ij - \frac{k_i^{in} k_j^{out}}{m}\) * \detal_{c_i, c_j}

        Parameters
        ----------
        network : nx.Graph or nx.DiGraph
            The network of interest
        community_dict : dict
            A dictionary to store the membership of each node
            Key is node and value is community index

        Returns<commit_msg>use formula instead of symbols<commit_after># -*- coding: utf-8 -*-

import numpy as np
import networkx as nx

def get_base_modularity_matrix(network):
    '''
        Obtain the modularity matrix for the whole network

        Parameters
        ----------
        network : nx.Graph or nx.DiGraph
            The network of interest

        Returns
        -------
        np.matrix
            The modularity matrix for `network`

        Raises
        ------
        TypeError
            When the input `network` does not fit either nx.Graph or nx.DiGraph
    '''

    if type(network) == nx.Graph:
        return nx.modularity_matrix(network)
    elif type(network) == nx.DiGraph:
        return nx.directed_modularity_matrix(network)
    else:
        raise TypeError('Graph type not supported. Use either nx.Graph or nx.Digraph')

def _get_delta_Q(X, a):
    '''
        Calculate the detal modularity
        .. math::
            \deltaQ = s^T \cdot \^{B_{g}} \cdot s

        Parameters
        ----------
        X : np.matrix
            B_hat_g
        a : np.matrix
            s, which is the membership vector

        Returns
        -------
        float
            The corresponding \deltaQ
    '''
    return np.dot(np.dot(a.T, X), a)[0, 0]

def get_modularity(network, community_dict):
    '''
        Calculate the modularity

        Undirected:
        .. math::
            Q = \frac{1}{2m}\sum_{i,j} \(A_ij - \frac{k_i k_j}{2m}\) * \detal_(c_i, c_j)
        Directed:
        .. math::
            Q = \frac{1}{m}\sum_{i,j} \(A_ij - \frac{k_i^{in} k_j^{out}}{m}\) * \detal_{c_i, c_j}

        Parameters
        ----------
        network : nx.Graph or nx.DiGraph
            The network of interest
        community_dict : dict
            A dictionary to store the membership of each node
            Key is node and value is community index

        Returns
{'fraction_non_alphanumeric': 0.12047872340425532, 'fraction_numerical': 0.003723404255319149, 'mean_word_length': 1.5446549391069013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2992533', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1123, 'n_words': 323}