Source code for spateo.tdr.interpolations.interpolation_gaussianprocess.gp_models
import gpytorch
from gpytorch.models import ApproximateGP, ExactGP
from gpytorch.variational import CholeskyVariationalDistribution, VariationalStrategy
[docs]class Approx_GPModel(ApproximateGP):
def __init__(self, inducing_points):
[docs] variational_distribution = CholeskyVariationalDistribution(inducing_points.size(0))
[docs] variational_strategy = VariationalStrategy(
self, inducing_points, variational_distribution, learn_inducing_locations=True
)
super(Approx_GPModel, self).__init__(variational_strategy)
[docs] self.mean_module = gpytorch.means.ConstantMean()
[docs] self.covar_module = gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel())
[docs] def forward(self, x):
mean_x = self.mean_module(x)
covar_x = self.covar_module(x)
return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)
[docs]class Exact_GPModel(ExactGP):
def __init__(self, train_x, train_y, likelihood):
super().__init__(train_x, train_y, likelihood)
[docs] self.mean_module = gpytorch.means.ZeroMean()
[docs] self.covar_module = gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel())
[docs] def forward(self, x):
mean_x = self.mean_module(x)
covar_x = self.covar_module(x)
return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)