n_out = 2

# Spatial Covariance.
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)
Esempio n. 2
0
""" Test script for meslas.means

"""
import torch
from meslas.means import ConstantMean, LinearMean

# Array of locations.
S1 = torch.Tensor([[0, 0], [0, 1], [0, 2], [3, 0], [2, 2]]).float()
S2 = torch.Tensor([[0, 0], [3, 0], [5, 4]]).float()

# Corresponding response indices.
L1 = torch.Tensor([0, 0, 0, 1, 1]).long()
L2 = torch.Tensor([0, 3, 0]).long()

# Constant mean of each component.
means = torch.tensor([1.0, -2.0, 4.0, 33.0])

my_mean = ConstantMean(means)
print(my_mean(S1, L1))

# Test the linear trend mean function.
beta0s = means
beta1s = torch.tensor([[1.0, 1.0], [2.0, 2.0], [0.0, 0.0], [-1.0, 0.0]])

my_linear_mean = LinearMean(beta0s, beta1s)
print(my_linear_mean(S1, L1))