コード例 #1
0
def generate_graph(NNodes, NEdges, Model, Rnd):
  
  Graph = None
  if Model == 'rand_ungraph':
    # GnRndGnm returns error, so manually generate
    Graph = snap.GenRndGnm_PUNGraph(NNodes, NEdges, 0)

  elif Model == 'rand_ngraph':
    Graph = snap.GenRndGnm_PNGraph(NNodes, NEdges, 1)
      
  elif Model == 'rand_neagraph':
    Graph = snap.GenRndGnm_PNEANet(NNodes, NEdges, 1)

  elif Model == 'syn_neagraph':
    Graph = snap.GenSyntheticGraph_PNEANet(NNodes, NEdges/NNodes,
                                             SYNTHETIC_DELTA)

  elif Model == 'syn_ngraph':
    Graph = snap.GenSyntheticGraph_PNGraph(NNodes, NEdges/NNodes,
                                             SYNTHETIC_DELTA)

  elif Model == 'rmat':
    Graph = snap.GenRMat(NNodes, NEdges, 0.40, 0.25, 0.2, Rnd)

  elif Model == 'sw':
    Graph = snap.GenSmallWorld(NNodes, NNodes/NEdges, 0.1)
  
  elif Model == 'pref':
    Graph = snap.GenPrefAttach(NNodes, NNodes/NEdges)

  else:
    print "Unknown model: %s" % Model
    sys.exit(1)

  return Graph
コード例 #2
0
ファイル: benchmark.py プロジェクト: vikeshkhanna/snap-python
def generate_graph(NNodes, NEdges, Model, Type, Rnd):

    if Model == 'rand_ungraph':
        # GnRndGnm returns error, so manually generate
        Graph = snap.GenRndGnm_PUNGraph(NNodes, NEdges, 0)

    elif Model == 'rand_ngraph':
        Graph = snap.GenRndGnm_PNGraph(NNodes, NEdges, 1)

    elif Model == 'rand_neanet':
        Graph = snap.GenRndGnm(NNodes, NEdges, 1)

    elif Model == 'syn_neanet':
        Graph = snap.GenSyntheticGraph(NNodes, NEdges / NNodes,
                                       SYNTHETIC_DELTA)

    elif Model == 'syn_ngraph':
        Graph = snap.GenSyntheticGraph_PNGraph(NNodes, NEdges / NNodes,
                                               SYNTHETIC_DELTA)

    elif Model == 'rmat':
        Graph = snap.GenRMat(NNodes, NEdges, 0.40, 0.25, 0.2, Rnd)

    elif Model == 'sw':
        Graph = snap.GenSmallWorld(NNodes, NNodes / NEdges, 0.1)

    elif Model == 'pref':
        Graph = snap.GenPrefAttach(NNodes, NNodes / NEdges)

    return Graph
コード例 #3
0
ファイル: rmat.py プロジェクト: jasonlyik/ee451-project
def main():
	if len(sys.argv) < 3:
		print("enter n and nnz as arguments")
		return

	n = int(sys.argv[1])
	e = int(sys.argv[2])

	now = time.time()
	Rnd = snap.TRnd()
	Rnd.PutSeed(int(now))

	for i in range(5):
		Graph = snap.GenRMat(n, e, .25, .25, .25, Rnd) 

		filestr = str(n) + "_" + str(e) + "_" + str(i)

		f = open(filestr, "w+")

		for EI in Graph.Edges():
			src = '{:10}'.format("%d" % (EI.GetSrcNId()))
			dst = '{:10}'.format("%d" % (EI.GetDstNId()))
			f.write(src + " " + dst + "\n")

		f.flush()
コード例 #4
0
def main():
    if len(sys.argv) < 4:
        print("enter a b c as arguments")
        return

    n = 32768
    e = 262144

    a = float(sys.argv[1])
    b = float(sys.argv[2])
    c = float(sys.argv[3])

    now = time.time()
    Rnd = snap.TRnd()
    Rnd.PutSeed(int(now))

    for i in range(5):
        Graph = snap.GenRMat(n, e, a / 100, b / 100, c / 100, Rnd)

        filestr = str(int(a)) + "_" + str(int(b)) + "_" + str(
            int(c)) + "_" + str(i)

        f = open(filestr, "w+")

        for EI in Graph.Edges():
            src = '{:10}'.format("%d" % (EI.GetSrcNId()))
            dst = '{:10}'.format("%d" % (EI.GetDstNId()))
            f.write(src + " " + dst + "\n")

        f.flush()
コード例 #5
0
ファイル: slashburn.py プロジェクト: dongkwan-kim/gm-and-sna
def analysis_wwr():

    try:
        import snap
    except ModuleNotFoundError:
        pass

    stanford_data = load_stanford_dataset()
    node_set, node_id_to_idx, idx_to_node_id = _get_mapping(stanford_data)
    to_followings, to_followers = _get_followings_and_followers(
        stanford_data, node_id_to_idx, len(node_set))

    num_nodes = len(node_set)
    num_edges = 0
    for u, vs in stanford_data.items():
        num_edges += len(vs)

    degree_skew_list, wwr_list = [], []
    a, b = 0.6, 0.1
    c_list = [0.05, 0.1, 0.15, 0.2, 0.25]
    for c in tqdm_s(c_list):

        g = snap.GenRMat(num_nodes, num_edges, a, b, c, snap.TRnd())

        g_adjdict = {ni.GetId(): [] for ni in g.Nodes()}
        for ei in g.Edges():
            g_adjdict[ei.GetSrcNId()].append(ei.GetDstNId())

        g_degree = np.asarray(
            [ni.GetOutDeg() + ni.GetInDeg() for ni in g.Nodes()])
        degree_skew = skew(g_degree)
        degree_skew_list.append(degree_skew)

        orderings, wwr = slashburn(g_adjdict, k=1000)
        wwr_list.append(wwr)

        print("\nc: {}, ds: {}, wwr: {}".format(c, degree_skew, wwr))

    idx_to_degree = _get_idx_to_degree(to_followings, to_followers, num_nodes)
    stanford_degree_skew = skew(np.asarray([d
                                            for d in idx_to_degree.values()]))
    stanford_orderings, standford_wwr = slashburn(deepcopy(stanford_data),
                                                  k=1000)

    print("\n\n--- Result ---")
    print("\t".join(
        ["Graph (c or name)", "degree skewness", "Wing width ratio"]))
    for c, degree_skew, wwr in zip(c_list, degree_skew_list, wwr_list):
        print("\t".join(
            ["c-{}".format(c),
             str(round(degree_skew, 5)),
             str(round(wwr, 5))]))
    print("\t".join([
        "web-Stanford",
        str(round(stanford_degree_skew, 5)),
        str(round(standford_wwr, 5))
    ]))
コード例 #6
0
def gen_rm(args):
    """Generate a RM Graph"""

    for i in range(args.num_graphs):

        a = np.random.uniform(0, 0.3)
        b = np.random.uniform(0, 0.1)
        c = np.random.uniform(0, 0.1)
        num_edges = int(
            np.random.uniform((args.num_vertices), (args.num_vertices * 2)))
        Graph = snap.GenRMat(args.num_vertices, num_edges, a, b, c)
        snap.SaveEdgeList(Graph, f'{args.data_loc}/RM/RM_{i}.edges')

        print(f"RM Graph {i} Generated and Saved")
コード例 #7
0
def generate_graph(NNodes, NEdges, Model, Type, Rnd):

    if Model == 'rand_ungraph':
        # GnRndGnm returns error, so manually generate
        #Graph = snap.GenRndGnm_PUNGraph(NNodes, NEdges, 0)
        Graph = snap.GenRndGnm(snap.PUNGraph, NNodes, NEdges, 0)

    elif Model == 'rand_ngraph':
        #Graph = snap.GenRndGnm_PNGraph(NNodes, NEdges, 1)
        Graph = snap.GenRndGnm(snap.PNGraph, NNodes, NEdges, 1)

    elif Model == 'rand_neanet':
        print "1", NNodes, NEdges
        #Graph = snap.GenRndGnm_PNEANet(NNodes, NEdges, 1)
        Graph = snap.GenRndGnm(snap.PNEANet, NNodes, NEdges, 1)
        print "2"
        print "3", Graph.GetNodes(), Graph.GetEdges()

    elif Model == 'syn_neanet':
        Graph = snap.GenSyntheticGraph(NNodes, NEdges / NNodes,
                                       SYNTHETIC_DELTA)

    elif Model == 'syn_ngraph':
        Graph = snap.GenSyntheticGraph_PNGraph(NNodes, NEdges / NNodes,
                                               SYNTHETIC_DELTA)

    elif Model == 'rmat':
        Graph = snap.GenRMat(NNodes, NEdges, 0.40, 0.25, 0.2, Rnd)

    elif Model == 'sw':
        Graph = snap.GenSmallWorld(NNodes, NNodes / NEdges, 0.1)

    elif Model == 'pref':
        Graph = snap.GenPrefAttach(NNodes, NNodes / NEdges)

    return Graph
コード例 #8
0
#Sorry for the messiness. I'll eventually organize this more, just wanted to throw something up here.
#currently this goes as far as calculating the probability that a node will copy any neighbor.

#import needed packages
import snap
import numpy

#generate RMAT graph using snap package
Rnd = snap.TRnd()
Graph = snap.GenRMat(900, 9000, .6, .1, .15, Rnd)


#define class that puts a node (i.e. speaker) with a value (i.e. linguistic variable)
class Speaker:
    def __init__(self, node, indeg, outdeg, value):
        self.node = node
        self.indeg = indeg
        self.outdeg = outdeg
        self.value = value


#create a list of "Speaker" objects for each node in the RMAT graph
nodes_ = []
for node in Graph.Nodes():
    nodes_.append(
        Speaker(node.GetId(), node.GetInDeg(), node.GetOutDeg(),
                numpy.random.randint(8)))

#create list of all nodes that can be influenced (i.e. have an out degree?)
#I hope I'm interpreting this bit right from the article
Copyers = []
コード例 #9
0
#Generates a recursive matrix
#GenRMat(nodes, edges, a, b, c, Rnd)
#a,b,c = probabilities that quadrant will be chosen

import snap

Rnd = snap.TRnd()
Graph = snap.GenRMat(900, 9000, .5, .1, .1, Rnd)
for EI in Graph.Edges():
    print "edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())
コード例 #10
0
# Real-world R-MAT parameters
a = 0.59
b = c = 0.19

# Transition coeff - start at Real-world R-MAT
coeff = 0.0
unif = 0.25

while True:
    print("==> Generating R-MAT, transition coefficient: {}".format(coeff))

    print("==> a: {}, b: {}, c: {}".format(a + coeff * (unif - a),
                                           b + coeff * (unif - b),
                                           c + coeff * (unif - c)))
    G = snap.GenRMat(n, m, a + coeff * (unif - a), b + coeff * (unif - b),
                     c + coeff * (unif - c))

    # Write to file
    file_name = "rmat_gradient_n{}_e{}_coeff{}.txt".format(n, m, coeff)
    f = open(file_name, "w")
    for e in G.Edges():
        (u, v) = (e.GetSrcNId(), e.GetDstNId())
        f.write("{}\t{}\n".format(u, v))
    f.close()

    # Next coeff
    if coeff == 1:
        break
    coeff += step
    if coeff > 1:
        coeff = 1
コード例 #11
0
ファイル: karate_chop.py プロジェクト: abitofalchemy/hrg_nets
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())

print("GRMAT finished")
GRmatgl = gs.subgraphs_cnt(GRmat, 100)

n_distribution = {}
Gstar = []
Dstar = []
Gstargl = []
for run in range(0, 20):
    nG, nD = stochastic_growth.grow(prod_rules, num_nodes / 10,
                                    0)  #num_nodes/50)
    Gstar.append(nG)