Esempio n. 1
0
def graph_measures(graph: gt.Graph) -> pd.DataFrame:
    def get_attrs(attrs):
        return (attrs[1][0], attrs[1][1][1], attrs[0])

    def append_val(key, prop, v):
        measures[key][0].append(prop[v])

    _, vp_authority, vp_hub = gt.hits(graph)

    measures = {
        key: ([], prop)
        for key, prop in {
            'tp_group': graph.vp.group_name,
            'tp_author': graph.vp.username,
            'tn_degree_in': graph.degree_property_map('in'),
            'tn_degree_out': graph.degree_property_map('out'),
            'tn_degree_total': graph.degree_property_map('total'),
            'tn_pagerank': gt.pagerank(graph),
            'tn_betweenness': gt.betweenness(graph)[0],
            'tn_closeness': gt.closeness(graph),
            'tn_eigenvector': gt.eigenvector(graph)[1],
            'tn_authority': vp_authority,
            'tn_hub': vp_hub,
            'tn_lcc': gt.local_clustering(graph)
        }.items()
    }

    for attrs in product(graph.vertices(), measures.items()):
        append_val(*get_attrs(attrs))

    return pd.DataFrame(
        dict(map(lambda item: (item[0], item[1][0]),
                 measures.items()))).fillna(0)
Esempio n. 2
0
def clusteringStats(g):
    clustring_vertices = local_clustering(g).a
    print("Clusterização")
    stats(clustring_vertices)
    print("\tGlobal", global_clustering(g)[0])

    histogram(np.histogram(clustring_vertices),
              "Distribuição de clusterização", "$C_i$", "$C$",
              sys.argv[1][:-8] + ".clusterizacao")
 def sredni_wspolczynnik_klasteryzacji(self):
     '''The local clustering coefficient [watts-collective-1998] ci is defined as
     ci=|{ejk}| / (ki(ki−1))   :vj,vk∈Ni,ejk∈E
     where ki is the out-degree of vertex i, and
     Ni={vj:eij∈E}
     is the set of out-neighbours of vertex i.
     For undirected graphs the value of ci is normalized as  c′i=2ci.
     The implemented algorithm runs in O(|V|⟨k⟩2) time, where ⟨k⟩ is the average out-degree
     https://en.wikipedia.org/wiki/Clustering_coefficient'''
     lc = local_clustering(self.graph, undirected=True)
     return vertex_average(self.graph, lc)[0]
 def sredni_wspolczynnik_klasteryzacji(self):
     '''The local clustering coefficient [watts-collective-1998] ci is defined as
     ci=|{ejk}| / (ki(ki−1))   :vj,vk∈Ni,ejk∈E
     where ki is the out-degree of vertex i, and
     Ni={vj:eij∈E}
     is the set of out-neighbours of vertex i.
     For undirected graphs the value of ci is normalized as  c′i=2ci.
     The implemented algorithm runs in O(|V|⟨k⟩2) time, where ⟨k⟩ is the average out-degree
     https://en.wikipedia.org/wiki/Clustering_coefficient'''
     lc = local_clustering(self.graph, undirected=True)
     return vertex_average(self.graph, lc)[0]
Esempio n. 5
0
def cohesion_index(graph, seed):
    g = graph.copy()

    filt = graph.new_vertex_property('bool')
    for vertex in seed:
        filt[vertex] = True
    g.set_vertex_filter(filt)
    g.purge_vertices()

    clust = gt.local_clustering(g)

    ic = np.mean(clust.a)

    return ic
Esempio n. 6
0
def compute_and_save_global_clustering(g, filename):
    clust = gt.local_clustering(g, undirected=False)[0]
    add_property(g, "clustering", "double", clust)
    g.save(filename)
Esempio n. 7
0
#############
closeness = GT.closeness(GT.extract_largest_component(g), norm=False, harmonic=True).get_array()

plt.title("Closeness distribution")
plt.ylabel('#Nodes')
plt.xlabel('Closeness coefficient')
plt.bar(*float_distribution(closeness, 40), width=(max(closeness)-min(closeness))/50)
plt.savefig(f"img/closeness_dist.png", format='png')
plt.close()

print(f"top {TOP} closeness nodes: {get_top(closeness, TOP)}")
del closeness

##############
# Clustering #
##############
clustering = list(GT.local_clustering(g))

plt.title("Clustering distribution")
plt.ylabel('#Nodes')
plt.xlabel('Local clustering coefficient')
plt.bar(*float_distribution(clustering, 40), width=(max(clustering)-min(clustering))/50)
plt.savefig(f"img/clustering_dist.png", format='png')
plt.close()

print(f"top {TOP} local clustering nodes: {get_top(clustering, TOP)}")
del clustering


draw(g, 'deg', output='network.pdf', vertex_size=5, edge_pen_width=1, output_size=(1000,1000))
Esempio n. 8
0
def lcl_clus_coef_dist(g):
    return gt.local_clustering(g).get_array()
Esempio n. 9
0
def lcl_clus_coef(g):
    return gt_stats.vertex_average(g, gt.local_clustering(g))[0]
Esempio n. 10
0
    CoocEdgeWeight = gtgCooc.edge_properties['weight']
    CoocVertexId = gtgCooc.vertex_properties['id']
    CoocVertexIter = gtgCooc.vertices()
    print("4")
    CoocBetween, ep = gt.betweenness(gtgCooc, weight=CoocEdgeWeight, norm=True)
    print("5")
    #ee, CoocEigen = gt.eigenvector(gtgCooc, weight=CoocEdgeWeight)
    print("6")
    #ee, CoocAuthority, CoocHub = gt.hits(gtgCooc, weight =CoocEdgeWeight)
    #CoocPagerank = gt.pagerank(gtgCooc, weight =CoocEdgeWeight)
    CoocCloseness = gt.closeness(gtgCooc, weight=CoocEdgeWeight)

    print("7")
    CoocKatz = gt.katz(gtgCooc, weight=CoocEdgeWeight)
    CoocClustering = gt.local_clustering(gtgCooc)
    print("8")
    CoocDegree = gtgCooc.degree_property_map("total", weight=CoocEdgeWeight)
    print("9")
    print("where")
    print("A")
    print len(nodeList)
    print("B")

    tempCoocList = []
    for i in CoocVertexIter:
        temp = (str(j_id), CoocVertexId[i], CoocDegree[i], CoocBetween[i],
                CoocCloseness[i], CoocKatz[i], CoocKatz[i], CoocClustering[i],
                "3")

        temp = [