# Dimension of the response. n_out = 2 # Spatial Covariance. matern_cov = Matern32(lmbda=0.1, sigma=1.0) # Cross covariance. cross_cov = UniformMixing(gamma0=0.0, sigmas=[np.sqrt(1.0), np.sqrt(1.5)]) covariance = FactorCovariance(matern_cov, cross_cov, n_out=n_out) # Specify mean function mean = ConstantMean([0.0, 0.0]) # Create the GRF. myGRF = GRF(mean, covariance) # Create a regular square grid in 2 dims. # Number of respones. dim = 2 my_grid = Grid(100, dim) # 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]).long() y = torch.tensor(11 * [-6]) mu_cond_grid, mu_cond_list, mu_cond_iso, K_cond_list, K_cond_iso = myGRF.krig_grid( my_grid, S_y, L_y, y, noise_std=0.05, compute_post_cov=True)
matern_cov = Matern32(lmbda=0.5, sigma=1.0) # Cross covariance. cross_cov = UniformMixing(gamma0=0.2, sigmas=[2.25, 2.25]) covariance = FactorCovariance(spatial_cov=matern_cov, cross_cov=cross_cov, n_out=n_out) # Specify mean function, here it is a linear trend that decreases with the # horizontal coordinate. beta0s = np.array([5.8, 24.0]) beta1s = np.array([[0, -4.0], [0, -3.8]]) mean = LinearMean(beta0s, beta1s) # Create the GRF. myGRF = GRF(mean, covariance) # ------------------------------------------------------ # DISCRETIZE EVERYTHING # ------------------------------------------------------ # Create a regular square grid in 2 dims. my_grid = TriangularGrid(31) print("Working on an equilateral triangular grid with {} nodes.".format( my_grid.n_points)) # Discretize the GRF on a grid and be done with it. # From now on we only consider locatoins on the grid. my_discrete_grf = DiscreteGRF.from_model(myGRF, my_grid) # ------------------------------------------------------ # Sample and plot
# Dimension of the response. n_out = 2 # Spatial Covariance. matern_cov = Matern32(lmbda=0.1, sigma=1.0) # Cross covariance. cross_cov = UniformMixing(gamma0=0.4, sigmas=[np.sqrt(1.0), np.sqrt(5.5)]) covariance = FactorCovariance(matern_cov, cross_cov, n_out=n_out) # Specify mean function mean = ConstantMean([0.0, 5.0]) # Create the GRF. myGRF = GRF(mean, covariance) # 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) # Sample and plot. sample = my_discrete_grf.sample() plot_grid_values(my_grid, sample) # Sample and plot. sample = my_discrete_grf.sample() plot_grid_values(my_grid, sample)
# Spatial Covariance. matern_cov = Matern32(lmbda=0.1, sigma=1.0) # Cross covariance. cross_cov = UniformMixing( gamma0=0.0, sigmas=[np.sqrt(0.25), np.sqrt(0.3), np.sqrt(0.4), np.sqrt(0.5)]) covariance = FactorCovariance(matern_cov, cross_cov, n_out=n_out) # Specify mean function mean = ConstantMean([1.0, -2.0, 4.0, 33.0]) # Create the GRF. myGRF = GRF(mean, covariance) # Array of locations. S1 = torch.Tensor([[0, 0], [0, 1], [0, 2], [3, 0]]).float() S2 = torch.Tensor([[0, 0], [3, 0], [5, 4]]).float() # Corresponding response indices. L1 = torch.Tensor([0, 0, 0, 1]).long() L2 = torch.Tensor([0, 3, 0]).long() # Test the sampling. print(myGRF.sample(S1, L1))
# Dimension of the response. n_out = 2 # Spatial Covariance. matern_cov = Matern32(lmbda=0.1, sigma=1.0) # Cross covariance. cross_cov = UniformMixing(gamma0=0.0, sigmas=[np.sqrt(1.0), np.sqrt(1.5)]) covariance = FactorCovariance(matern_cov, cross_cov, n_out=n_out) # Specify mean function mean = ConstantMean([0.0, 0.0]) # Create the GRF. myGRF = GRF(mean, covariance) # Create an equilateral triangular grid in 2 dims. # Number of respones. my_grid = TriangularGrid(40) print(my_grid.n_points) # 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() # Predict at some points. S2 = torch.Tensor([[0.2, 0.1], [0, 0], [3, 0], [5, 4]]).float()
# Dimension of the response. n_out = 2 # Spatial Covariance. matern_cov = Matern32(lmbda=0.1, sigma=1.0) # Cross covariance. cross_cov = UniformMixing(gamma0=0.0, sigmas=[np.sqrt(1.0), np.sqrt(1.5)]) covariance = FactorCovariance(matern_cov, cross_cov, n_out=n_out) # Specify mean function mean = ConstantMean([0.0, 0.0]) # Create the GRF. myGRF = GRF(mean, covariance) # Create an equilateral triangular grid in 2 dims. # Number of respones. my_grid = TriangularGrid(40) my_square_grid = SquareGrid(50, 2) print(my_grid.n_points) # 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() mu_cond, K_cond = myGRF.krig_isotopic(my_grid.points,