diff --git a/filters.py b/filters.py index 1da675f..5e13b84 100644 --- a/filters.py +++ b/filters.py @@ -2,7 +2,6 @@ import autograd.numpy as npa from numpy.typing import ArrayLike as ArrayLikeType import matplotlib.pyplot as plt -filter_radius_um = 1 def _centered(arr: npa.ndarray, newshape: ArrayLikeType) -> npa.ndarray: """Formats the output of an FFT to center the zero-frequency component. diff --git a/mpid.py b/mpid.py index d1f7025..cf01145 100644 --- a/mpid.py +++ b/mpid.py @@ -137,13 +137,13 @@ class SpaceGrid: ''' Returns the resolution of the spatial grid in micrometers [um]. ''' - return self.unit_cell_pitch * 1e6 # convert to [um] + return self.unit_cell_pitch * 1e6 # returns [um] def get_unit_cell_pitch(self) -> float: ''' Returns the unit cell pitch of the spatial grid in micrometers [um]. ''' - return self.unit_cell_pitch * 1e6 # convert back to [um] + return self.unit_cell_pitch * 1e6 # returns [um] def get_size_x(self): return self.size_x @@ -396,7 +396,7 @@ class Simulation: self.filter_radius = None if conic_filter_radius is not None: - self.filter_radius = conic_filter_radius * 1e-6 + self.filter_radius = conic_filter_radius else: self.filter_radius = None diff --git a/single_converter_symm.py b/single_converter_symm.py index 7d69ba1..39c0162 100644 --- a/single_converter_symm.py +++ b/single_converter_symm.py @@ -75,7 +75,7 @@ simulation.set_optimization( ms_max_avail_diameter=ms_max_available_diameter, phase_mask_init_size=output_fiber_core_diameter/3, opt_max_eval=opt_max_eval, - #conic_filter_radius=1.0, + conic_filter_radius=1.0, ) simulation.run() diff --git a/single_converter_symm_ego.py b/single_converter_symm_ego.py index 45d5d54..e55c84d 100644 --- a/single_converter_symm_ego.py +++ b/single_converter_symm_ego.py @@ -88,7 +88,7 @@ def setup_optical_system()->pid.Simulation: ms_max_avail_diameter=ms_max_available_diameter, phase_mask_init_size=output_fiber_core_diameter/3, opt_max_eval=opt_max_eval, - conic_filter_radius=1.0, + conic_filter_radius=1.5, results_while_solving = False, save_results = False, ) @@ -299,7 +299,7 @@ def run_ego(initial_dataset, surrogate_model, n_ego_iter, xlimits, simulation): y_pred_grid = np.zeros_like(d0_grid) for i in range(d0_grid.shape[0]): for j in range(d0_grid.shape[1]): - y_pred_grid[i,j] = sm.predict_values(np.atleast_2d([d0_grid[i,j], d1_grid[i,j]])) + y_pred_grid[i,j] = sm.predict_values(np.atleast_2d([d0_grid[i,j], d1_grid[i,j]]))[0,0] contour = ax.contourf(d0_grid, d1_grid, y_pred_grid, levels=50, cmap='viridis') fig.colorbar(contour, ax=ax, label='predicted overlap') ax.scatter(xdoe_train_loaded[:,0], xdoe_train_loaded[:,1], color='blue', label='DOE Points') @@ -328,21 +328,6 @@ def run_ego(initial_dataset, surrogate_model, n_ego_iter, xlimits, simulation): y_opt = y_data[ind_best] np.savetxt(f'{surrogate_folder_name}/ego_opt_results.txt', np.hstack((x_opt,y_opt))) - ims = [] - fig = plt.figure(figsize=[10, 10]) - ax = plt.gca() - ax.axes.get_xaxis().set_visible(False) - ax.axes.get_yaxis().set_visible(False) - - for k in range(n_ego_iter): - image_pt = mpimg.imread(f"{surrogate_folder_name}/optimisation_{k}.pdf") - im = plt.imshow(image_pt) - ims.append([im]) - - ani = animation.ArtistAnimation(fig, ims, interval=500) - #save the animation to a gif file - ani.save(f'{surrogate_folder_name}/ego_optimization.gif', writer='pillow') - #plot of the EI history fig, ax = plt.subplots(figsize=(8,6)) ax.plot(range(1, n_ego_iter+1), EI_history, marker='o') @@ -459,8 +444,8 @@ if __name__ == "__main__": n_ego_iter = 15 #number of EGO refinement iterations corr_function_name = 'matern32' - doe_folder_name = 'DOE' - surrogate_folder_name = corr_function_name + '_surrogate_filtered' + doe_folder_name = 'DOE_1_5' + surrogate_folder_name = corr_function_name + '_surrogate_filtered_1_5' if not os.path.exists(doe_folder_name): os.makedirs(doe_folder_name) if not os.path.exists(surrogate_folder_name): @@ -486,4 +471,4 @@ if __name__ == "__main__": #EVALUATE THE MODEL PERFORMANCE BY RUNNING A LOO CROSS-VALIDATION refined_dataset = pickle.load(open(f'{surrogate_folder_name}/refined_dataset.pkl', 'rb')) - leave_one_out(refined_dataset, corr_function_name) \ No newline at end of file + leave_one_out(refined_dataset, corr_function_name)