-
Notifications
You must be signed in to change notification settings - Fork 0
/
testStream.py
75 lines (46 loc) · 1.48 KB
/
testStream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from collections import defaultdict
import itertools
import time
import sys
import copy
import csv
from itertools import combinations
from loadGraph import loadGraph
from Louvain import Louvain
from FindEndogenousViaRandomWalks import endogenous
from rankMetricM import rankMetricM
from rankMetricRC import rankMetricRC
from ResAndDis import resAndDis
import igraph as ig
from initPartition import initPartition
import numpy as np
import networkx as nx
import netwulf as nw
edgeFile = "datasets/coraEdgelist.csv"
#edgeFile = "datasets/email.csv"
# Load the graph
G = loadGraph(edgeFile)
# Number of nodes of the initial G
nodesLen = G.number_of_nodes()
#nodesLen = g.vcount()
#for edges: G.ecount()
g = ig.Graph.TupleList(G.edges(), directed=True)
# Find the initial partitioning from the given comm file
InitialPartition, lisInitialPartition = initPartition(g)
partitionI = InitialPartition
# Create a network
#G = nx.random_partition_graph([10, 10, 10], .25, .01)
# Change 'block' node attribute to 'group'
#for k, v in G.nodes(data=True):
# v['group'] = v['block']; del v['block']
# Or detect communities and encode them in 'group' attribute
# import community
# bb = community.best_partition(G)
nx.set_node_attributes(G,partitionI, 'group')
# Set node 'size' attributes
for n, data in G.nodes(data=True):
data['size'] = np.random.random()
# Set link 'weight' attributes
#for n1, n2, data in G.edges(data=True):
# data['weight'] = np.random.random()
nw.visualize(G)