Example #1
0
def get_properties_with_sanppy(extension, input_folder):
    id_map = {}
    next_id = 0
    graph = snap.PNGraph.New()
    files_read = 0
    for file in os.listdir(input_folder):
        if not extension or file.endswith(extension):
            files_read += 1
            with open(os.path.join(input_folder, file)) as file:
                for line in file.readlines():
                    edge = line.rstrip().split()
                    n1 = id_map.get(edge[0], next_id)
                    if n1 == next_id:
                        id_map[edge[0]] = n1
                    next_id += 1
                    n2 = id_map.get(edge[1], next_id)
                    if n2 == next_id:
                        id_map[edge[1]] = n2
                    next_id += 1
                    if not graph.IsNode(n1):
                        graph.AddNode(n1)
                    if not graph.IsNode(n2):
                        graph.AddNode(n2)
                    graph.AddEdge(n1, n2)
    ef_diam_l, ef_diam_h, diam, sp = snap.GetBfsEffDiamAll(graph, 10, True)
    properties = [
        snap.CntNonZNodes(graph),
        snap.CntUniqDirEdges(graph),
        snap.IsConnected(graph),
        snap.CntNonZNodes(graph) / snap.CntUniqDirEdges(graph),
        snap.GetClustCf(graph), sp, diam,
        snap.CntUniqDirEdges(graph) /
        (snap.CntNonZNodes(graph) * snap.CntNonZNodes(graph))
    ]
    return dict(zip(get_property_names(), properties))
Example #2
0
def getBasicInfo(strPath, net):

    G = snap.LoadEdgeList(snap.PUNGraph,strPath,0,1)
    GraphInfo = {}
    GraphInfo['nodes'] = G.GetNodes()
    GraphInfo['edges'] = G.GetEdges()
    GraphInfo['zeroDegNodes'] = snap.CntDegNodes(G, 0)
    GraphInfo['zeroInDegNodes'] = snap.CntInDegNodes(G, 0)
    GraphInfo['zeroOutDegNodes'] = snap.CntOutDegNodes(G, 0)
    GraphInfo['nonZeroIn-OutDegNodes'] = snap.CntNonZNodes(G)
    GraphInfo['uniqueDirectedEdges'] = snap.CntUniqDirEdges(G)
    GraphInfo['uniqueUndirectedEdges'] = snap.CntUniqUndirEdges(G)
    GraphInfo['selfEdges'] = snap.CntSelfEdges(G)
    GraphInfo['biDirEdges'] = snap.CntUniqBiDirEdges(G)

    NTestNodes = 10
    IsDir = False
    GraphInfo['approxFullDiameter'] = snap.GetBfsEffDiam(G, NTestNodes, IsDir)
    GraphInfo['90effectiveDiameter'] = snap.GetAnfEffDiam(G)

    DegToCntV = snap.TIntPrV()
    snap.GetDegCnt(G, DegToCntV)
    sumofNode = G.GetNodes()
    L = [item.GetVal1()*item.GetVal2() for item in DegToCntV]
    GraphInfo['averageDegree'] = float(sum(L))/(sumofNode)

    (DegreeCountMax ,Degree, DegreeCount, CluDegree, Clu) = getGraphInfo(G)
    # creatNet(G,net)

    return GraphInfo,DegreeCountMax , Degree, DegreeCount, CluDegree, Clu
Example #3
0
def partOneAndTwo(WikiG):
    # WikiG.Dump()
    print('1. Number of nodes: '+str(WikiG.GetNodes()))

    selfloop_cnt = 0
    for node in WikiG.Nodes():
        # print(node.GetId())
        if WikiG.IsEdge(node.GetId(), node.GetId()):
            selfloop_cnt += 1
    print('2. Self loop Node: {}'.format(selfloop_cnt))

    cnt_dir = snap.CntUniqDirEdges(WikiG)
    print('3. The number of directed edges: {}'.format(cnt_dir))

    cnt_undir = snap.CntUniqUndirEdges(WikiG)
    print("4. The number of unique undirected edges is %d" % cnt_undir)
    print("5. The number of reciprocated edges is %d" % (cnt_dir - cnt_undir))

    cnt_in = snap.CntInDegNodes(WikiG, 0)
    print("6. The number of nodes of zero out-degree is %d" % cnt_in)
    cnt_out = snap.CntOutDegNodes(WikiG, 0)
    print("7. The number of nodes of zero in-degree is %d" % cnt_out)

    cnt_deg_above_10 = 0
    cnt_deg_less_10 = 0
    for node in WikiG.Nodes():
        if node.GetOutDeg() > 10:
            cnt_deg_above_10 += 1
        if node.GetInDeg() < 10:
            cnt_deg_less_10 += 1
    print("8. The number of nodes with more than 10 outgoing edges is %d" % cnt_deg_above_10)
    print("9. The number of nodes with fewer than 10 incoming edges is %d" % cnt_deg_less_10)


    # Part 2
    out_file_name = 'wiki'
    snap.PlotInDegDistr(WikiG, out_file_name, "Directed graph - in-degree Distribution")
    snap.PlotOutDegDistr(WikiG, out_file_name, "Directed graph - out-degree Distribution")

    InDegDistr = np.loadtxt("inDeg."+out_file_name+".tab")
    InDegDistr = InDegDistr[InDegDistr[:, 0] > 0]

    OutDegDistr = np.loadtxt("OutDeg."+out_file_name+".tab")
    # print(OutDegDistr.shape)
    OutDegDistr = OutDegDistr[OutDegDistr[:, 0] > 0]
    # print(OutDegDistr.shape)

    coff = np.polyfit(np.log10(OutDegDistr)[:, 0], np.log10(OutDegDistr)[:, 1], 1)
    print(coff)
    plt.figure()
    plt.subplot(211)
    plt.loglog(InDegDistr[:, 0], InDegDistr[:, 1])
    plt.title('In deg Distr')
    plt.subplot(212)
    plt.loglog(OutDegDistr[:, 0], OutDegDistr[:, 1])
    plt.loglog(OutDegDistr[:, 0], np.power(10, coff[1])*np.power(OutDegDistr[:, 0], coff[0]))
    plt.title('Out deg Distr & Last-Square Reg Line in log-log plot')
    plt.show()
Example #4
0
def quick_properties(graph, name, dic_path):
    """Get quick properties of the graph "name". dic_path is the path of the dict {players: id} """
    n_edges = graph.GetEdges()
    n_nodes = graph.GetNodes()
    print("##########")
    print("Quick overview of {} Network".format(name))
    print("##########")
    print("{} Nodes, {} Edges").format(n_nodes, n_edges)
    print("{} Self-edges ".format(snap.CntSelfEdges(graph)))
    print("{} Directed edges, {} Undirected edges".format(
        snap.CntUniqDirEdges(graph), snap.CntUniqUndirEdges(graph)))
    print("{} Reciprocated edges".format(snap.CntUniqBiDirEdges(graph)))
    print("{} 0-out-degree nodes, {} 0-in-degree nodes".format(
        snap.CntOutDegNodes(graph, 0), snap.CntInDegNodes(graph, 0)))
    node_in = graph.GetNI(snap.GetMxInDegNId(graph))
    node_out = graph.GetNI(snap.GetMxOutDegNId(graph))
    print("Maximum node in-degree: {}, maximum node out-degree: {}".format(
        node_in.GetDeg(), node_out.GetDeg()))
    print("###")
    components = snap.TCnComV()
    snap.GetWccs(graph, components)
    max_wcc = snap.GetMxWcc(graph)
    print "{} Weakly connected components".format(components.Len())
    print "Largest Wcc: {} Nodes, {} Edges".format(max_wcc.GetNodes(),
                                                   max_wcc.GetEdges())
    prankH = snap.TIntFltH()
    snap.GetPageRank(graph, prankH)
    sorted_prankH = sorted(prankH, key=lambda key: prankH[key], reverse=True)
    NIdHubH = snap.TIntFltH()
    NIdAuthH = snap.TIntFltH()
    snap.GetHits(graph, NIdHubH, NIdAuthH)
    sorted_NIdHubH = sorted(NIdHubH,
                            key=lambda key: NIdHubH[key],
                            reverse=True)
    sorted_NIdAuthH = sorted(NIdAuthH,
                             key=lambda key: NIdAuthH[key],
                             reverse=True)
    with open(dic_path, 'rb') as dic_id:
        mydict = pickle.load(dic_id)
        print("3 most central players by PageRank scores: {}, {}, {}".format(
            list(mydict.keys())[list(mydict.values()).index(sorted_prankH[0])],
            list(mydict.keys())[list(mydict.values()).index(sorted_prankH[1])],
            list(mydict.keys())[list(mydict.values()).index(
                sorted_prankH[2])]))
        print("Top 3 hubs: {}, {}, {}".format(
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdHubH[0])],
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdHubH[1])],
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdHubH[2])]))
        print("Top 3 authorities: {}, {}, {}".format(
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdAuthH[0])],
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdAuthH[1])],
            list(mydict.keys())[list(mydict.values()).index(
                sorted_NIdAuthH[2])]))
Example #5
0
def analyze_with_sanppy(extension, input_path):
    id_map = {}
    next_id = 0
    graph = snap.PNGraph.New()
    files_read = 0
    if os.path.isdir(input_path):
        for file in os.listdir(input_path):
            if not extension or file.endswith(extension):
                files_read += 1
                next_id = load_graph_from_file(os.path.join(input_path, file), graph, id_map, next_id)
    else:
        load_graph_from_file(input_path, graph, id_map, next_id)
    print("Nodes: {}".format(snap.CntNonZNodes(graph)))
    print("Edges: {}".format(snap.CntUniqDirEdges(graph)))
    print("Connected: {}".format(snap.IsConnected(graph)))
    print("Average degree: {}".format(snap.CntNonZNodes(graph) / snap.CntUniqDirEdges(graph)))
    print("Average clustering coefficient: {}".format(snap.GetClustCf(graph)))
    ef_diam_l, ef_diam_h, diam, sp = snap.GetBfsEffDiamAll(graph, 10, True)
    print("Average shortest-path: {}".format(sp))
    print("Diameter: {}".format(diam))
    print("Density: {}".format(snap.CntUniqDirEdges(graph)/(snap.CntNonZNodes(graph)*snap.CntNonZNodes(graph))))
def wikiVotingNetwork():

    Component = snap.TIntPrV()
    #Loding the graph
    Wiki = snap.LoadEdgeList(snap.PNGraph, "Wiki-Vote.txt", 0, 1)
    #Printing Number of Nodes in the Graph
    print "Number of Nodes: ", Wiki.GetNodes()
    #Printing Number of Edges in the Graph
    print "Number of Edges: ", Wiki.GetEdges()
    #Printing Number of Directed Edges in the Graph
    print "Number of Directed Edges: ", snap.CntUniqDirEdges(Wiki)
    #Printing Number of Un-Directed Edges in the Graph
    print "Number of Undirected Edges: ", snap.CntUniqUndirEdges(Wiki)
    #Printing Number of Directed Edges in the Graph
    print "Number of Self-Edges: ", snap.CntSelfEdges(Wiki)
    #Printing Number of Zero InDeg Nodes in the Graph
    print "Number of Zero InDeg Nodes: ", snap.CntInDegNodes(Wiki, 0)
    #Printing Number of Zero OutDeg Nodes in the Graph
    print "Number of Zero OutDeg Nodes: ", snap.CntOutDegNodes(Wiki, 0)
    #Printing Node ID with maximum degree in the Graph
    print "Node ID with maximum degree: ", snap.GetMxDegNId(Wiki)

    snap.GetSccSzCnt(Wiki, Component)

    for comp in Component:
        #printing number of strongly connected components with size
        print "Size: %d - Number of Strongly Connected Components: %d" % (
            comp.GetVal1(), comp.GetVal2())
    #printing size of largest connected components
    print "Size of largest connected component: ", snap.GetMxSccSz(Wiki)

    snap.GetWccSzCnt(Wiki, Component)

    for comp in Component:
        #printing number of weekly connected components with size
        print "Size: %d - Number of Weekly Connected Component Wikipedia: %d" % (
            comp.GetVal1(), comp.GetVal2())

    #printing size of weekly connected components
    print "Size of Weakly connected component: ", snap.GetMxWccSz(Wiki)
    #plotting out-degree distribution
    snap.PlotOutDegDistr(Wiki, "wiki-analysis",
                         "Directed graph - Out-Degree Distribution")
Example #7
0
print "\n"

c = 0
for e in g.Edges():
    if (e.GetSrcNId() == e.GetDstNId()):
        c = c + 1
print c
print "\n"

# c=0;
# for e in g.Edges():
# 	if(e.GetSrcNId()!=e.GetDstNId()):
# 		c=c+1;
# print c;
# print "\n"
print snap.CntUniqDirEdges(g)
print '\n'

# cc=0;
# ug=snap.ConvertGraph(snap.PUNGraph,g);
# for e in ug.Edges():
# 	if(e.GetSrcNId()!=e.GetDstNId()):
# 		cc=cc+1;
# print cc;
# print "\n";
print snap.CntUniqUndirEdges(g)
print '\n'

# print c-cc;
# print "\n";
print snap.CntUniqBiDirEdges(g)
Example #8
0
def quick_properties(graph, name, dic_path):
    """Get quick properties of the graph "name". dic_path is the path of the dict {players: id} """
    results = {}
    n_edges = graph.GetEdges()
    n_nodes = graph.GetNodes()
    n_self_edges = snap.CntSelfEdges(graph)
    n_directed_edges, n_undirected_edges = snap.CntUniqDirEdges(
        graph), snap.CntUniqUndirEdges(graph)
    n_reciprocated_edges = snap.CntUniqBiDirEdges(graph)
    n_zero_out_nodes, n_zero_in_nodes = snap.CntOutDegNodes(
        graph, 0), snap.CntInDegNodes(graph, 0)
    max_node_in = graph.GetNI(snap.GetMxInDegNId(graph)).GetDeg()
    max_node_out = graph.GetNI(snap.GetMxOutDegNId(graph)).GetDeg()
    components = snap.TCnComV()
    snap.GetWccs(graph, components)
    max_wcc = snap.GetMxWcc(graph)
    results["a. Nodes"] = n_nodes
    results["b. Edges"] = n_edges
    results["c. Self-edges"] = n_self_edges
    results["d. Directed edges"] = n_directed_edges
    results["e. Undirected edges"] = n_undirected_edges
    results["f. Reciprocated edges"] = n_reciprocated_edges
    results["g. 0 out-degree nodes"] = n_zero_out_nodes
    results["h. 0 in-degree nodes"] = n_zero_in_nodes
    results["i. Maximum node out-degree"] = max_node_out
    results["j. Maximum node in-degree"] = max_node_in
    results["k. Weakly connected components"] = components.Len()
    results["l. Nodes, edges of largest WCC"] = (max_wcc.GetNodes(),
                                                 max_wcc.GetEdges())
    print("##########")
    print("Quick overview of {} Network".format(name))
    print("##########")
    print("{} Nodes, {} Edges".format(n_nodes, n_edges))
    print("{} Self-edges ".format(n_self_edges))
    print("{} Directed edges, {} Undirected edges".format(
        n_directed_edges, n_undirected_edges))
    print("{} Reciprocated edges".format(n_reciprocated_edges))
    print("{} 0-out-degree nodes, {} 0-in-degree nodes".format(
        n_zero_out_nodes, n_zero_in_nodes))
    print("Maximum node in-degree: {}, maximum node out-degree: {}".format(
        max_node_in, max_node_out))
    print("###")
    print "{} Weakly connected components".format(components.Len())
    print "Largest Wcc: {} Nodes, {} Edges".format(max_wcc.GetNodes(),
                                                   max_wcc.GetEdges())

    prankH = snap.TIntFltH()
    snap.GetPageRank(graph, prankH)
    sorted_prankH = sorted(prankH, key=lambda key: prankH[key], reverse=True)
    NIdHubH = snap.TIntFltH()
    NIdAuthH = snap.TIntFltH()
    snap.GetHits(graph, NIdHubH, NIdAuthH)
    sorted_NIdHubH = sorted(NIdHubH,
                            key=lambda key: NIdHubH[key],
                            reverse=True)
    sorted_NIdAuthH = sorted(NIdAuthH,
                             key=lambda key: NIdAuthH[key],
                             reverse=True)
    with open(dic_path, 'rb') as dic_id:
        mydict = pickle.load(dic_id)
        print("3 most central players by PageRank scores: {}, {}, {}".format(
            name_from_index(sorted_prankH, 0, mydict),
            name_from_index(sorted_prankH, 1, mydict),
            name_from_index(sorted_prankH, 2, mydict)))
        print("Top 3 hubs: {}, {}, {}".format(
            name_from_index(sorted_NIdHubH, 0, mydict),
            name_from_index(sorted_NIdHubH, 1, mydict),
            name_from_index(sorted_NIdHubH, 2, mydict)))
        print("Top 3 authorities: {}, {}, {}".format(
            name_from_index(sorted_NIdAuthH, 0, mydict),
            name_from_index(sorted_NIdAuthH, 1, mydict),
            name_from_index(sorted_NIdAuthH, 2, mydict)))
        results["m. Three top PageRank"] = (name_from_index(
            sorted_prankH, 0, mydict), name_from_index(
                sorted_prankH, 1,
                mydict), name_from_index(sorted_prankH, 2, mydict))
        results["n. Three top hubs"] = (name_from_index(
            sorted_NIdHubH, 0,
            mydict), name_from_index(sorted_NIdHubH, 1, mydict),
                                        name_from_index(
                                            sorted_NIdHubH, 2, mydict))
        results["o. Three top authorities"] = (name_from_index(
            sorted_NIdAuthH, 0,
            mydict), name_from_index(sorted_NIdAuthH, 1, mydict),
                                               name_from_index(
                                                   sorted_NIdAuthH, 2, mydict))
    return results
Example #9
0
import matplotlib.pyplot as plt

# Section 1 #
# Load data from file, then construct a directed graph
wiki_g = snap.LoadEdgeListStr(snap.PNGraph, "Wiki-Vote.txt", 0, 1)
# solution to hw
print('*' * 10 + ' Section I ' + '*' * 10)
print("The wiki-vote graph has " + str(wiki_g.GetNodes()) + " nodes.")
# self_loop_nodes = 0
# for edge in wiki_g.Edges():
#    if edge.GetSrcNId() == edge.GetDstNId():
#        self_loop_nodes = self_loop_nodes + 1
# Better use built-in functions to count the self-edges...
print("The wiki-vote graph has " + str(snap.CntSelfEdges(wiki_g)) +
      " self-looped nodes.")
print("The wiki-vote graph has " + str(snap.CntUniqDirEdges(wiki_g)) +
      " unique directed edges.")
print("The wiki-vote graph has " + str(snap.CntUniqUndirEdges(wiki_g)) +
      " unique undirected edges.")
print("The wiki-vote graph has " +
      str(int(snap.CntUniqUndirEdges(wiki_g) / 2)) + " reciprocated edges.")

nodes_zero_out_degree = 0
nodes_zero_in_degree = 0
nodes_more_than_10_outgoing_edges = 0
nodes_fewer_than_10_incoming_edges = 0

min_out_degree = 1
max_out_degree = 1

for node in wiki_g.Nodes():
Example #10
0
import snap
from twython import Twython
import sys

if __name__ == '__main__':
    CONSUMER_KEY, CONSUMER_SECRET = open('twitapikeys.txt').read().split()[:2]
    twitterapi = Twython(CONSUMER_KEY, CONSUMER_SECRET)

    filename = sys.argv[1]
    repliesgraph = snap.LoadEdgeList(snap.PNGraph, filename, 0, 1)
    snap.PrintInfo(repliesgraph, "Twitter replies network")
    print

    #reciprocity
    num_dir_edges = snap.CntUniqDirEdges(repliesgraph)
    print "{0:.2f}% of directed edges are reciprocal".format(
        snap.CntUniqBiDirEdges(repliesgraph) * 2 * 100 / num_dir_edges)

    #clustering coefficient
    print "The clustering coefficient is {0:.2f}%".format(
        snap.GetClustCf(repliesgraph) * 100)

    #strongly and weakly connected components
    CntV = snap.TIntPrV()
    snap.GetSccSzCnt(repliesgraph, CntV)
    num_cc = 0
    for p in CntV:
        print "{0} strongly connected component(s) of size {1}".format(
            p.GetVal2(), p.GetVal1())
        num_cc += p.GetVal2()
Example #11
0
wikiGraph = snap.LoadEdgeList(snap.PNGraph, SOURCE_FILE, 0, 1)
assert 103689 == wikiGraph.GetEdges()
assert 7115 == wikiGraph.GetNodes()

# 1.1
print("The number of nodes in the network is %s." % (
    wikiGraph.GetNodes()))

# 1.2
print("The number of nodes with a self-edge is %s." % (
    snap.CntSelfEdges(wikiGraph)))

# 1.3
print("The number of directed edges %s." % (
    snap.CntUniqDirEdges(wikiGraph)))

# 1.4
print("The number of undirected edges is %s." % (
    snap.CntUniqUndirEdges(wikiGraph)))

# 1.5
print("The number of reciprocated edges is %s." % (
    snap.CntUniqDirEdges(wikiGraph) - snap.CntUniqUndirEdges(wikiGraph)))

# 1.6
print("The number of nodes of zero out-degree is %s." % (
    snap.CntOutDegNodes(wikiGraph, 0)))

# 1.7
print("The number of nodes of zero in-degree is %s." % (
Example #12
0
    # self_loop_v_cnt = 0
    # direct_edge_cnt = 0
    # for edge in G1.Edges():
    #     src, dst = edge.GetSrcNId(), edge.GetDstNId()
    #     # print(src, dst)
    #     if src == dst:
    #         self_loop_v_cnt += 1
    #     else:
    #         direct_edge_cnt += 1

    # Answer 2:
    print('There are {} self-loop nodes'.format(snap.CntSelfEdges(G1)))

    # Answer 3:
    print('Thre are {} directed edges'.format(snap.CntUniqDirEdges(G1)))

    # Answer 4:
    print('There are {} undirect edges'.format(snap.CntUniqUndirEdges(G1)))

    # Answer 5:
    print('There are {} reciprocated edges'.format(snap.CntUniqBiDirEdges(G1)))

    # Answer 6:
    print('There are {} nodes having 0 out-degree'.format(
        snap.CntOutDegNodes(G1, 0)))

    # Answer 7:
    print('There are {} nodes having 0 in-degree'.format(
        snap.CntInDegNodes(G1, 0)))
Example #13
0
def numUniqueEdges(G):
    return snap.CntUniqDirEdges(G)
Example #14
0
            X.append(values[0])
            Y.append(values[1])
        else:
            ctr += 1

    plt.plot(X, Y)
    plt.title("dist of outDeg of nodes")

    plt.show()

if __name__ == '__main__':
    G = snap.LoadEdgeList(snap.PNGraph, "wiki-Vote.txt", 0, 1)

    print("nodes: %d, edges: %d" % (G.GetNodes(), G.GetEdges()))
    print("num of self directed egdes: %d" % (snap.CntSelfEdges(G)))
    print("num of directed edges: %d" % (snap.CntUniqDirEdges(G)))

    nodeOutDegZero = 0
    for node in G.Nodes():
        if node.GetOutDeg() == 0:
            nodeOutDegZero += 1
    print("number of nodes with zero out degree: %d" % nodeOutDegZero)


    '''for NI in G.Nodes():
      if G.IsEdge(NI.GetId(),NI.GetId()):
        print("%d"% (NI.GetId()))'''

    outDistPlot(G)
    LSRegression()
    GI.AddEdge(interestFile.iloc[i, 0], getval(S, interestFile.iloc[i, 1]))

snap.DrawGViz(G1, snap.gvlDot, "reco.png", "Network Diagram", True,
              snap.TIntStrH())

snap.PlotInDegDistr(G1, "Indeg", "Directed graph - in-degree")
snap.PlotOutDegDistr(G1, "Outdeg", "Directed graph - out-degree")

# vector of pairs of integers (size, count)
ComponentDist = snap.TIntPrV()
# get distribution of connected components (component size, count)
snap.GetWccSzCnt(G1, ComponentDist)
for comp in ComponentDist:
    print "Size: %d - Number of Components: %d" % (comp.GetVal1(),
                                                   comp.GetVal2())
Count = snap.CntUniqDirEdges(G1)
print "Directed Graph: Count of unique directed edges is %d" % Count

# get degree distribution pairs (degree, count)
snap.GetOutDegCnt(G1, ComponentDist)
print "Degree Distribution Pairs-"
xval = []
yval = []
for item in ComponentDist:
    print "%d nodes with out-degree %d" % (item.GetVal2(), item.GetVal1())
    xval.append(item.GetVal1())
    yval.append(item.GetVal2())
bins = np.arange(len(yval))
plt.hist(yval, xval, alpha=0.5, label='Nodes with Out degree')
plt.title('Distribution of Out degree by Nodes')
plt.xlabel('Out degree')
Example #16
0
 def numUniqueDirectedEdges(self):
     return snap.CntUniqDirEdges(self.rawGraph)
Example #17
0
                                  snap.TBool(False))

# graph will be an object of type snap.PNGraph
graph = snap.ToGraph(snap.PNGraph, sample_table, "srcID", "dstID",
                     snap.aaFirst)
#no of nodes
Count = snap.CntNonZNodes(graph)
print "Count of nodes with degree greater than 0 is %d" % Count
#no of edges
Count = snap.CntOutDegNodes(graph, 0)
print "Count of nodes with out-degree 0 is %d" % Count
#no of nodes with zero in-degree
Count = snap.CntInDegNodes(graph, 0)
print "Count of nodes with in-degree 0 is %d" % Count
#no of directed edges
Count = snap.CntUniqDirEdges(graph)
print "Count of directed edges is %d" % Count
#no of undirected edges
Count = snap.CntUniqUndirEdges(graph)
print "Count of undirected edges is %d" % Count
#no of self edges
Count = snap.CntSelfEdges(graph)
print "Count of self edges is %d" % Count
#no of unique bi-directional/reciprocated edges
Count = snap.CntUniqBiDirEdges(graph)
print "Count of unique bidirectional edges is %d" % Count

#no of nodes with out-degree greater than 10
OutDegV = snap.TIntPrV()
snap.GetNodeOutDegV(graph, OutDegV)
count_od = 0
Example #18
0
print("Source Node: ", mapping.GetKeyId(srcNode), "is", srcNode)
for dstNode in range(1, G0.GetMxNId()):
    if G0.IsEdge(mapping.GetKeyId(srcNode), dstNode):
        NIdV.Add(dstNode)
        pass

SubGraph = snap.GetSubGraph(G0, NIdV)

for outDeg in range(00, 10):
    for inDeg in range(00, 10):
        snap.DelDegKNodes(SubGraph, outDeg, inDeg)

for dstNode in range(1, SubGraph.GetMxNId()):
    if SubGraph.IsEdge(mapping.GetKeyId(srcNode), dstNode):
        print(dstNode, mapping.GetKey(dstNode))

Nodes = snap.TIntFltH()
Edges = snap.TIntPrFltH()
snap.GetBetweennessCentr(SubGraph, Nodes, Edges, 1.0)
for node in Nodes:
    print "node: %d centrality: %f" % (node, Nodes[node])

print snap.IsConnected(SubGraph)

snap.SaveEdgeList(
    SubGraph, "RelGraph.txt",
    "Save as tab-separated list of edges with no Zero InDeg Nodes")

print("Number of edges is %d" % (snap.CntUniqDirEdges(SubGraph)))

snap.PrintInfo(SubGraph)