def main():

    # Import pickle resuts
    with open('plot_10000.pkl', 'rb') as f:
        training_reward = pickle.load(f)

    # Create the episode list
    episode = list(range(100, 10000, 10))

    # Create the average list for plotting
    avg_list = [np.mean(training_reward[(i - 100):i]) for i in episode]

    # Smooth the average list
    avg_list_smoothed = uniform_filter1d(avg_list, 1)

    # Create the standard deviation list
    stdev_list = [np.std(training_reward[(i - 100):i]) for i in episode]
    stdev_list_smoothed = uniform_filter1d(stdev_list, 1)

    # Plot the episodic raw reward
    plt.plot(episode, training_reward[100:10000:10])
    tikz_save('raw_reward_plot.tikz')
    plt.close()

    # Plot the average reward for and standard deviation band
    plt.plot(episode, avg_list)
    plt.fill_between(episode,
                     avg_list_smoothed + stdev_list_smoothed,
                     avg_list_smoothed - stdev_list_smoothed,
                     alpha=0.3,
                     edgecolor="#ff7f0e")

    tikz_save('average_reward_plot.tikz')
    plt.close()
예제 #2
0
def PlotTikZ(filename, plot2save, scale=None):
    try:
        import matplotlib
    except:
        return
    try:
        from tikzplotlib import save as tikz_save
    except:
        try:
            from matplotlib2tikz import save as tikz_save
        except:
            return

    if not isinstance(plot2save, matplotlib.figure.Figure):
        plot2save = plot2save.gcf()
    try:
        tikz_save(filename,
                  figure=plot2save,
                  show_info=False,
                  float_format='%.6g')
    except:
        tikz_save(filename, figure=plot2save, show_info=False)
    texfile = open(filename, 'rU' if sys.version_info.major < 3 else 'r')
    lines = []
    for line in texfile:
        line = line.replace('\xe2\x88\x92', '-')
        if not scale is None:
            line = line.replace('begin{tikzpicture}',
                                'begin{tikzpicture}[scale=' + str(scale) + ']')
        lines.append(str(line))
    texfile.close()
    texfile = open(filename, 'w')
    for line in lines:
        texfile.write(line)
    texfile.close()
예제 #3
0
    def save_fig(self,
                 out_file,
                 fig=None,
                 png_preview=True,
                 override_externals=True,
                 post_process=True,
                 rm_damping_label=False):
        """Save matplotlib figure as TikZ. Optional PNG out.

        Create the directory if it does not exist.
        """
        if fig is not None:
            self.set_current(fig)

        tex_file, png_file = [
            self._add_extension(out_file, extension)
            for extension in ['tex', 'png']
        ]

        os.makedirs(os.path.dirname(out_file), exist_ok=True)

        if png_preview:
            plt.savefig(png_file, bbox_inches='tight')

        self._fix_underscore_latex_formatting_in_title()

        tikz_save(tex_file,
                  override_externals=override_externals,
                  extra_axis_parameters=self.extra_axis_parameters)

        if post_process is True:
            self.post_process(out_file, rm_damping_label=rm_damping_label)
예제 #4
0
def saveToTikz(nameTikzFile):

    plt.grid(True)
    #tikzplotlib.clean_figure()
    tikz_save(nameTikzFile,
              axis_height='\\figureheight',
              axis_width='\\figurewidth',
              extra_axis_parameters=[
                  '/pgf/number format/.cd, 1000 sep={}', 'title=\\figuretitle',
                  'xlabel=\\figurexlabel', 'ylabel=\\figureylabel'
              ])
def plot_precision_recall_curves(precissions_rgb, recalls_rgb, precisions_d3,
                                 recalls_d3, precisions_rgbd, recalls_rgbd,
                                 precisions_rgbdf, recalls_rgbdf):
    fig, ax = plt.subplots(figsize=(6, 4))
    ax.plot(recalls_rgb, precissions_rgb, label="RGB")
    ax.plot(recalls_d3, precisions_d3, label="D3")
    ax.plot(recalls_rgbd, precisions_rgbd, label="RGBD")
    ax.plot(recalls_rgbdf, precisions_rgbdf, label="RGBD-F")

    ax.set_xlabel("Recall")
    ax.set_ylabel("Precission")
    ax.set_ylim(0., 1.05)
    ax.legend()
    tikz_save("precision_recall_elevator.tex")

    plt.show()
예제 #6
0
파일: main.py 프로젝트: oeams/gurkal
def compare_coefficients():
    rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']})
    rc('text', usetex=True)
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')
    matplotlib.rcParams['text.usetex'] = True
    matplotlib.rcParams['text.latex.unicode'] = True

    jobs = [1, 2, 3, 4]
    nP = 2
    diff = [1]

    for c2 in range(4, 5):
        ran = []
        gap = []
        rel = []
        for c1 in range(1, 6):
            Q = create.createQUBO(jobs, nP, diff, c1, c2)
            best, second, worst = solve.solution_distribution(
                Q, len(jobs), nP, diff,
                max(jobs) * c1 + 1, 1)
            ran.append(worst - best)
            gap.append(second - best)
            rel.append(float(second - best) / float(worst - best))

        x_ran = list(np.arange(0.8, 5.8, 1))
        x_gap = list(np.arange(1.2, 6.2, 1))
        x_rel = list(range(1, 6, 1))
        f, ax1 = plt.subplots()
        ax2 = ax1.twinx()
        ax1.bar(x_ran, ran, width=0.4)
        ax1.bar(x_gap, gap, color='g', width=0.4)
        ax1.set_yscale('log')
        ax2.plot(x_rel, rel, 'r')
        ax2.tick_params(axis='y', colors='r')
        plt.title(str(c1) + ", " + str(c2))
        ax1.legend(['Spannweite', u'Lucke'])
        ax1.set_ylabel("Energiespektrum")
        ax1.set_xlabel("Koeffizent A")
        ax2.set_ylabel(u"Verhaltnis")

        tikz_save(str(c1) + ", " + str(c2),
                  figureheight='\\figureheight',
                  figurewidth='\\figurewidth')
예제 #7
0
def plot_runtimes(rgb_file, d3_file, rgbd_file, rgbd_fusenet_file):
    rgb_result = pd.read_csv(rgb_file)
    d3_result = pd.read_csv(d3_file)
    rgbd_result = pd.read_csv(rgbd_file)
    rgbd_fusenet_result = pd.read_csv(rgbd_fusenet_file)
    data = [
        rgb_result['time'], d3_result['time'], rgbd_result['time'],
        rgbd_fusenet_result['time']
    ]
    fig, ax = plt.subplots()
    flierprops = {'color': 'black', 'marker': 'x'}
    boxprops = {'color': 'black', 'linestyle': '-'}

    ax.boxplot(data, flierprops=flierprops, boxprops=boxprops)
    plt.xlabel("model-version")
    plt.ylabel("time [h]")
    from tikzplotlib import save as tikz_save
    tikz_save(f"hyperopt_runtime_boxplot.tex")

    plt.show()
예제 #8
0
def plot_logs(ps, legend, title, window_size=25, vtag='mse', ylim=[0.00, 0.35],
              tikz=False, pdf=False, filename='tfplots.tex', log=False):
    # cs = ['b', 'r', 'g']
    for no, p in enumerate(ps):
        adding_umc = []
        try:
            for e in tf.train.summary_iterator(p):
                for v in e.summary.value:
                    if v.tag == vtag:
                        # print(v.simple_value)
                        adding_umc.append(v.simple_value)
        except:
            # ingnore that silly data loss error....
            pass
        # x = np.array(range(len(adding_umc)))

        y = np.array(adding_umc)
        yhat = tensoboard_average(y, window_size)
        xhat = np.linspace(0, y.shape[0], yhat.shape[0])
        # plt.plot(yhat, cs[no])
        if log:
            plt.semilogy(xhat, yhat, label=legend[no])
        else:
            plt.plot(xhat, yhat, label=legend[no])

    plt.ylim(ylim[0], ylim[1])
    plt.grid()
    plt.ylabel(vtag)
    plt.xlabel('updates')
    plt.legend()
    plt.title(title)

    if tikz:
        from tikzplotlib import save as tikz_save
        tikz_save(filename)
    elif pdf:
        plt.savefig(filename, bbox_inches='tight')
    else:
        plt.show()
예제 #9
0
def plot_training(rgb_file, d3_file, rgbd_file, rgbd_fusenet_file):
    rgb_result = pd.read_csv(rgb_file)
    d3_result = pd.read_csv(d3_file)
    rgbd_result = pd.read_csv(rgbd_file)
    rgbd_fusenet_result = pd.read_csv(rgbd_fusenet_file)

    fig, ax = plt.subplots()
    print(rgb_result)
    ax.plot(rgb_result['f1score'], label="RGB")
    ax.plot(d3_result['f1score'], label="D3")
    ax.plot(rgbd_result['f1score'], label="RGBD")
    ax.plot(rgbd_fusenet_result['f1score'], label="RGBD-F")
    ax.legend(loc='upper center',
              bbox_to_anchor=(0.5, 1.3),
              ncol=3,
              fancybox=False,
              shadow=False)
    plt.xlabel("Evaluation run")
    plt.ylabel("F1 score")
    from tikzplotlib import save as tikz_save
    tikz_save(f"hyperopt_evaluation_runs.tex")

    plt.show()
예제 #10
0
print(rgb_tra)
print(rgb_val)

training = pd.DataFrame(columns=["RGB", "D3", "RGBD", "RGBD-F"])
training["RGB"] = rgb_tra["Value"]
training["D3"] = d3_tra["Value"]
training["RGBD"] = rgbd_tra["Value"]
training["RGBD-F"] = rgbdf_tra["Value"]
training.plot()

print(training)

plt.ylabel("training loss")
plt.xlabel("epoch")
tikz_save("elevator_runs_train.tex")
plt.show()

validation = pd.DataFrame(columns=["RGB", "D3", "RGBD", "RGBD-F"])
validation["RGB"] = rgb_val["Value"]
validation["D3"] = d3_val["Value"]
validation["RGBD"] = rgbd_val["Value"]
validation["RGBD-F"] = rgbdf_val["Value"]
validation['index'] = range(0, len(validation))

rgb_trend = get_trend(validation["index"], validation["RGB"])
d3_trend = get_trend(validation["index"], validation["D3"])
rgbd_trend = get_trend(validation["index"], validation["RGBD"])
rgbdf_trend = get_trend(validation["index"], validation["RGBD-F"])

validation_avg = validation.groupby(np.arange(len(validation)) // 5).mean()