Esempio n. 1
0
def make_figure():
    fig = plt.figure(figsize=(12, 4))
    gs1 = matplotlib.gridspec.GridSpec(ncols=3, nrows=1, figure=fig)
    gs2 = matplotlib.gridspec.GridSpec(ncols=3, nrows=1, figure=fig)
    gs1.update(left=0.06,
               right=0.995,
               bottom=0.6,
               top=0.9,
               hspace=0.45,
               wspace=0.1)
    gs2.update(left=0.06,
               right=0.995,
               bottom=0.1,
               top=0.55,
               hspace=0.45,
               wspace=0.1)

    ax11 = fig.add_subplot(gs1[0])
    ax12 = fig.add_subplot(gs1[1])
    ax13 = fig.add_subplot(gs1[2])
    ax21 = fig.add_subplot(gs2[0])
    ax22 = fig.add_subplot(gs2[1])
    ax23 = fig.add_subplot(gs2[2])
    axes = [ax11, ax12, ax13, ax21, ax22, ax23]
    return fig, axes
Esempio n. 2
0
def make_angle_single_figure_grid():
    fig = plt.figure(figsize=(8, 3.25))
    gs1 = matplotlib.gridspec.GridSpec(ncols=1, nrows=1, figure=fig)
    gs2 = matplotlib.gridspec.GridSpec(ncols=1, nrows=1, figure=fig)
    gs1.update(left=0.15, right=0.9, bottom=0.475, top=0.88, hspace=0.15, wspace=0.15)
    gs2.update(left=0.15, right=0.9, bottom=0.18, top=0.425, hspace=0.15, wspace=0.15)

    return fig, fig.add_subplot(gs1[0]), fig.add_subplot(gs2[0])
Esempio n. 3
0
def make_starting_point_plot(dname, problemFunc, optimizers, results):
    fig = plt.figure(figsize=(6, 2.5))
    gs = matplotlib.gridspec.GridSpec(ncols=1, nrows=1, figure=fig)
    gs.update(left=0.1, right=0.95, bottom=0.15, top=0.85, hspace=0.2, wspace=0.1)

    def plot_1d(ax):
        LR = 0.5
        N_ITERS = 10
        thetas = [0.5, 1.0, 2.0, 4.0]

        ds = eftk.datasets.load("1D-Quadratic")
        problem = eftk.problem_defs.LinearRegression(*ds.get_train(), prior_var=np.inf)

        for opt_name, opt in optimizers.items():
            if opt_name is "GD":
                continue

            for i, theta0 in enumerate(thetas):
                res = list(opt(problem, lr=LR, theta=np.array([theta0]), damping=10**-6).run(n_iter=N_ITERS))
                if i == 0:
                    ax.plot(res, color=efplt.colors[opt_name], linewidth=LINEWIDTH, label=r"\bf{" + opt_name + "}", linestyle=efplt.linestyles[opt_name])
                else:
                    ax.plot(res, color=efplt.colors[opt_name], linewidth=LINEWIDTH, linestyle=efplt.linestyles[opt_name])

        ax.set_title(r"\LARGE $\mathbf{(x-0.5)^2 + (x+0.5)^2}$")
        ax.set_ylabel(r"\bf{Loss}")
        ax.set_xlabel("Iteration", labelpad=-15)
        ax.set_yscale("log")
        ax.set_xticks([0, 10])

        efplt.hide_frame([ax])

    def plot_boston(ax):

        factors = 1.0 - np.array([0.125, 0.25, 0.5, 1])
        hyperparameters = find_best_hyperparameters(results)

        different_startingpoints = run_different_startingpoints(dname, problemFunc, optimizers, hyperparameters, factors)

        for i, startingPoint in enumerate(different_startingpoints):
            ax.plot(startingPoint["NGD"], color=efplt.colors["NGD"], linewidth=LINEWIDTH, linestyle=efplt.linestyles["NGD"], label=r"\bf{NGD}" if i == 0 else None)
        for i, startingPoint in enumerate(different_startingpoints):
            ax.plot(startingPoint["EFGD"], color=efplt.colors["EFGD"], linewidth=LINEWIDTH, linestyle=efplt.linestyles["EFGD"], label=r"\bf{EFGD}" if i == 0 else None)

        ax.set_title(r"\bf{" + dname + "}")
        ax.set_yscale("log")
        ax.set_xlabel("Iteration", labelpad=-15)

        efplt.hide_frame([ax])
        ax.set_xticks([0, 20])

    plot_boston(fig.add_subplot(gs[0]))
    fig.legend(loc='right', bbox_to_anchor=(0.998, 0.85), ncol=1, borderpad=.25, handletextpad=0.4, borderaxespad=0)
    return fig
Esempio n. 4
0
def make_angle_figure_grid():
    fig = plt.figure(figsize=(12, 3))
    gs1 = matplotlib.gridspec.GridSpec(ncols=3, nrows=1, figure=fig)
    gs2 = matplotlib.gridspec.GridSpec(ncols=3, nrows=1, figure=fig)
    gs1.update(left=0.08, right=0.98, bottom=0.475, top=0.88, hspace=0.15, wspace=0.15)
    gs2.update(left=0.08, right=0.98, bottom=0.18, top=0.425, hspace=0.15, wspace=0.15)

    axes1 = [fig.add_subplot(gs1[0]), fig.add_subplot(gs1[1]), fig.add_subplot(gs1[2])]
    axes2 = [fig.add_subplot(gs2[0]), fig.add_subplot(gs2[1]), fig.add_subplot(gs2[2])]

    return fig, axes1, axes2
Esempio n. 5
0
def fig_and_axes():
    fig = plt.figure(figsize=(12, 3.2))
    gs = matplotlib.gridspec.GridSpec(1, 4)
    gs.update(left=0.01,
              right=0.99,
              wspace=0.1,
              hspace=0.2,
              bottom=0.05,
              top=0.90)
    axes = [fig.add_subplot(gs[i, j]) for i in range(1) for j in range(4)]
    return fig, axes