def collect_results(self): n_miss = self.missing_ratios.size n_solvers = len(self.solvers) x_est = np.full((self.sig_params['sig_len'], n_solvers, n_miss), np.nan, dtype=complex) track_iter = [[None for _ in range(n_miss)] for _ in range(n_solvers)] track_error = [[None for _ in range(n_miss)] for _ in range(n_solvers)] runtime = np.full((n_solvers, n_miss), np.nan) reconstruction_error = np.full((n_solvers, n_miss), np.nan) for i_task in range(self.get_n_tasks()): i_solver, i_ratio = self.get_task(i_task) filename = self.get_task_filename(task_id=i_task) if Path(filename).exists(): print('.', end='') data = np.load(filename, allow_pickle=True) x_est[:, i_solver, i_ratio] = data['x_est'] track_iter[i_solver][i_ratio] = data['track_iter'] track_error[i_solver][i_ratio] = data['track_error'] runtime[i_solver, i_ratio] = data['runtime'] reconstruction_error[i_solver, i_ratio] = \ compute_error(x_ref=self.x_ref, x_est=x_est[:, i_solver, i_ratio]) else: print('M', end='') np.savez(self.get_results_filename(), x_est=x_est, track_iter=track_iter, track_error=track_error, reconstruction_error=reconstruction_error, runtime=runtime, x_ref=self.x_ref) print('')
def update(self, X, i): self.iter.append(i) x_est = self.istft(X) err = compute_error(x_ref=self.x_ref, x_est=x_est) self.error.append(err)
def update(self, U, i): self.iter.append(i) x_est = phasecut_signal_reconstruction(U, self.B, self.istft) err = compute_error(x_ref=self.x_ref, x_est=x_est) self.error.append(err)
def plot_results(self): res = np.load(self.get_results_filename(), allow_pickle=True) print("dim res=", res['reconstruction_error'].shape) for i_ratio in range(self.missing_ratios.size): plt.figure() for i_solver in range(len(self.solvers)): plt.plot(self.widths, res['reconstruction_error'][i_solver, i_ratio, :], label=self.solvers[i_solver]) if self.missing_ratios[i_ratio] == 0.5: pli_error = np.full(5, fill_value=np.nan) for i in range(5): try: refmat = loadmat( 'mat_files/pcwd_large_0.5000000000000001_{}.mat'. format(2 * i + 1)) mat = loadmat( 'mat_files/Sol_pcwd_large_0.5000000000000001_{}.mat.mat' .format(2 * i + 1)) x_pli = phaselift_signal_reconstruction(mat['Sol']) pli_error[i] = compute_error(refmat['x_ref'], x_pli) except FileNotFoundError as e: print(e) print(pli_error) plt.plot(self.widths[~np.isnan(pli_error)], pli_error[~np.isnan(pli_error)], label='PLI') elif self.missing_ratios[i_ratio] == 0.3: pli_error = np.full(5, fill_value=np.nan) for i in range(5): try: refmat = loadmat( 'mat_files/pcwd_large_0.30000000000000004_{}.mat'. format(2 * i + 1)) mat = loadmat( 'mat_files/Sol_pcwd_large_0.30000000000000004_{}.mat.mat' .format(2 * i + 1)) x_pli = phaselift_signal_reconstruction(mat['Sol']) pli_error[i] = compute_error(refmat['x_ref'], x_pli) except FileNotFoundError as e: print(e) print(pli_error) plt.plot(self.widths[~np.isnan(pli_error)], pli_error[~np.isnan(pli_error)], label='PLI') else: pli_error = np.full(5, fill_value=np.nan) plt.legend() plt.xlabel('Hole width') plt.ylabel('Error (dB)') plt.grid() plt.title('{:.0%} missing phases'.format( self.missing_ratios[i_ratio])) plt.savefig(str( self.get_figure_folder() / '{}_err_ratio{:.0f}.pdf'.format( self.name, self.missing_ratios[i_ratio] * 100)), bbox_inches='tight') plt.show() for i_solver in range(len(self.solvers)): if self.solvers[i_solver] == 'RPI': continue for i_ratio in range(self.missing_ratios.size): plt.figure() for i_width in range(self.widths.size): plt.plot(res['track_iter'][i_solver][i_ratio][i_width], res['track_error'][i_solver][i_ratio][i_width], label='width: {}'.format(self.widths[i_width])) plt.xlabel('Iterations') plt.ylabel('Error (dB)') plt.grid() plt.title('Convergence of {}, {:.0%} missing'.format( self.solvers[i_solver], self.missing_ratios[i_ratio])) plt.legend() plt.savefig(str(self.get_figure_folder() / '{}_err_iter_{}_miss{:.0f}.pdf').format( self.name, self.solvers[i_solver], self.missing_ratios[i_ratio] * 100), bbox_inches='tight') plt.show()