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
# ------------------------------------------------------
# Sample all components at all locations.
sample = my_discrete_grf.sample()
plot_grid_values(my_grid, sample)

# From now on, we will consider the drawn sample as ground truth.
예제 #2
0
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)

# Sample the continuous version and compare.
sample_cont = myGRF.sample_isotopic(my_grid.points)
plot_grid_values(my_grid, sample_cont)
예제 #3
0
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()
L2 = torch.Tensor([0, 0, 1, 0]).long()

mu_cond_list, var_cond_list = myGRF.krig(S2,
                                         L2,
예제 #4
0
""" Test script for meslas.geometry submodule

"""
import torch
from meslas.geometry.grid import create_square_grid, TriangularGrid
import matplotlib.pyplot as plt

print(create_square_grid(10, 4))
print(create_square_grid(10, 4).shape)

my_grid = TriangularGrid(40)

neighbors_inds = my_grid.get_neighbors(100)

plt.scatter(my_grid.points[:, 0], my_grid.points[:, 1], c='k', s=1)
plt.scatter(my_grid.points[neighbors_inds, 0],
            my_grid.points[neighbors_inds, 1],
            c='b',
            s=1)
plt.scatter(my_grid.points[100, 0], my_grid.points[100, 1], c='r', s=1)
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.show()
예제 #5
0
# 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 equilateral triangular grid in 2 dims.
# The argument specified the number of cells along 1 dimension, hence total
# size of the grid is roughly the square of this number.
my_grid = TriangularGrid(21)
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 locations on the grid.
my_discrete_grf = DiscreteGRF.from_model(myGRF, my_grid)

# ------------------------------------------------------
# Sample and plot
# ------------------------------------------------------
# Sample all components at all locations.
sample = my_discrete_grf.sample()
plot_grid_values(my_grid, sample)

# ------------------------------------------------------
예제 #6
0
                              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
# ------------------------------------------------------
# Sample all components at all locations.
sample = my_discrete_grf.sample()
plot_grid_values(my_grid, sample)

# From now on, we will consider the drawn sample as ground truth.