Пример #1
0
def show_clusters_over_time(task_output_path=None,
                            query_laps=[0, 1, 2, 5, 10, None],
                            nrows=2):

    ncols = int(np.ceil(len(query_laps) // float(nrows)))
    fig_handle, ax_handle_list = pylab.subplots(figsize=(FIG_SIZE[0] * ncols,
                                                         FIG_SIZE[1] * nrows),
                                                nrows=nrows,
                                                ncols=ncols,
                                                sharex=True,
                                                sharey=True)
    for plot_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_handle = ax_handle_list.flatten()[plot_id]
        bnpy.viz.PlotComps.plotCompsFromHModel(
            cur_model,
            Data=dataset,
        )  #ax_handle=cur_ax_handle)
        cur_ax_handle.set_xticks([-2, -1, 0, 1, 2])
        cur_ax_handle.set_yticks([-2, -1, 0, 1, 2])
        cur_ax_handle.set_xlabel("lap: %d" % lap_val)
    pylab.tight_layout()
    pylab.savefig("results/covMat1.png")
    pylab.waitforbuttonpress()
    pylab.show()
def show_clusters_over_time(task_output_path=None,
                            query_laps=[0, 1, 2, 5, 10, None],
                            nrows=2):
    ''' Read model snapshots from provided folder and make visualizations

    Post Condition
    --------------
    New matplotlib plot with some nice pictures.
    '''
    ncols = int(np.ceil(len(query_laps) // float(nrows)))
    fig_handle, ax_handle_list = pylab.subplots(figsize=(FIG_SIZE[0] * ncols,
                                                         FIG_SIZE[1] * nrows),
                                                nrows=nrows,
                                                ncols=ncols,
                                                sharex=True,
                                                sharey=True)
    for plot_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_handle = ax_handle_list.flatten()[plot_id]
        bnpy.viz.PlotComps.plotCompsFromHModel(cur_model,
                                               Data=dataset,
                                               ax_handle=cur_ax_handle)
        cur_ax_handle.set_xticks([-2, -1, 0, 1, 2])
        cur_ax_handle.set_yticks([-2, -1, 0, 1, 2])
        cur_ax_handle.set_xlabel("lap: %d" % lap_val)
    pylab.tight_layout()
Пример #3
0
def show_top_words_over_time(task_output_path=None,
                             vocabList=None,
                             query_laps=[0, 1, 2, 5, None],
                             ncols=10):
    '''
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows,
        ncols=ncols,
        sharex=True,
        sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.PrintTopics.plotCompsFromHModel(cur_model,
                                                 vocabList=vocabList,
                                                 fontsize=9,
                                                 Ktop=7,
                                                 ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.subplots_adjust(wspace=0.04,
                          hspace=0.1,
                          left=0.01,
                          right=0.99,
                          top=0.99,
                          bottom=0.1)
    pylab.tight_layout()
Пример #4
0
def show_bars_over_time(task_output_path=None,
                        query_laps=[0, 1, 2, 5, None],
                        ncols=10):
    ''' Show square-image visualization of estimated topics over time.

    Post Condition
    --------------
    New matplotlib figure with visualization (one row per lap).
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows,
        ncols=ncols,
        sharex=True,
        sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        cur_topics_KV = cur_model.obsModel.getTopics()
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.BarsViz.show_square_images(cur_topics_KV,
                                            vmin=0.0,
                                            vmax=0.06,
                                            ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.tight_layout()
Пример #5
0
def show_clusters_over_time(task_output_path=None,
                            query_laps=[0, 1, 2, 10, 20, None],
                            nrows=2):
    '''
    '''
    ncols = int(np.ceil(len(query_laps) // float(nrows)))
    fig_handle, ax_handle_list = plt.subplots(figsize=(FIG_SIZE[0] * ncols,
                                                       FIG_SIZE[1] * nrows),
                                              nrows=nrows,
                                              ncols=ncols,
                                              sharex=True,
                                              sharey=True)
    for plot_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        cur_ax_handle = ax_handle_list.flatten()[plot_id]
        bnpy.viz.PlotComps.plotCompsFromHModel(cur_model,
                                               dataset=dataset,
                                               ax_handle=cur_ax_handle)
        cur_ax_handle.set_title("lap: %d" % lap_val)
        cur_ax_handle.set_xlabel(dataset.column_names[0])
        cur_ax_handle.set_ylabel(dataset.column_names[1])
        cur_ax_handle.set_xlim(data_ax_h.get_xlim())
        cur_ax_handle.set_ylim(data_ax_h.get_ylim())
    plt.tight_layout()
    plt.show()
Пример #6
0
def show_bars_over_time(task_output_path=None,
                        query_laps=[0, 1, 2, 5, None],
                        ncols=10):
    '''
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows,
        ncols=ncols,
        sharex=True,
        sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        cur_topics_KV = cur_model.obsModel.Post.lam1 / (
            trained_model.obsModel.Post.lam1 +
            trained_model.obsModel.Post.lam0)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.BarsViz.show_square_images(cur_topics_KV,
                                            vmin=0.0,
                                            vmax=0.06,
                                            ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.tight_layout()
Пример #7
0
def show_topic_proportions_over_time(task_output_path=None,
                                     query_laps=[0, 1, 2, 5, None],
                                     ncols=10):
    '''
    '''

    fig = plt.figure()
    fig_handle, ax_handles_RC = plt.subplots(figsize=(MED_FIG_SIZE[0] * ncols,
                                                      MED_FIG_SIZE[1]),
                                             nrows=1,
                                             ncols=len(query_laps),
                                             sharey=True)
    for col_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax = ax_handles_RC[col_id]
        cur_proportions = cur_model.allocModel.E_beta()
        cur_ax.set_title('Lap = %d' % lap_val)
        cur_ax.plot(cur_proportions, marker='o')
        cur_ax.set_ylabel('Proportions')
        cur_ax.set_xlabel('Topic index')
    plt.subplots_adjust(wspace=0.04,
                        hspace=0.1,
                        left=0.01,
                        right=0.99,
                        top=0.99,
                        bottom=0.1)
    plt.tight_layout()
    savefigpath = output_path + 'topic_proportions.png'
    print("Will save figure to %s" % savefigpath)
    plt.savefig(savefigpath)
    return
Пример #8
0
def show_top_words_over_time(task_output_path=None,
                             vocabList=None,
                             query_laps=[0, 1, 2, 5, None],
                             ncols=10):
    '''
    '''

    fig = plt.figure()
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = plt.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows,
        ncols=ncols,
        sharex=True,
        sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.PrintTopics.plotCompsFromHModel(cur_model,
                                                 vocabList=vocabList,
                                                 fontsize=9,
                                                 Ktop=7,
                                                 ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)

        cur_proportions = cur_model.allocModel.E_beta()
        for i in range(np.amin([len(cur_ax_list), len(cur_proportions)])):
            ax = cur_ax_list[i]
            ax.set_title('Prop. = %.2f' % cur_proportions[i], fontsize=10)
    plt.subplots_adjust(wspace=0.04,
                        hspace=0.1,
                        left=0.01,
                        right=0.99,
                        top=0.99,
                        bottom=0.1)
    plt.tight_layout()
    savefigpath = output_path + 'top_words.png'
    print("Will save figure to %s" % savefigpath)
    plt.savefig(savefigpath)
    return