def create_graph_kronecker(objects,
                           properties):  #uses alpha-beta method to build kron
    initEdges = properties['init_edges']
    alpha = properties['alpha']
    beta = properties['beta']
    k = properties['kron_interations']
    tryAgain = True
    init = InitMatrix(properties['kron_seed_nodes'])
    init.make()
    init.addSelfEdges()
    for i in range(len(initEdges)):
        pos = initEdges[i]
        index1 = pos[0]
        index2 = pos[1]
        if (index1 > properties['kron_seed_nodes']
                or index2 > properties['kron_seed_nodes']):
            raise IOError("init_edges are out of range of seed matrix size")
        else:
            init.addEdge(index1, index2)

    if (properties['kron_seed_self_loops_stochastic'] == False):
        init.makeStochasticAB(alpha, beta, False)
    else:
        init.makeStochasticAB(alpha, beta)

    while (
            tryAgain == True
    ):  #loop to make sure we are connected, should there be a limit to this?
        final = KroneckerGenerator.generateStochasticKron(init, k, True)
        is_conn = nx.is_connected(final)
        if (is_conn == False):
            print "Graph was not connected, trying again..."
            tryAgain = True
        else:
            tryAgain = False

    stats = create_graph_stats(final)
    conn = nx.Graph()
    for (i, j) in final.edges():
        inode = objects[i]
        jnode = objects[j]
        conn.add_edge(inode, jnode)
    return conn, stats
def create_graph_kronecker(objects, properties):  # uses alpha-beta method to build kron
    initEdges = properties["init_edges"]
    alpha = properties["alpha"]
    beta = properties["beta"]
    k = properties["kron_interations"]
    tryAgain = True
    init = InitMatrix(properties["kron_seed_nodes"])
    init.make()
    init.addSelfEdges()
    for i in range(len(initEdges)):
        pos = initEdges[i]
        index1 = pos[0]
        index2 = pos[1]
        if index1 > properties["kron_seed_nodes"] or index2 > properties["kron_seed_nodes"]:
            raise IOError("init_edges are out of range of seed matrix size")
        else:
            init.addEdge(index1, index2)

    if properties["kron_seed_self_loops_stochastic"] == False:
        init.makeStochasticAB(alpha, beta, False)
    else:
        init.makeStochasticAB(alpha, beta)

    while tryAgain == True:  # loop to make sure we are connected, should there be a limit to this?
        final = KroneckerGenerator.generateStochasticKron(init, k, True)
        is_conn = nx.is_connected(final)
        if is_conn == False:
            print "Graph was not connected, trying again..."
            tryAgain = True
        else:
            tryAgain = False

    stats = create_graph_stats(final)
    conn = nx.Graph()
    for (i, j) in final.edges():
        inode = objects[i]
        jnode = objects[j]
        conn.add_edge(inode, jnode)
    return conn, stats
    stats = {'cc':cc, 'bc':bc, 'deg':deg, \
             'num_cc':num_cc, 'dens':dens}#, 'largest_cc':largest_cc}

    return stats  #conn,


#above are methods to make input for histogram

nodes = 2

init = InitMatrix(nodes)
init.make()

#Alpha Beta Method of Testing
init.addEdge(0, 1)
init.addSelfEdges()
init.makeStochasticAB(0.4, 0.2)

#Custom Method of Testing
#p = 15
#c = 6
#probArr = np.array([1, c*p, p/c, 0, 0, c*p, 1, p/c, 0, 0, p/c, p/c, 1, p/c, p/c, 0, 0, p/c, 1, c*p, 0, 0, p/c, c*p, 1])
#init.makeStochasticCustom(probArr)

#Networkx Graph Gen as Seed, Alpha Beta after Testing
#G = nx.watts_strogatz_graph(5, 2, 0.1)
#nx.draw(G)
#plt.show() # if you want to visualize your seed graph first
#init = InitMatrix(nodes)
#init = init.makeStochasticABFromNetworkxGraph(G, 0.75, 0.5)
Пример #4
0
    dens = nx.density(x)

    stats = {'cc':cc, 'bc':bc, 'deg':deg, \
             'num_cc':num_cc, 'dens':dens}#, 'largest_cc':largest_cc}

    return stats #conn,

#above are methods to make input for histogram

nodes = 2

init = InitMatrix(nodes)
init.make()

#Alpha Beta Method of Testing
init.addEdge(0, 1)
init.addSelfEdges()
init.makeStochasticAB(0.4, 0.2)

#Custom Method of Testing
#p = 15
#c = 6
#probArr = np.array([1, c*p, p/c, 0, 0, c*p, 1, p/c, 0, 0, p/c, p/c, 1, p/c, p/c, 0, 0, p/c, 1, c*p, 0, 0, p/c, c*p, 1])
#init.makeStochasticCustom(probArr) 

#Networkx Graph Gen as Seed, Alpha Beta after Testing
#G = nx.watts_strogatz_graph(5, 2, 0.1)
#nx.draw(G)
#plt.show() # if you want to visualize your seed graph first
#init = InitMatrix(nodes)
#init = init.makeStochasticABFromNetworkxGraph(G, 0.75, 0.5)