def diameter_vs_prob(k, q, probs):
    """diameter and clustering coefficient vs rewiring prob with k trials"""
    xdata = []
    ydata = []
    #    zdata = []
    #    prob = 0.0005
    #    while prob < 0.5:
    for prob in probs:
        print(prob)
        xdata += [prob]
        diameters = []
        #        coeffs = []
        for i in range(k):
            graph = make_ring_graph(20, 20, prob, q)
            diameters += [diameter(graph)]
#            coeffs += [clustering_coefficient(graph)]
        ydata += [sum(diameters) / k
                  ]  #divide by 19 as this diameter of circle lattice


#        zdata += [sum(coeffs) /  k / 0.7] #divide by 0.7 as this is clustering coefficient of circle lattice
#        prob = 1.2*prob#*1.1
    return xdata, ydata  #, zdata
Ejemplo n.º 2
0
            margin=dict(b=20, l=5, r=5, t=40),
            annotations=[
                dict(
                    text=
                    "Python code: <a href='https://plot.ly/ipython-notebooks/network-graphs/'> https://plot.ly/ipython-notebooks/network-graphs/</a>",
                    showarrow=False,
                    xref="paper",
                    yref="paper",
                    x=0.005,
                    y=-0.002)
            ],
            xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
            yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))

    plot(fig)


if __name__ == "__main__":
    m, k = 12, 6
    p, q = 0.495, 0.005

    # p + q = 0.5
    # investigate diameter
    graph = make_ring_graph(m, k, p, q)
    brilliance = br(graph)
    # {0:{v1, v2, ..}, 1:{v, ...}, ...}

    #    graph = {0:[2, 5, 9, 11, 13],1:[7, 9, 12, 13],2:[0,6,7,11],3:[4,8,10,12],4:[3,9],5:[0,7,12],6:[2],7:[1,2,5],8:[3],9:[0,1,4],10:[3],11:[0,2],12:[1,3,5],13:[0,1]}

    draw_network(graph)
###################################################################
'''RANDOM RING GRAPHS'''
m, k = 20, 20
rrg = [(m, k, 0.5 - x * 0.05) for x in range(11)]  #(m, k, p, q)
xs, ys = [], []
exps = []
ranges = []
for b in rrg:
    d_size = 600
    d = {}
    for i in range(d_size):
        d[i] = 0
    a = 20
    for i in range(a):
        g = make_ring_graph(b[0], b[1], b[2], 0.5 - b[2])
        dg = in_degree_distribution(g)
        for i in range(d_size):
            if i in dg.keys():
                d[i] += float(dg[i]) / a
    total = 0
    for i in range(d_size):
        if d[i] == 0:
            del d[i]
        else:
            total += float(i * d[i]) / (b[0] * b[1])
    exps.append(total)
    x, y = d.keys(), d.values()
    x = [float(x_i) * b[2]**0 for x_i in x]
    y = [float(y_i) / (b[0] * b[1]) for y_i in y]
    ranges.append(find_range(x, y))