plot.py 文件源码

python
阅读 83 收藏 0 点赞 0 评论 0

项目:pymake 作者: dtrckd 项目源码 文件源码
def plot_ibp(model, target_dir=None, block=False, columns=[0], separate=False, K=4):

    G = nx.from_numpy_matrix(model.Y(), nx.DiGraph())
    F = model.leftordered()
    W = model._W

    # Plot Adjacency Matrix
    draw_adjmat(model._Y)
    # Plot Log likelihood
    plot_csv(target_dir=target_dir, columns=columns, separate=separate)
    #W[np.where(np.logical_and(W>-1.6, W<1.6))] = 0
    #W[W <= -1.6]= -1
    #W[W >= 1.6] = 1

    # KMeans test
    clusters = kmeans(F, K=K)
    nodelist_kmeans = [k[0] for k in sorted(zip(range(len(clusters)), clusters), key=lambda k: k[1])]
    adj_mat_kmeans = nx.adjacency_matrix(G, nodelist=nodelist_kmeans).A
    draw_adjmat(adj_mat_kmeans, title='KMeans on feature matrix')
    # Adjacency matrix generation
    draw_adjmat(model.generate(nodelist_kmeans), title='Generated Y from ILFRM')

    # training Rescal
    R = rescal(model._Y, K)
    R = R[nodelist_kmeans, :][:, nodelist_kmeans]
    draw_adjmat(R, 'Rescal generated')

    # Networks Plots
    f = plt.figure()

    ax = f.add_subplot(121)
    title = 'Features matrix, K = %d' % model._K
    ax.set_title(title)
    ColorMap(F, pixelspervalue=5, title=title, ax=ax)

    ax = f.add_subplot(122)
    ax.set_title('W')
    img = ax.imshow(W, interpolation='None')
    plt.colorbar(img)

    f = plt.figure()
    ax = f.add_subplot(221)
    ax.set_title('Spectral')
    nx.draw_spectral(G, axes=ax)
    ax = f.add_subplot(222)
    ax.set_title('Spring')
    nx.draw(G, axes=ax)
    ax = f.add_subplot(223)
    ax.set_title('Random')
    nx.draw_random(G, axes=ax)
    ax = f.add_subplot(224)
    ax.set_title('graphviz')
    try:
        nx.draw_graphviz(G, axes=ax)
    except:
        pass

    display(block=block)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号