Example #1
0
def usual_graph():
    colors = ['r', 'b', 'g', 'm', 'c', 'y', 'k', '#ffa000', '#7366bd']
    markers = ['o', '^', 'd', (5,1)]
    #labels = ["Arora", "Random-rare", "Random-uniform", "Clust-words", "SVD", "Clust-tfIdf"]
    labels = ["","Arora","Random-rare", "Random-uniform", "Clust-words", "SVD","Clust-tfidf", "Mixed-clust", "Mixed-Arora","Arora uniform"]
    result_dir = 'test/024_04_16_random_uniform70_/'
    cfg = config.load(result_dir+'plsa_config.txt')
    cfg['result_dir'] = result_dir
    results = []
    general_info = load_obj(cfg['result_dir']+"general_info")
    for a in general_info:
        results.append(a[0])
    for i, fun_name in enumerate(cfg['measure'].split(',')):
        if i == 1:
            plt.figure()
            val = np.array([r[:, i] for r in results])
            fun = getattr(measure, fun_name + '_name')
            plt.ylabel(fun(), fontsize=18)
            plt.title("F", fontsize=18)
            plt.xlabel(u"Номер итерации", fontsize=18)
            #plt.grid(True)
            index_exp_series = 0
            for it, expirement_runs in enumerate([int(x) for x in cfg['runs'].split(",")]):
                series_stats = calculate_stats(val[index_exp_series:index_exp_series+expirement_runs, 0:], cfg['begin_graph_iter'])
                plt.plot(range(cfg['begin_graph_iter'], cfg['begin_graph_iter'] + len(series_stats[0])), series_stats[0], linewidth=2, c=colors[it % len(colors)], label = labels[int(cfg['prepare_method'].split(',')[it])])
                plt.fill_between(range(cfg['begin_graph_iter'], cfg['begin_graph_iter'] + len(series_stats[0])), series_stats[2], series_stats[3], alpha = 0.1, facecolor=colors[it % len(colors)])
                index_exp_series += expirement_runs

            x1,x2,y1,y2 = plt.axis()
            plt.axis((x1,x2,1900,2100))
            plt.legend()
            plt.draw()

            filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'_addit.pdf')
            plt.savefig(filename, format='pdf')
            fun = getattr(measure, fun_name + '_name_eng')
            plt.ylabel(fun(), fontsize=18)
            plt.title("F", fontsize=18)
            plt.xlabel("Iteration", fontsize=18)
            x1,x2,y1,y2 = plt.axis()
            plt.axis((x1,x2,1900,2100))
            plt.legend()
            plt.draw()

            filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'_eng_addit.pdf')
            plt.savefig(filename, format='pdf')
Example #2
0
def plot_results(results, finals, cfg):
    print("Plot graphs")
    colors = ['r', 'b', 'g', 'm', 'c', 'y', 'k']
    markers = ['o', '^', 'd', (5,1)]
    labels = ["Arora", "Random-rare", "Random-uniform", "Clust-words", "SVD", "Clust-tfIdf"]

    with open(os.path.join(cfg['result_dir'], cfg['experiment']+'_finals.txt'),"w") as f:
        for i, fun_name in enumerate(cfg['finals'].split(',')):
            fun = getattr(measure, fun_name)
            name, val = fun(np.array([[1]]), np.array([[1]]), np.array([[1]]))
            index_exp_series = 0
            for it, expirement_runs in enumerate([int(x) for x in cfg['runs'].split(",")]):
                series_mean = np.mean(finals[i][index_exp_series:index_exp_series+expirement_runs])
                series_max = np.max(finals[i][index_exp_series:index_exp_series+expirement_runs])
                series_min = np.min(finals[i][index_exp_series:index_exp_series+expirement_runs])
                f.write(str(it+1)+" "+str(name)+" "+str(series_mean)+" "+str(series_max)+" "+str(series_min)+"\n")
                index_exp_series += expirement_runs
            f.write('\n')

    copyfile("config.txt", os.path.join(cfg['result_dir'], cfg['experiment']+'_config.txt'))

    for i, fun_name in enumerate(cfg['measure'].split(',')):
        plt.figure()
        val = np.array([r[:, i] for r in results])
        fun = getattr(measure, fun_name + '_name')
        plt.ylabel(fun(), fontsize=18)
        plt.title("F", fontsize=18)
        plt.xlabel(u"Номер итерации", fontsize=18)
        #plt.grid(True)
        index_exp_series = 0
        for it, expirement_runs in enumerate([int(x) for x in cfg['runs'].split(",")]):
            series_stats = calculate_stats(val[index_exp_series:index_exp_series+expirement_runs, 0:], cfg['begin_graph_iter'])
            plt.plot(range(cfg['begin_graph_iter'], cfg['begin_graph_iter'] + len(series_stats[0])), series_stats[0], linewidth=2, c=colors[it % len(colors)], label = labels[int(cfg['prepare_method'].split(',')[it])])
            plt.fill_between(range(cfg['begin_graph_iter'], cfg['begin_graph_iter'] + len(series_stats[0])), series_stats[2], series_stats[3], alpha = 0.1, facecolor=colors[it % len(colors)])
            '''plt.fill_between(range(len(series_stats[0])), series_stats[0] + series_stats[1], series_stats[0] - series_stats[1], alpha = 0.1, facecolor=colors[it % len(colors)])
            plt.plot(series_stats[2], linewidth=0.5, c=colors[it % len(colors)])
            plt.plot(series_stats[3], linewidth=0.5, c=colors[it % len(colors)])'''
            index_exp_series += expirement_runs

        plt.legend()
        plt.draw()

        filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'.pdf')
        plt.savefig(filename, format='pdf')
        fun = getattr(measure, fun_name + '_name_eng')
        plt.ylabel(fun(), fontsize=18)
        plt.title("F", fontsize=18)
        plt.xlabel("Iteration", fontsize=18)
        plt.legend()
        plt.draw()

        filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'_eng.pdf')
        plt.savefig(filename, format='pdf')
        if fun_name == "perplexity" or fun_name == "frobenius":
            plt.figure()
            val = np.array([r[:, i] for r in results])
            fun = getattr(measure, fun_name + '_name')
            plt.ylabel(fun(), fontsize=18)
            plt.title("F", fontsize=18)
            plt.xlabel(u"Номер итерации", fontsize=18)
            #plt.grid(True)
            index_exp_series = 0
            for it, expirement_runs in enumerate([int(x) for x in cfg['runs'].split(",")]):
                series_stats = calculate_stats(val[index_exp_series:index_exp_series+expirement_runs, 0:], 1)
                plt.plot(range(1, 1 + len(series_stats[0])), series_stats[0], linewidth=2, c=colors[it % len(colors)], label = labels[int(cfg['prepare_method'].split(',')[it])])
                plt.fill_between(range(1, 1 + len(series_stats[0])), series_stats[2], series_stats[3], alpha = 0.1, facecolor=colors[it % len(colors)])
                '''plt.fill_between(range(len(series_stats[0])), series_stats[0] + series_stats[1], series_stats[0] - series_stats[1], alpha = 0.1, facecolor=colors[it % len(colors)])
                plt.plot(series_stats[2], linewidth=0.5, c=colors[it % len(colors)])
                plt.plot(series_stats[3], linewidth=0.5, c=colors[it % len(colors)])'''
                index_exp_series += expirement_runs

            plt.legend()
            plt.draw()

            filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'_addit.pdf')
            plt.savefig(filename, format='pdf')
            fun = getattr(measure, fun_name + '_name_eng')
            plt.ylabel(fun(), fontsize=18)
            plt.title("F", fontsize=18)
            plt.xlabel("Iteration", fontsize=18)
            plt.legend()
            plt.draw()

            filename = os.path.join(cfg['result_dir'], cfg['experiment']+'_'+fun_name+'_eng_addit.pdf')
            plt.savefig(filename, format='pdf')