<commit_before># -*- coding: utf-8 -*-
"""
Flow Hierarchy.
"""
#    Copyright (C) 2004-2011 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.
import networkx as nx
__authors__ = "\n".join(['<NAME> (<EMAIL>)'])
__all__ = ['flow_hierarchy']

def flow_hierarchy(G,weight=None):
    """Returns the flow hierarchy of a directed network `G'.

    Flow hierarchy is defined as the fraction of edges not participating
    in cycles in a directed graph.[1].

    Parameters
    ----------
    G : NetworkX DiGraph or MultiDiGraph
        Graph to be analyzed.
    weight : key,optional (default=None)
        Value for weights on nodes. If None defaults to 1

    Returns
    -------
    h : float
       flow heirarchy value for the network

    Notes
    -----
    In [1] they use an algorithm which repeatedly exponentiates the link
    adjacency matrix and then looks for zeros on the diagonal. This has a
    running time of O(m^(log(m)). However, an edge is in a cycle iff it is
    in a strongly connected component, which can be found in O(m) time using
    Tarjan's algorithm
    
    References
    ----------
    .. [1] Luo, J.; Magee, C.L. (2011),
    Detecting evolving patterns of self-organizing networks by flow
    hierarchy measurement, Complexity, Volume 16 Issue 6 53-61

    """
    if not G.is_directed():
        raise nx.NetworkXError("G must be a digraph in flow_heirarchy")
    cG = nx.condensation_multigraph(G)
    return cG.size(weight=weight)/float(G.size(weight=weight))
    <commit_msg>Altered flow_hierarchy to not save new graph, to save memory.<commit_after># -*- coding: utf-8 -*-
"""
Flow Hierarchy.
"""
#    Copyright (C) 2004-2011 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.
import networkx as nx
__authors__ = "\n".join(['<NAME> (<EMAIL>)'])
__all__ = ['flow_hierarchy']

def flow_hierarchy(G,weight=None):
    """Returns the flow hierarchy of a directed network `G'.

    Flow hierarchy is defined as the fraction of edges not participating
    in cycles in a directed graph.[1].

    Parameters
    ----------
    G : NetworkX DiGraph or MultiDiGraph
        Graph to be analyzed.
    weight : key,optional (default=None)
        Value for weights on nodes. If None defaults to 1

    Returns
    -------
    h : float
       flow heirarchy value for the network

    Notes
    -----
    In [1] they use an algorithm which repeatedly exponentiates the link
    adjacency matrix and then looks for zeros on the diagonal. This has a
    running time of O(m^(log(m)). However, an edge is in a cycle iff it is
    in a strongly connected component, which can be found in O(m) time using
    Tarjan's algorithm
    
    References
    ----------
    .. [1] Luo, J.; Magee, C.L. (2011),
    Detecting evolving patterns of self-organizing networks by flow
    hierarchy measurement, Complexity, Volume 16 Issue 6 53-61

    """
    if not G.is_directed():
        raise nx.NetworkXError("G must be a digraph in flow_heirarchy")
    scc = nx.strongly_connected_components(G)
    return 1.0 - sum(G.subgraph(c).size(weight=weight) for c in scc)/float(G.size(weight=weight))
{'fraction_non_alphanumeric': 0.11730114515629836, 'fraction_numerical': 0.01547508511296812, 'mean_word_length': 2.6519774011299435, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '7573122', 'n_tokens_mistral': 1028, 'n_tokens_neox': 962, 'n_words': 376}