def main(): os.makedirs(output_path, exist_ok=True) # Load F = torch.from_numpy( np.load(os.path.join(data_folder, "F_full_surface.npy"))).float().detach() grid = Grid.load(os.path.join(data_folder, "grid.pickle")) volcano_coords = torch.from_numpy(grid.cells).float().detach() data_coords = torch.from_numpy( np.load(os.path.join(data_folder, "surface_data_coords.npy"))).float() ground_truth = torch.from_numpy( np.load(os.path.join(data_folder, "post_sample.npy"))) data_values = torch.from_numpy( np.load(os.path.join(data_folder, "post_data_sample.npy"))) # Dictionary between the original Niklas data and our discretization. niklas_data_inds = torch.from_numpy( np.load(os.path.join(data_folder, "niklas_data_inds_insurf.npy"))).long() niklas_coords = data_coords[niklas_data_inds].numpy() # -------------------------------- # DEFINITION OF THE EXCURSION SET. # -------------------------------- THRESHOLD_low = 700.0 excursion_inds = (ground_truth >= THRESHOLD_low).nonzero()[:, 0] # Params data_std = 0.1 # lambda0 = 338.0 lambda0 = 338.46 sigma0 = 359.49 m0 = -114.40 # Define GP model. data_feed = lambda x: data_values[x] updatable_gp = UpdatableGP(cl, lambda0, sigma0, m0, volcano_coords, n_chunks=80) for i, current_ind in enumerate(niklas_data_inds): y = data_feed(current_ind) G = F[current_ind, :].reshape(1, -1) updatable_gp.update(G, y, data_std) # Extract variance and coverage function. coverage = updatable_gp.coverage(THRESHOLD_low, None) # Save. np.save(os.path.join(output_path, "coverage_{}.npy".format(i)), coverage)
def main(): os.makedirs(output_path, exist_ok=True) # Load F = torch.from_numpy( np.load(os.path.join(data_folder, "F_full_surface.npy"))).float().detach() grid = Grid.load(os.path.join(data_folder, "grid.pickle")) volcano_coords = torch.from_numpy(grid.cells).float().detach() data_coords = torch.from_numpy( np.load(os.path.join(data_folder, "surface_data_coords.npy"))).float() ground_truth = torch.from_numpy( np.load(os.path.join(data_folder, "post_sample.npy"))) data_values = torch.from_numpy( np.load(os.path.join(data_folder, "post_data_sample.npy"))) # Dictionary between the original Niklas data and our discretization. niklas_data_inds = torch.from_numpy( np.load(os.path.join(data_folder, "niklas_data_inds_insurf.npy"))).long() niklas_coords = data_coords[niklas_data_inds].numpy() # -------------------------------- # DEFINITION OF THE EXCURSION SET. # -------------------------------- THRESHOLD_low = 700.0 excursion_inds = (ground_truth >= THRESHOLD_low).nonzero()[:, 0] # Params data_std = 0.1 # lambda0 = 338.0 lambda0 = 338.46 sigma0 = 359.49 m0 = -114.40 # Define GP model. data_feed = lambda x: data_values[x] updatable_gp = UpdatableGP(cl, lambda0, sigma0, m0, volcano_coords, n_chunks=80) # Asimilate myopic data collection plan. visited_inds = np.load(os.path.join(results_folder, "visited_inds.npy")) observed_data = np.load(os.path.join(results_folder, "visited_inds.npy")) n_chunks = 80 for i, inds in enumerate(np.array_split(visited_inds, n_chunks)): print("Processing chunk {} / {}".format(i, n_chunks)) y = data_feed(inds) G_current = F[inds, :] updatable_gp.update(G_current, y, data_std)
pts_inds = np.linspace(1, 1999, k).astype(int) G_pts = np.zeros((k, my_problem.grid.cells.shape[0]), dtype=np.float32) G_pts[np.array(range(k)), pts_inds] = 1.0 data_std = 0.01 G_pts = torch.from_numpy(G_pts).float() d_pts = G_pts @ ground_truth # Observe k points. constant_updatable_gp = UpdatableGP(kernel, lambda0, torch.tensor([sigma0]), m0, cell_coords, n_chunks=200) constant_updatable_gp.update(G_pts, d_pts, data_std=0) post_mean = constant_updatable_gp.mean_vec.cpu().numpy() plot_basic(my_problem.grid, ground_truth.numpy(), additional_vals=[post_mean], points=[cell_coords[pts_inds], d_pts], outfile=os.path.join(output_folder, "posterior_points.png")) plot_basic(my_problem.grid, ground_truth.numpy(), points=[cell_coords[pts_inds], d_pts], outfile=os.path.join(output_folder, "ground_truth_marked_pts.png")) # Observe a few Fourier data. constant_updatable_gp = UpdatableGP(kernel, lambda0,
def main(): # Load G = torch.from_numpy(np.load(os.path.join( data_folder, "F_niklas.npy"))).float().detach() grid = Grid.load(os.path.join(data_folder, "grid.pickle")) volcano_coords = torch.from_numpy(grid.cells).float().detach() data_coords = torch.from_numpy( np.load(os.path.join(data_folder, "niklas_data_coords.npy"))).float() data_values = torch.from_numpy( np.load(os.path.join(data_folder, "niklas_data_obs.npy"))).float() n_data = G.shape[0] # Define GP model. data_std = 0.1 sigma0 = 284.66 m0 = 2139.1 lambda0 = 651.58 # Build trends: constant + planar + cylindrical. x0 = volcano_coords[:, 0].mean() # Volcano center. y0 = volcano_coords[:, 1].mean() z0 = volcano_coords[:, 2].mean() coeff_mean = torch.tensor([m0, 0.0, 0.0]).reshape(-1, 1) coeff_cov = torch.tensor([[200.0, 0, 0], [0, 0.05, 0], [0, 0, 0.05]]) coeff_F = torch.hstack([ torch.ones(volcano_coords.shape[0], 1), planar(volcano_coords, x0, y0, z0, phi=torch.tensor([45]), theta=torch.tensor([45])).reshape(-1, 1), cylindrical(volcano_coords, x0, y0).reshape(-1, 1) ]) # Model with trend. updatable_gp = UniversalUpdatableGP(kernel, lambda0, torch.tensor([sigma0]), volcano_coords, coeff_F, coeff_cov, coeff_mean, n_chunks=200) # Sample artificial volcano and # invert data at Niklas points. ground_truth, true_trend_coeffs = updatable_gp.sample_prior() noise = MultivariateNormal(loc=torch.zeros(n_data), covariance_matrix=data_std**2 * torch.eye(n_data)).rsample() synth_data = G @ ground_truth + noise updatable_gp.update(G, synth_data, data_std) np.save("post_mean_universal.npy", updatable_gp.mean_vec.detach().cpu().numpy()) np.save("ground_truth.npy", ground_truth.cpu().numpy()) # Model who thinks the trend is a constant. # Let's be fair and allow it to know the true mean. m0_true = true_trend_coeffs[0] constant_updatable_gp = UpdatableGP(kernel, lambda0, torch.tensor([sigma0]), m0_true, volcano_coords, n_chunks=200) constant_updatable_gp.update(G, synth_data, data_std) np.save("post_mean_constant.npy", constant_updatable_gp.mean_vec.detach().cpu().numpy()) np.save("true_trend_coeffs.npy", true_trend_coeffs.detach().cpu().numpy()) np.save("trend_matrix.npy", coeff_F.detach().cpu().numpy())