Beispiel #1
0
def generate_friends_network(user_count=10,
                             friends_count=get_friends_count(),
                             prob=get_prob(),
                             network_type='random',
                             conf_model=False):
    # User list, probability p and network_type is given, construct a graph
    res = "empty"

    # generate specific graphs
    if network_type.lower().find("small") >= 0:
        # This is a small world network
        print "Creating a small world network with " + str(
            user_count) + " users"
        rnd = snap.TRnd(1, 0)
        new_graph = snap.GenSmallWorld(user_count, friends_count, prob, rnd)
    elif network_type.lower().find("ring") >= 0:
        # A ring graph
        print "Creating a ring with " + str(user_count) + " users"
        new_graph = snap.GenCircle(snap.PUNGraph, user_count, friends_count)
    elif network_type.lower().find("power") >= 0:
        # Power Law network
        print "Creating a powerlaw network with " + str(user_count) + " users"
        new_graph = snap.GenRndPowerLaw(user_count, friends_count, conf_model)
    else:
        # A random graph
        print "Creating a random network with " + str(user_count) + " users"
        edge_count = user_count * friends_count
        new_graph = snap.GenRndGnm(snap.PUNGraph, user_count, edge_count)
    save_graph_in_db(new_graph)
Beispiel #2
0
def gen_data():
    graph = snap.GenRndGnm(snap.PNGraph, 300, 2400, True)
    snap.SaveEdgeList(graph, "../data/Erdos-Renyi.txt")
    graph = snap.GenPrefAttach(300, 8)
    snap.SaveEdgeList(graph, "../data/PrefAttach.txt")
    graph = snap.GenRndPowerLaw(300, 1.2)
    snap.SaveEdgeList(graph, "../data/power-law.txt")
Beispiel #3
0
    def scale_free_network(self):

        d = SfDialog(self.root)
        self.root.wait_window(d.top)

        nodes = d.nodes
        power = d.power

        self.graph = snap.GenRndPowerLaw(nodes, power)

        self.graph_name = "Scale-Free Network"
        self.add_characteristics(self.graph, self.graph_name)
Beispiel #4
0
		kmin = max(1, min(kmin, deg))
		kmax = max(kmax, deg)

	return 1. + np.log(graph.GetNodes()) / (np.log(kmax) - np.log(kmin))

def getBasicProps(graph):
	# Assuming unweighted undirected graph
	return {
		'num_nodes': graph.GetNodes(),
		'num_edges': graph.GetEdges(),
		'avg_deg': 2. * graph.GetEdges() / graph.GetNodes(),
		'gamma': getGamma(graph),
		'deg_centr': getDegCentr(graph),
		'num_tris': snap.GetTriads(graph, -1),
		'global_cc': snap.GetClustCf(graph, -1),
	}


Graph = snap.GenRndPowerLaw (1965206, 2.5)

prop = ['Scc','Wcc','InDeg','Clust']
for item in prop:
	createFile(item,item,item)
OutDeg(Graph)
plotDegCorr(Graph)

print getBasicProps(Graph)



Beispiel #5
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
TSKS11 Hands-on session 4
Degree correlations

Erik G. Larsson, 2018
"""

import snap
import sys
sys.path.append("..")
sys.path.append("/courses/TSKS11/ht2019/data_and_fcns/")
from degreecorr import plot_knn

G = snap.GenRndPowerLaw(100000, 2.5)
snap.SaveEdgeList(G, "n1.edgelist.txt")

G = snap.GenRndPowerLaw(100000, 2.5)
snap.SaveEdgeList(G, "n2.edgelist.txt")

G = snap.GenRndPowerLaw(100000, 2.5)
snap.SaveEdgeList(G, "n3.edgelist.txt")

G = snap.GenRndPowerLaw(100000, 2.5)
snap.SaveEdgeList(G, "n4.edgelist.txt")

G = snap.GenRndPowerLaw(100000, 2.5)
snap.SaveEdgeList(G, "n5.edgelist.txt")
Beispiel #6
0
    so_pr_ordered.append((
        so_pr_iter.GetKey(),
        so_pr_iter.GetDat(),
    ))
    so_pr_iter.Next()
print("Top 3 nodes by PageRank (nodeId,PageRank):")
for kv_pair in so_pr_ordered[0:3]:
    print(kv_pair)
#3
#Closeness, and degree centrality take single nodes as input
#Betweenness,Eigenvector and Page rank take a whole graph and return a hashtable
#top5% only
seed = snap.TRnd(1988)
exponent = 3
n = 400
g_rnd = snap.GenRndPowerLaw(n, exponent)


def all_node_centrality(g, centralityFunc):
    centralities = snap.TIntFlt64H()
    for node in g.Nodes():
        centralities[node.GetId()] = centralityFunc(g, node.GetId())
    return centralities


def iter_kv_pairs(hasht):
    it = hasht.BegI()
    while not it.IsEnd():
        yield it.GetKey(), it.GetDat()
        it.Next()
Beispiel #7
0
import snap

# this fails
G = snap.GenRndPowerLaw(1000, 1.374, True)
print "True works!"

# this works
G = snap.GenRndPowerLaw(1000, 1.374, False)
print "False works!"

Beispiel #8
0
import snap

G = snap.GenRndPowerLaw(1000, 13.74, True)

Beispiel #9
0
def genScaleFree(N=5000, gamma=2.5):
    return snap.GenRndPowerLaw(N, gamma)