Esempio n. 1
0
def synth_plots():
    num_nodes = 100
    samples = 5

    chunglu_M = []
    kron_M = []
    HRG_M = []
    pHRG_M = []
    G_M = []

    for i in range(0, samples):
        ##BA Graph
        G = nx.erdos_renyi_graph(num_nodes, .1)
        G_M.append(G)

        for i in range(0, samples):
            chunglu_M.append(nx.expected_degree_graph(G.degree().values()))

        HRG_M_s, degree = HRG.stochastic_hrg(G, samples)
        HRG_M = HRG_M + HRG_M_s
        pHRG_M_s = PHRG.probabilistic_hrg(G, samples)
        pHRG_M = pHRG_M + pHRG_M_s
        for i in range(0, samples):
            P = kronfit(G)
            k = math.log(num_nodes, 2)
            kron_M.append(
                product.kronecker_random_graph(int(math.floor(k)),
                                               P,
                                               directed=False))

    metrics.draw_network_value(G_M, chunglu_M, HRG_M, pHRG_M, kron_M)
Esempio n. 2
0
def KPGM(G, gname):
    target_nodes = G.number_of_nodes()
    k = int(math.log(target_nodes, 2))
    print 'k=', k

    # from: i:/data/saguinag/Phoenix/demo_graphs/karate.txt
    # karate: P = [[0.9999,0.661],[0.661,     0.01491]]
    # Interent: autonomous systems
    # P = [[0.9523, 0.585],[0.585,     0.05644]]
    P = kronfit(G)
    #print 'kronfit params (matrix):', P
    pred_graph = product.kronecker_random_graph(k, P)
    for u, v in pred_graph.selfloop_edges():
        pred_graph.remove_edge(u, v)

    return pred_graph
Esempio n. 3
0
def get_kpgm_graph_recurrence(graph,recurrence_nbr=1):
	"""
	Returns
	-------
	nth graph --<kpgm>--
	"""
	import product
	import math
	from cikm_experiments import kronfit
	for r in range(recurrence_nbr):
		k = int(math.log(graph.number_of_nodes(),2))
		P = kronfit(graph) #[[0.9999,0.661],[0.661,		 0.01491]]
		KPG = product.kronecker_random_graph(k, P, directed=False)

		for u,v in KPG.selfloop_edges():
			KPG.remove_edge(u, v)
		graph = KPG
		if KPG.is_directed(): print '!!!!!! is directed'
	print '\tKronecker -> run:', r, graph.number_of_nodes(),graph.number_of_edges()
	return KPG
Esempio n. 4
0
def grow_graphs_using_kpgm(graph,recurrence_nbr=1):
	"""
	Returns
	-------
	nth graph --<kpgm>--
	"""
	import product
	import math
	from pami import kronfit
	kp_graphs = []
	k = int(math.log(graph.number_of_nodes(),2))
	P = kronfit(graph) #[[0.9999,0.661],[0.661,		 0.01491]]
	print P, 'your are here'*2
	exit()
	for r in range(recurrence_nbr):
		KPG = product.kronecker_random_graph(k, P)
		for u,v in KPG.selfloop_edges():
			KPG.remove_edge(u, v)
		graph = KPG
		print '\tKronecker -> run:', r, graph.number_of_nodes(),graph.number_of_edges()
		kp_graphs.append(graph)
	return kp_graphs
Esempio n. 5
0
            pred_graph = grow(rule_list, g)[0]

        if model == 'chlu':  # ChungLu
            z = graphical_degree_sequence(target_nodes)
            pred_graph = nx.expected_degree_graph(z)

        if model == 'kpgm':  # KPGM -
            k = int(math.log(target_nodes, 2))

            # from: i:/data/saguinag/Phoenix/demo_graphs/karate.txt
            # karate: P = [[0.9999,0.661],[0.661,     0.01491]]
            # Interent: autonomous systems
            # P = [[0.9523, 0.585],[0.585,     0.05644]]
            P = kronfit(G)
            print P
            pred_graph = product.kronecker_random_graph(k, P)
            for u, v in pred_graph.selfloop_edges():
                pred_graph.remove_edge(u, v)

        ofname = "../Results/{}_{}_{}.gpickle".format(gname, model, i)
        nx.write_gpickle(pred_graph, ofname)
        print ofname
        G = pred_graph

print 'Done'
# write this graph to tmp.edglst to fit Kron params
# nx.write_edgelist(G,'tmp.edglst')

#   multiGraphs.append(hstar)
#   chungluGraphs.append(cl_grph)
#   # kronGraphs.append(KPG)
Esempio n. 6
0
import product
import networkx as nx
from PIL import Image, ImageDraw
import random

k = 6
P = [[1,1,0],[0,1,0],[0,1,.98]]
G = product.kronecker_random_graph(k,P)
for u,v in G.selfloop_edges():
  G.remove_edge(u,v)

pr = nx.pagerank(G)
maxPR = max(pr.values())

filename = 'kronecker'

size = 1000
rectWidth = 10

im = Image.new("RGB", (size, size), "white")
draw = ImageDraw.Draw(im)

for edge in G.edges():
  x = (1 - (pr[edge[0]] / maxPR)) * (size - rectWidth - rectWidth) + rectWidth
  y = (1 - (pr[edge[1]] / maxPR)) * (size - rectWidth - rectWidth) + rectWidth
  draw.rectangle([x, y, x + rectWidth, y + rectWidth], fill='black')
  draw.rectangle([y, x, y + rectWidth, x + rectWidth], fill='black')
im.save('./fig/' + filename + '.scale.png')

nodes = G.nodes()
x = sorted(pr.values(), key = lambda node: node, reverse = True)
Esempio n. 7
0
def gcd():
    num_nodes = 1000

    ba_G = nx.barabasi_albert_graph(num_nodes, 3)
    er_G = nx.erdos_renyi_graph(num_nodes, .1)
    ws_G = nx.watts_strogatz_graph(num_nodes, 8, .1)
    nws_G = nx.newman_watts_strogatz_graph(num_nodes, 8, .1)

    graphs = [ba_G, er_G, ws_G, nws_G]

    samples = 50

    for G in graphs:
        chunglu_M = []
        for i in range(0, samples):
            chunglu_M.append(nx.expected_degree_graph(G.degree()))

        HRG_M, degree = HRG.stochastic_hrg(G, samples)
        pHRG_M = PHRG.probabilistic_hrg(G, samples)
        kron_M = []
        rmat_M = []
        for i in range(0, samples):
            P = kronfit(G)
            k = math.log(num_nodes, 2)
            kron_M.append(
                product.kronecker_random_graph(int(math.floor(k)),
                                               P,
                                               directed=False))

        df_g = metrics.external_rage(G)
        gcd_chunglu = []
        gcd_phrg = []
        gcd_hrg = []
        gcd_kron = []
        for chunglu_M_s in chunglu_M:
            df_chunglu = metrics.external_rage(chunglu_M_s)
            rgfd = metrics.tijana_eval_rgfd(df_g, df_chunglu)
            gcm_g = metrics.tijana_eval_compute_gcm(df_g)
            gcm_h = metrics.tijana_eval_compute_gcm(df_chunglu)
            gcd_chunglu.append(metrics.tijana_eval_compute_gcd(gcm_g, gcm_h))
        for HRG_M_s in HRG_M:
            df_hrg = metrics.external_rage(HRG_M_s)
            rgfd = metrics.tijana_eval_rgfd(df_g, df_hrg)
            gcm_g = metrics.tijana_eval_compute_gcm(df_g)
            gcm_h = metrics.tijana_eval_compute_gcm(df_hrg)
            gcd_hrg.append(metrics.tijana_eval_compute_gcd(gcm_g, gcm_h))
        for pHRG_M_s in pHRG_M:
            df_phrg = metrics.external_rage(pHRG_M_s)
            rgfd = metrics.tijana_eval_rgfd(df_g, df_phrg)
            gcm_g = metrics.tijana_eval_compute_gcm(df_g)
            gcm_h = metrics.tijana_eval_compute_gcm(df_phrg)
            gcd_phrg.append(metrics.tijana_eval_compute_gcd(gcm_g, gcm_h))
        for kron_M_s in kron_M:
            df_kron = metrics.external_rage(kron_M_s)
            rgfd = metrics.tijana_eval_rgfd(df_g, df_kron)
            gcm_g = metrics.tijana_eval_compute_gcm(df_g)
            gcm_h = metrics.tijana_eval_compute_gcm(df_kron)
            gcd_kron.append(metrics.tijana_eval_compute_gcd(gcm_g, gcm_h))

        print gcd_chunglu
        print gcd_hrg
        print gcd_phrg
        print gcd_kron
        print
        print
Esempio n. 8
0
        if (len(c) is not 3): continue
        E.add_edge(int(c[1]), int(c[2]))
        if int(c[1]) > num_nodes or int(c[2]) > num_nodes:
            continue
    Gergm.append(E)
    print "G ergm iteration " + str(run) + " of 20"
    Gergmgl.append(gs.subgraphs_cnt(E, 50))

k = int(math.floor(math.log(num_nodes, 10)))
P = [[.9716, .658], [.5684, .1256]]  #karate
P = [[.8581, .5116], [.5063, .2071]]  #as20000102
#P = [[.7317,.5533],[.5354,.2857]] #dblp
#P = [[.9031,.5793],[.5051,.2136]] #ca-grqc
#P = [[.9124,.5884],[.5029,.2165]] #enron
P = [[.8884, .5908], [.5628, .2736]]  #brightkite
Gkron = product.kronecker_random_graph(k, P).to_undirected()

print("GKron finished")

sum = .9716 + .5382 + .5684 + .1256  #karate
#sum = .8581+.5116+.5063+.2071 #as20000102
#sum = .7317+.5533+.5354+.2857 # dblp
#sum = .9031+.5793+.5051+.2136 #ca-grqc
#sum = .9124+.5884+.5029+.2165 #enron
sum = .8884 + .5908 + .5628 + .2736  #brightkite
GRmatSNAP = snap.GenRMat(num_nodes, num_edges, P[0][0] / sum, P[0][1] / sum,
                         P[1][0] / sum)
GRmat = nx.Graph()
for EI in GRmatSNAP.Edges():
    GRmat.add_edge(EI.GetSrcNId(), EI.GetDstNId())