marker='^', alpha=0.5, linewidth=line_width, markersize=marker_size) ax.legend([r'gradient descent', r'lasso', r'least squares oracle'], fontsize=legend_font_size) ax.title.set_text(r'Comparing $\ell_{2}$ errors') def plot_everything(): simulations = load_simulations_from_directory('./outputs/gd_vs_lasso_d/') fig1, ax1 = get_new_fig_and_ax(1) plot_oracle_errors(simulations, ax1, get_d_simulation_set_up) ax1.set_xlabel(r'$\log \, d$') ax1.set_ylabel(r'$||\widehat{\mathbf{w}} - \mathbf{w}^{\star}||^{2}_{2}$') # plot_coordinates_paths(ax2, ax3) for ax in [ax1]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return fig1 if __name__ == '__main__': mpl.use('Agg') fig = plot_everything() save_fig(fig, './figures', 'lasso_vs_gd_d')
plot_errors_path(errs, xaxis, ax1, linewidth=line_width) def plot_everything(): fig1, ax1 = get_new_fig_and_ax(1) fig2, ax2 = get_new_fig_and_ax(2) compare_l2_errors(ax1, ax2) bottom1, top1 = ax1.get_ylim() bottom2, top2 = ax2.get_ylim() bottom = min(bottom1, bottom2) top = max(top1, top2) ax1.set_ylim(bottom, top) ax2.set_ylim(bottom, top) ax1.title.set_text('Constant step size') ax2.title.set_text('Increasing step sizes') for ax in [ax1, ax2]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return fig1, fig2 if __name__ == '__main__': mpl.use('Agg') fig1, fig2 = plot_everything() save_fig(fig1, './figures', 'constant_step_size') save_fig(fig2, './figures', 'increasing_step_sizes')
def plot_everything(simulations_dir): simulations = load_simulations_from_directory(simulations_dir) fig1, ax1 = get_new_fig_and_ax(1, width=6.0, height=9.0) fig2, ax2 = get_new_fig_and_ax(2, width=6.0, height=9.0) fig3, ax3 = get_new_fig_and_ax(3, width=6.0, height=9.0) compare_l2_errors(ax1, fig1, simulations) ax1.title.set_text(r'gd vs lasso $\ell_{2}$ errors') plot_l_infty_errors(ax2, fig2, simulations, 'gd') ax2.title.set_text(r'gd $\ell_{\infty}$ errors on $S^{c}$') plot_l_infty_errors(ax3, fig3, simulations, 'lasso') ax3.title.set_text(r'lasso $\ell_{\infty}$ errors on $S^{c}$') for ax in [ax1, ax2, ax3]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return fig1, fig2, fig3 if __name__ == '__main__': mpl.use('Agg') fig1, fig2, fig3 = plot_everything('./outputs/n_vs_k/') save_fig(fig1, './figures', 'n_vs_k_l2_comparisons') save_fig(fig2, './figures', 'n_vs_k_l_infty_gd') save_fig(fig3, './figures', 'n_vs_k_l_infty_lasso')
simulations = load_simulations_from_directory(simulations_dir) fig1, ax1 = get_new_fig_and_ax(1) fig2, ax2 = get_new_fig_and_ax(2) plot_oracle_errors(simulations, ax1, get_dataset_size_simulation_set_up, mu=0.5) ax1.title.set_text(r'Comparing $\ell_{2}$ errors, $\mu = 0.5$') plot_oracle_errors(simulations, ax2, get_dataset_size_simulation_set_up, mu=0.0) ax2.title.set_text(r'Comparing $\ell_{2}$ errors, $\mu = 0.0$') for ax in [ax1, ax2]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return fig1, fig2 if __name__ == '__main__': mpl.use('Agg') fig1, fig2 = plot_everything('./outputs/gd_vs_lasso_cor/') save_fig(fig1, './figures', 'phase_transition_n_cor_0_5') save_fig(fig2, './figures', 'phase_transition_n_cor_0_0')
bottom = min(bottom1, bottom2) top = max(top1, top2) # To make scaling the same as for plots in gd_vs_lasso # we override the top. top = 1.5 ax1.set_ylim(bottom, top) ax2.set_ylim(bottom, top) def plot_everything(): fig1, ax1 = get_new_fig_and_ax(1) fig2, ax2 = get_new_fig_and_ax(2) fig3, ax3 = get_new_fig_and_ax(3) plot_alpha_effect(ax1) plot_coordinates_paths(ax2, ax3) for ax in [ax1, ax2, ax3]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return (fig1, fig2, fig3) if __name__ == '__main__': mpl.use('Agg') fig1, fig2, fig3 = plot_everything() save_fig(fig1, './figures', 'alpha_effects') save_fig(fig2, './figures', 'alpha_large') save_fig(fig3, './figures', 'alpha_small')
transitions = [transition_gamma, transition_sigma, transition_log2_n] axes = [ax1, ax2, ax3] for transition, ax in zip(transitions, axes): bottom, top = ax.get_ylim() ax.vlines(transition, bottom, top, linestyles='solid', colors='red', linewidth=line_width) plot_coordinates_paths(simulations, ax4, ax5) for ax in [ax1, ax2, ax3, ax4, ax5]: for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]): item.set_fontsize(font_size) return (fig1, fig2, fig3, fig4, fig5) if __name__ == '__main__': mpl.use('Agg') fig1, fig2, fig3, fig4, fig5 = plot_everything() save_fig(fig1, './figures', 'phase_transition_gamma') save_fig(fig2, './figures', 'phase_transition_sigma') save_fig(fig3, './figures', 'phase_transition_n') save_fig(fig4, './figures', 'gd_path') save_fig(fig5, './figures', 'lasso_path')