Exemple #1
0
def test(n, iters):
    A, f, a = random_matrix(n)
    labels = [str(i) for i in range(1, n + 1)]
    G = spec.DirectedGraph(A, (a, f), labels=labels)
    G.coloring()
    print(G.colors)
    stats.community_dist_hist(G.colors,
                              title=G.n,
                              logscale=False,
                              show=True,
                              save=False)

    for k in range(iters):
        base = random.sample(G.indexer.keys(), int(np.floor(G.n * .9)))
        print('\nSpecializing on ', base)
        G.specialize(base, recolor=True)
        print(G.colors)
        stats.community_dist_hist(G.colors,
                                  title='$S_{}$'.format(k + 1) + str(base) +
                                  'n=' + str(G.n),
                                  logscale=False,
                                  show=True,
                                  save=False)
                  [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 1],
                  [0, 0, 0, 1, 0, 1, 0]])
    labels = ["a", "b", "c", 'd', 'e', 'f', 'g']
    # G = s.DirectedGraph(A, labels)

    # G.specialize_graph(["a",'e'], verbose=True)
    B = np.array([[0, 0, 1], [1, 0, 0], [1, 1, 0]])
    sig = lambda x: np.tanh(x)
    f = np.array(
        [[lambda x: 0 * x, lambda x: 0 * x, lambda x: -(1 / 2) * sig(x)],
         [lambda x: 0.5 * sig(x), lambda x: 0 * x, lambda x: 0 * x],
         [lambda x: 0.5 * sig(x), lambda x: 0.5 * sig(x), lambda x: 0 * x]])
    a = np.array([3 / 10, 3 / 10, 3 / 10])
    c = np.array([1 / 4, 0.025, 0])
    labels = ['x1', 'x2', 'x3']

    G = s.DirectedGraph(B, (a, f, c), labels=labels)
    G.iterate(80, np.random.random(G.n), graph=True)

    G.specialize_graph(['x2', 'x3'], verbose=False)
    G.iterate(80, np.random.random(G.n), graph=True)

    G.specialize_graph(['x1.1', 'x1.2', 'x2'], verbose=False)
    G.iterate(80, np.random.random(G.n), graph=True)

    # N = nx.DiGraph(G.A.T)
    # nx.draw_networkx_labels(N, pos=nx.spring_layout(N), labels=G.labeler)
    # nx.draw(N, pos=nx.spring_layout(N))
    # plt.draw()
    # plt.show()
Exemple #3
0
        return anp.sin(x)

    def f2(x):
        return 0.9 * x + 7 / 5

    def f3(x):
        return 0.9 * x + 0.5

    f = np.array([[sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, sig],
                  [sig, sig, sig, sig, sig, sig, sig, zero]])

    a = np.array([zero, f1, f1, f1, f1, f1, f1, f1])
    labels = ['1', '2', '3', '4', '5', '6', '7', '8']

    G = s.DirectedGraph(A, (a, f), labels=labels)
    # print(G.coloring())
    # G.network_vis()#use_eqp=True)
    # G.iterate(20,np.random.random(8),graph=True)
    base = ['1', '8']  #,'5','6','7']
    G.specialize(base)
    # with open('half_spec.txt', 'w') as out_file:
    #     out_file.write(str(G.A))
    G.iterate(20, np.random.random(38), graph=True)
    # G.network_vis(use_eqp=True)
    # print(G.n)