def main(fmt='png'): nsamples = 8 npixels = 256 tol = 1e-6 # for example reconstructions, run GD until ||x-x*|| <= tol objfun = get_dataset(nsamples, npixels, lower_level_solver='gd') dirname = 'examples' outfolder = os.path.join(MAIN_OUTFOLDER, dirname) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) # Plot the training data (true & noisy images only) plot_training_data(objfun, 6, npixels, filename=os.path.join(outfolder, 'gd_demo_data'), ymin=-0.3, ymax=1.3, legend_loc='center left', fmt=fmt, font_size='x-small', nrows=2, axis_font_size='small', figsize=cm2inch(1.3*8,1.3*3.5)) param_combinations = [] # alpha, eps_l2, eps_tv, xlabel, ylabel # first row (vary alpha) param_combinations.append((1.0, 1e-3, 1e-3, r'$\alpha=1$', 'TV\nweight')) param_combinations.append((1e-1, 1e-3, 1e-3, r'$\alpha=0.1$', None)) param_combinations.append((1e-2, 1e-3, 1e-3, r'$\alpha=0.01$', None)) # second row (vary eps_tv) param_combinations.append((1.0, 1e-3, 1e0, r'$\nu=1$', 'TV\nsmoothing')) param_combinations.append((1.0, 1e-3, 1e-1, r'$\nu=0.1$', None)) param_combinations.append((1.0, 1e-3, 1e-2, r'$\nu=0.01$', None)) # third row (vary eps_l2) param_combinations.append((1.0, 1e0, 1e-3, r'$\xi=1$', 'L2\npenalty')) param_combinations.append((1.0, 1e-1, 1e-3, r'$\xi=0.1$', None)) param_combinations.append((1.0, 1e-2, 1e-3, r'$\xi=0.01$', None)) plot_example_recons(objfun, 0, tol, npixels, param_combinations, 3, 3, filename=os.path.join(outfolder, 'gd_demo_recons'), figsize=cm2inch(1.3 * 8, 1.3 * 4.3), ymin=-0.3, ymax=1.3, legend_loc='center left', fmt=fmt, font_size='x-small', axis_font_size='small') return
def main(fmt='png'): # Generate main plots for 2D denoising setting_filestem = '3param2d_demo' infolder = os.path.join(RESULTS_FOLDER, setting_filestem) outfolder = os.path.join(MAIN_OUTFOLDER, setting_filestem) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) results_list = get_results(setting_filestem, infolder=infolder, fista_dynamic_only=False) # Basic objective reduction make_obj_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_obj_redn'), use_logscale=False, legend_loc='upper right', fmt=fmt, ymin=None, ymax=None, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', legend_ncol=2) # niters plot make_niters_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_niters'), use_logscale=True, legend_loc=None, fmt=fmt, cumulative=True, ymin=None, ymax=None, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', xtick_freq=25) # Parameter plots for param_idx, param_name in [(0, 'alpha'), (1, 'eps_l2'), (2, 'eps_tv')]: make_param_plot(results_list, param_idx, filename=os.path.join(outfolder, setting_filestem + '_param_%s' % param_name), use_logscale=True, legend_loc=None, fmt=fmt, param_is_log=True, ymin=None, ymax=None, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small') # Build final reconstructions (this is slow, so save results before plotting) build_final_reconstructions2d(results_list, outfolder, fista_dynamic_only=True, lower_level_solver='fista', lower_level_niters=2000) # and plot final reconstructions img_idx = [0, 3, 7, 12, 20] plot_final_reconstructions2d_vertical(results_list, img_idx, outfolder, filename=os.path.join(outfolder, setting_filestem + '_recons'), fmt=fmt, fista_dynamic_only=True, axis_font_size='small', figsize=cm2inch(1.3*6,1.3*(3*len(img_idx)))) # sigma v alpha comparison setting_files = [] setting_files.append('3param2d_demo') setting_files.append('3param2d_demo_noise2') setting_files.append('3param2d_demo_noise3') setting_files.append('3param2d_demo_noise4') setting_files.append('3param2d_demo_noise5') setting_files.append('3param2d_demo_noise6') setting_files.append('3param2d_demo_noise7') setting_files.append('3param2d_demo_noise8') plot_alpha_sigma_relationship(setting_files, filename=os.path.join(outfolder, setting_filestem + '_alpha_sigma'), ymin=None, ymax=None, legend_loc='lower right', lw=1.5, fmt=fmt, font_size='x-small', axis_font_size='small', markersize=6, solver_name='fista_dynamic', figsize=cm2inch(1.3*7, 1.3*2.5)) return
def main_3param(fmt='png'): # Generate main plots for 3-param denoising setting_filestem = '3param_reg6' infolder = os.path.join(RESULTS_FOLDER, setting_filestem) outfolder = os.path.join(MAIN_OUTFOLDER, setting_filestem) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) results_list = get_results(setting_filestem, infolder=infolder, fista_dynamic_only=False) # Basic objective reduction make_obj_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_obj_redn'), use_logscale=True, legend_loc='upper right', fmt=fmt, ymin=2e0, ymax=1e2, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', legend_ncol=2) # niters plot make_niters_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_niters'), use_logscale=True, legend_loc=None, fmt=fmt, cumulative=True, ymin=None, ymax=None, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', xtick_freq=25) # reconstructions plot_final_reconstructions(results_list, nimgs=6, filename=os.path.join(outfolder, setting_filestem + '_recons'), legend_loc='center left', fmt=fmt, ymin=None, ymax=None, lower_level_solver='fista', lower_level_niters=1000, fista_dynamic_only=True, figsize=cm2inch(1.3 * 8, 1.3 * 3.5), font_size='x-small', nrows=2, axis_font_size='small') # reconstructions with beta=1e-4 alt_setting_filestem = '3param_reg4' alt_infolder = os.path.join(RESULTS_FOLDER, alt_setting_filestem) alt_results_list = get_results(alt_setting_filestem, infolder=alt_infolder, fista_dynamic_only=False) plot_final_reconstructions(alt_results_list, nimgs=6, filename=os.path.join(outfolder, alt_setting_filestem + '_recons'), legend_loc='center left', fmt=fmt, ymin=None, ymax=None, lower_level_solver='fista', lower_level_niters=1000, fista_dynamic_only=True, figsize=cm2inch(1.3 * 8, 1.3 * 3.5), font_size='x-small', nrows=2, axis_font_size='small') # reconstructions after different numbers of iterations eval_idx = [1, 10, 20, 100] make_recons_evolution_plot(setting_filestem, eval_idx, img_idx=0, nrows=2, filename=os.path.join(outfolder, setting_filestem + '_recons_during_solve'), solver_name='fista_dynamic', lower_level_solver='fista', lower_level_niters=1000, legend_loc='center left', legend_ncol=1, axis_font_size='small', font_size='x-small', figsize=cm2inch(1.3 *8, 1.3 * 3.5), ymin=-0.3, ymax=1.3, fmt=fmt) return
def main_1param(fmt='png'): # Generate main plots for 1-param denoising setting_filestem = '1param_start0_budget20' infolder = os.path.join(RESULTS_FOLDER, setting_filestem) outfolder = os.path.join(MAIN_OUTFOLDER, setting_filestem) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) results_list = get_results(setting_filestem, infolder=infolder, fista_dynamic_only=False) # Basic objective reduction make_obj_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_obj_redn'), use_logscale=True, legend_loc='upper right', fmt=fmt, ymin=8e-1, ymax=2e3, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', legend_ncol=2) # Zoomed in objective reduction make_obj_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_obj_redn_zoom'), use_logscale=False, legend_loc=None, fmt=fmt, ymin=1.3, ymax=3.0, figsize=cm2inch(8,4), font_size='x-small', axis_font_size='small') # Alpha plot make_param_plot(results_list, 0, filename=os.path.join(outfolder, setting_filestem + '_param_alpha'), use_logscale=True, legend_loc=None, fmt=fmt, param_is_log=True, ymin=None, ymax=None, figsize=cm2inch(8,4), font_size='x-small', axis_font_size='small') # niters plot make_niters_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_niters'), use_logscale=True, legend_loc=None, fmt=fmt, cumulative=True, ymin=None, ymax=None, figsize=cm2inch(8,4), font_size='x-small', axis_font_size='small', xtick_freq=5) plot_final_reconstructions(results_list, nimgs=6, filename=os.path.join(outfolder, setting_filestem + '_recons'), legend_loc='center left', fmt=fmt, ymin=-0.3, ymax=1.3, lower_level_solver='fista', lower_level_niters=1000, fista_dynamic_only=True, figsize=cm2inch(1.3 * 8, 1.3 * 3.5), font_size='x-small', nrows=2, axis_font_size='small') # alpha trajectories for different starting points alt_starting_points = ['1param_start1_budget20', '1param_start2_budget20', '1param_startm1_budget20', '1param_startm2_budget20'] for alt_setting_filestem in alt_starting_points: if 'start1' in alt_setting_filestem: # has a legend, so a bit special legend_loc = 'lower right' legend_ncol = 2 ymin = 1e-2 else: legend_loc = None legend_ncol = 1 ymin = None alt_infolder = os.path.join(RESULTS_FOLDER, alt_setting_filestem) alt_results_list = get_results(alt_setting_filestem, infolder=alt_infolder, fista_dynamic_only=False) make_param_plot(alt_results_list, 0, filename=os.path.join(outfolder, alt_setting_filestem + '_param_alpha'), use_logscale=True, legend_loc=legend_loc, fmt=fmt, param_is_log=True, ymin=ymin, ymax=None, figsize=cm2inch(1.5 * 6, 1.5 * 3), font_size='x-small', legend_ncol=legend_ncol, axis_font_size='small') # Robustness to starting point [width=9cm, height=2.5cm] filestems = ['1param_start%s_budget20' % s for s in ['m2', 'm1', '0', '1', '2']] plot_starting_point_robust(filestems, filename=os.path.join(outfolder, '1param_start_robust'), font_size='x-small', figsize=cm2inch(1.3*8,1.3*2.5), fmt=fmt, legend_loc='upper left', legend_ncol=1, axis_font_size='small') return
def main(fmt='png'): dirname = 'examples' outfolder = os.path.join(MAIN_OUTFOLDER, dirname) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) # compare error bounds [width=3.6cm, height=2.5cm, but scaled] print("============") print("Nesterov quadratic with GD") print("============") compare_bounds_single_problem('nesterov', 'gd', 200, n=10, filename=os.path.join( outfolder, 'nesterov10_gd200'), legend_loc='lower left', fmt=fmt, font_size='x-small', axis_font_size='small', ymin=None, ymax=None, figsize=cm2inch(1.5 * 3.6, 1.5 * 2.5), lw=1.5) print("============") print("Nesterov quadratic with FISTA") print("============") compare_bounds_single_problem('nesterov', 'fista', 200, n=10, filename=os.path.join( outfolder, 'nesterov10_fista200'), legend_loc=None, fmt=fmt, font_size='x-small', axis_font_size='small', ymin=None, ymax=None, figsize=cm2inch(1.5 * 3.6, 1.5 * 2.5), lw=1.5) print("============") print("Denoising with GD") print("============") compare_bounds_single_problem('denoising', 'gd', 2000, filename=os.path.join( outfolder, 'denoising_gd2000'), legend_loc=None, fmt=fmt, font_size='x-small', axis_font_size='small', ymin=None, ymax=None, figsize=cm2inch(1.5 * 3.6, 1.5 * 2.5), lw=1.5) print("============") print("Denoising with FISTA") print("============") compare_bounds_single_problem('denoising', 'fista', 1000, filename=os.path.join( outfolder, 'denoising_fista1000'), legend_loc=None, fmt=fmt, font_size='x-small', axis_font_size='small', ymin=None, ymax=None, figsize=cm2inch(1.5 * 3.6, 1.5 * 2.5), lw=1.5) return
def main(fmt='png'): # Generate main plots for MRI sampling setting_filestem = 'inpainting_mri_demo2_several_noise' infolder = os.path.join(RESULTS_FOLDER, setting_filestem) outfolder = os.path.join(MAIN_OUTFOLDER, setting_filestem) if not os.path.isdir(outfolder): os.makedirs(outfolder, exist_ok=True) results_list = get_results(setting_filestem, infolder=infolder, fista_dynamic_only=False) # Basic objective reduction make_obj_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_obj_redn'), use_logscale=False, legend_loc='upper right', fmt=fmt, ymin=0.3, ymax=5.0, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', legend_ncol=2) # niters plot make_niters_plot(results_list, filename=os.path.join(outfolder, setting_filestem + '_niters'), use_logscale=True, legend_loc=None, fmt=fmt, cumulative=True, ymin=1e4, ymax=None, figsize=cm2inch(8, 4), font_size='x-small', axis_font_size='small', xtick_freq=500) # final sampling patterns make_sampling_pattern_plot(results_list, filename=os.path.join( outfolder, setting_filestem + '_sampling_patterns'), fmt=fmt, axis_font_size='small', apply_fftshift=True, cmap='gray', sampling_thresh=0.001, figsize=cm2inch(1.3 * 8, 1.3 * 4)) # reconstructions make_mri_reconstruction_plot(results_list, filename=os.path.join( outfolder, setting_filestem + '_recons'), nimgs=6, ymin=None, ymax=None, legend_loc='center left', fmt=fmt, font_size='x-small', fista_dynamic_only=True, lower_level_solver='fista', lower_level_niters=2000, nrows=2, axis_font_size='small', sampling_thresh=0.001, figsize=cm2inch(1.3 * 8, 1.3 * 3.5)) return