How to use the igraph.mean function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
def calc_stats(network, edge_type, method, path):

    # if network is weighted
    if network.is_weighted():

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength())
        diameter = network.diameter(directed=False)
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / calc.py View on Github external
node_count = ig_network.vcount()
        edge_count = ig_network.ecount()
        directed_status = 'Directed' if ig_network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if ig_network.is_weighted() else 'No'
        connected_status = 'Yes' if ig_network.is_connected() else 'No'
        avg_degree = ig.mean(ig_network.degree(loops=False))
        avg_weighted_degree = ig.mean(ig_network.strength(weights='weight'))
        diameter = ig_network.diameter(directed=False, weights='weight')
        radius = ig_network.radius(mode='ALL')
        density = ig_network.density()
        modularity = ig_network.modularity(ig_network.community_multilevel(weights='weight'))
        communities = len(ig_network.community_multilevel(weights='weight'))
        components = len(ig_network.components())
        closeness = ig.mean(ig_network.closeness(weights='weight'))
        node_betweenness = ig.mean(ig_network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(ig_network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(ig_network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(ig_network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(ig_network.average_path_length(directed=False))

        # print stats to terminal
        print('> Network Overview\n')
        print('- Nodes: {}'.format(node_count))
        print('- Edges: {}'.format(edge_count))
        print('- Type: {}'.format(directed_status))
        print('- Weighted: {}'.format(weighted_status))
        print('- Connected: {}'.format(connected_status))
        print('- Average Degree: {0:.3f}'.format(avg_degree))
        print('- Average Weighted Degree: {0:.3f}'.format(avg_weighted_degree))
        print('- Diameter: {}'.format(diameter))
        print('- Radius: {}'.format(radius))
        print('- Density: {0:.3f}'.format(density))
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength())
        diameter = network.diameter(directed=False)
        radius = network.radius(mode='ALL')
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength())
        diameter = network.diameter(directed=False)
        radius = network.radius(mode='ALL')
        density = network.density()
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
# variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength())
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / calc.py View on Github external
edge_count = ig_network.ecount()
        directed_status = 'Directed' if ig_network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if ig_network.is_weighted() else 'No'
        connected_status = 'Yes' if ig_network.is_connected() else 'No'
        avg_degree = ig.mean(ig_network.degree(loops=False))
        avg_weighted_degree = ig.mean(ig_network.strength(weights='weight'))
        diameter = ig_network.diameter(directed=False, weights='weight')
        radius = ig_network.radius(mode='ALL')
        density = ig_network.density()
        modularity = ig_network.modularity(ig_network.community_multilevel(weights='weight'))
        communities = len(ig_network.community_multilevel(weights='weight'))
        components = len(ig_network.components())
        closeness = ig.mean(ig_network.closeness(weights='weight'))
        node_betweenness = ig.mean(ig_network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(ig_network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(ig_network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(ig_network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(ig_network.average_path_length(directed=False))

        # print stats to terminal
        print('> Network Overview\n')
        print('- Nodes: {}'.format(node_count))
        print('- Edges: {}'.format(edge_count))
        print('- Type: {}'.format(directed_status))
        print('- Weighted: {}'.format(weighted_status))
        print('- Connected: {}'.format(connected_status))
        print('- Average Degree: {0:.3f}'.format(avg_degree))
        print('- Average Weighted Degree: {0:.3f}'.format(avg_weighted_degree))
        print('- Diameter: {}'.format(diameter))
        print('- Radius: {}'.format(radius))
        print('- Density: {0:.3f}'.format(density))
        print('- Modularity: {0:.3f}'.format(modularity))
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / network.py View on Github external
def calc_stats(network, edge_type, method, path):

    # if network is weighted
    if network.is_weighted():

        # variables to hold stats
        node_count = network.vcount()
        edge_count = network.ecount()
        directed_status = 'Directed' if network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if network.is_weighted() else 'No'
        connected_status = 'Yes' if network.is_connected() else 'No'
        avg_degree = ig.mean(network.degree(loops=False))
        avg_weighted_degree = ig.mean(network.strength(weights='weight'))
        diameter = network.diameter(directed=False, weights='weight')
        radius = network.radius(mode='ALL')
        density = network.density()
        modularity = network.community_multilevel(weights='weight').modularity
        communities = len(network.community_multilevel(weights='weight'))
        components = len(network.components())
        closeness = ig.mean(network.closeness(weights='weight'))
        node_betweenness = ig.mean(network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(network.average_path_length(directed=False))

    # if network is not weighted
    else:
github SergiuTripon / msc-thesis-na-epsrc / analysis / src / calc.py View on Github external
directed_status = 'Directed' if ig_network.is_directed() else 'Undirected'
        weighted_status = 'Yes' if ig_network.is_weighted() else 'No'
        connected_status = 'Yes' if ig_network.is_connected() else 'No'
        avg_degree = ig.mean(ig_network.degree(loops=False))
        avg_weighted_degree = ig.mean(ig_network.strength(weights='weight'))
        diameter = ig_network.diameter(directed=False, weights='weight')
        radius = ig_network.radius(mode='ALL')
        density = ig_network.density()
        modularity = ig_network.modularity(ig_network.community_multilevel(weights='weight'))
        communities = len(ig_network.community_multilevel(weights='weight'))
        components = len(ig_network.components())
        closeness = ig.mean(ig_network.closeness(weights='weight'))
        node_betweenness = ig.mean(ig_network.betweenness(directed=False, weights='weight'))
        edge_betweenness = ig.mean(ig_network.edge_betweenness(directed=False, weights='weight'))
        avg_clustering_coeff = ig.mean(ig_network.transitivity_avglocal_undirected())
        eigenvector_centrality = ig.mean(ig_network.eigenvector_centrality(directed=False, weights='weight'))
        avg_path_length = ig.mean(ig_network.average_path_length(directed=False))

        # print stats to terminal
        print('> Network Overview\n')
        print('- Nodes: {}'.format(node_count))
        print('- Edges: {}'.format(edge_count))
        print('- Type: {}'.format(directed_status))
        print('- Weighted: {}'.format(weighted_status))
        print('- Connected: {}'.format(connected_status))
        print('- Average Degree: {0:.3f}'.format(avg_degree))
        print('- Average Weighted Degree: {0:.3f}'.format(avg_weighted_degree))
        print('- Diameter: {}'.format(diameter))
        print('- Radius: {}'.format(radius))
        print('- Density: {0:.3f}'.format(density))
        print('- Modularity: {0:.3f}'.format(modularity))
        print('- Communities: {}'.format(communities))