# Create an equilateral triangular grid in 2 dims. # Number of respones. my_grid = TriangularGrid(40) my_square_grid = SquareGrid(50, 2) my_discrete_grf = DiscreteGRF.from_model(myGRF, my_grid) # Observe some data. S_y = torch.tensor([[0.2, 0.1], [0.2, 0.2], [0.2, 0.3], [0.2, 0.4], [0.2, 0.5], [0.2, 0.6], [0.2, 0.7], [0.2, 0.8], [0.2, 0.9], [0.2, 1.0], [0.6, 0.5]]) L_y = torch.tensor([0, 0, 0, 0, 0, 1, 1, 0 ,0 ,0, 0]) y = torch.tensor(11*[-6]).float() # Since we are working with a discrete GRF, we can only observa data at grid # nodes. Hence get the ones corresponding to the measured data. S_y_inds = my_grid.get_closest(S_y) my_sensor = DiscreteSensor(my_grid, my_discrete_grf) # Excursion threshold. lower = torch.tensor([2.5, 20.0]).float() my_sensor.update_design(S_y_inds, L_y, y, noise_std=0.05) excursion_probas = my_sensor.compute_exursion_prob(lower) plot_grid_probas(my_grid, excursion_probas, my_sensor.S_y_tot)
noise_realization = noise_distr.sample() return ground_truth[node_ind] + noise_realization my_sensor = DiscreteSensor(my_discrete_grf) # Excursion threshold. lower = torch.tensor([2.3, 22.0]).float() # Get the real excursion set and plot it. excursion_ground_truth = (sample.isotopic > lower).float() plot_grid_values(my_grid, excursion_ground_truth.sum(dim=1), cmap="proba") # Plot the prior excursion probability. excu_probas = my_sensor.compute_exursion_prob(lower) plot_grid_probas(my_grid, excu_probas) print(my_sensor.grf.mean_vec.isotopic.shape) # Start from lower middle corner. my_sensor.set_location([0.0, 0.5]) # First initialize the myopic strategy. my_sensor.neighbors_eibv, my_sensor.neighbors_inds = my_sensor.get_neighbors_isotopic_eibv( noise_std, lower) # Run the myopic strategy for a while n_steps = 4 for i in range(n_steps): my_sensor.run_myopic_stragegy(n_steps=1, data_feed=data_feed, lower=lower,
from meslas.plotting import plot_grid_values, plot_grid_probas plot_grid_values(my_grid, mu_cond, S_y, L_y) plot_grid_values(my_square_grid, mu_cond_sq, S_y, L_y) # Try the variance part. mu_cond, var_cond = myGRF.krig_isotopic(my_grid.points, S_y, L_y, y, noise_std=0.05, compute_post_var=True) plot_grid_values(my_grid, var_cond, S_y, L_y, cmap="proba") variance_reduction = myGRF.variance_reduction_isotopic(my_grid.points, S_y, L_y, noise_std=0.05) plot_grid_values(my_grid, variance_reduction, S_y, L_y, cmap="proba") K_cond_diag = torch.diagonal(K_cond.isotopic, dim1=0, dim2=1).T lower = torch.tensor([-1.0, -1.0]).double() coverage = coverage_fct_fixed_location(mu_cond.isotopic, K_cond_diag, lower, upper=None) plot_grid_probas(my_grid, coverage, title="Excursion Probability")