Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, inducing_points):
variational_distribution = CholeskyVariationalDistribution(
inducing_points.size(-2), batch_shape=torch.Size([2])
)
variational_strategy = VariationalStrategy(
self, inducing_points, variational_distribution, learn_inducing_locations=True
)
super(SVGPRegressionModel, self).__init__(variational_strategy)
self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = gpytorch.kernels.ScaleKernel(
gpytorch.kernels.RBFKernel(lengthscale_prior=gpytorch.priors.SmoothedBoxPrior(0.001, 1.0, sigma=0.1))
)
self.assertEqual(AddK.base_kernel.lengthscale.numel(), 3)
self.assertEqual(AddK.outputscale.numel(), 3)
testvals = torch.tensor([[1, 2, 3], [7, 5, 2]], dtype=torch.float)
add_k_val = AddK(testvals, testvals).evaluate()
manual_k1 = ScaleKernel(
AdditiveKernel(RBFKernel(active_dims=0), RBFKernel(active_dims=1), RBFKernel(active_dims=2))
)
manual_k1.initialize(outputscale=1 / 3)
manual_k2 = ScaleKernel(
AdditiveKernel(RBFKernel(active_dims=[0, 1]), RBFKernel(active_dims=[1, 2]), RBFKernel(active_dims=[0, 2]))
)
manual_k2.initialize(outputscale=1 / 3)
manual_k3 = ScaleKernel(AdditiveKernel(RBFKernel()))
manual_k3.initialize(outputscale=1 / 3)
manual_k = AdditiveKernel(manual_k1, manual_k2, manual_k3)
manual_add_k_val = manual_k(testvals, testvals).evaluate()
# np.testing.assert_allclose(add_k_val.detach().numpy(), manual_add_k_val.detach().numpy(), atol=1e-5)
self.assertTrue(torch.allclose(add_k_val, manual_add_k_val, atol=1e-5))
def __init__(self, train_x, train_y, likelihood):
super(GPRegressionModel, self).__init__(train_x, train_y, likelihood)
self.mean_module = ZeroMean()
self.base_covar_module = ScaleKernel(RBFKernel())
self.covar_module = AdditiveStructureKernel(
GridInterpolationKernel(self.base_covar_module, grid_size=100, num_dims=1), num_dims=2
)
def __init__(self, train_inputs, train_targets, likelihood, batch_shape=torch.Size()):
super(ExactGPModel, self).__init__(train_inputs, train_targets, likelihood)
self.mean_module = ConstantMean(batch_shape=batch_shape, prior=gpytorch.priors.SmoothedBoxPrior(-1, 1))
self.covar_module = ScaleKernel(
RBFKernel(
batch_shape=batch_shape,
lengthscale_prior=gpytorch.priors.NormalPrior(
loc=torch.zeros(*batch_shape, 1, 1), scale=torch.ones(*batch_shape, 1, 1)
),
),
batch_shape=batch_shape,
outputscale_prior=gpytorch.priors.SmoothedBoxPrior(-2, 2),
)
def __init__(self, inducing_points):
variational_distribution = CholeskyVariationalDistribution(
inducing_points.size(-2), batch_shape=torch.Size([2]),
)
variational_strategy = WhitenedVariationalStrategy(
self, inducing_points, variational_distribution, learn_inducing_locations=True
)
super(SVGPRegressionModel, self).__init__(variational_strategy)
self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = gpytorch.kernels.ScaleKernel(
gpytorch.kernels.RBFKernel(lengthscale_prior=gpytorch.priors.SmoothedBoxPrior(0.001, 1.0, sigma=0.1))
)
def kernel(self, kernel):
r"""Set the kernel function :math:`K(.,.)` (=prior covariance of the GP)."""
if kernel is None:
kernel = gpytorch.kernels.RBFKernel() # + gpytorch.kernels.WhiteNoiseKernel()
kernel = gpytorch.kernels.ScaleKernel(kernel)
if not isinstance(kernel, gpytorch.kernels.Kernel):
raise TypeError("Expecting the kernel to be an instance of `gpytorch.kernels.Kernel`, got instead "
"{}".format(type(kernel)))
self._kernel = kernel
raise ValueError(f"Unsupported shape {train_X.shape} for train_X.")
# Set up noise model
train_y_log_var = (
2 * train_Y_se.log() + phi_func(train_phi.view_as(train_Y_se)).log()
)
noise_model = SingleTaskGP(train_X=train_x, train_Y=train_y_log_var)
noise_covar = FidelityAwareHeteroskedasticNoise(
noise_model=noise_model, x_idxr=x_idxr, phi_idxr=phi_idxr, phi_func=phi_func
)
likelihood = _GaussianLikelihoodBase(noise_covar)
super().__init__(
train_inputs=train_X, train_targets=train_Y, likelihood=likelihood
)
self.mean_module = ConstantMean(batch_size=batch_size)
self.covar_module = ScaleKernel(
base_kernel=MaternKernel(
nu=2.5,
ard_num_dims=ard_num_dims,
lengthscale_prior=GammaPrior(3.0, 6.0),
param_transform=softplus,
),
batch_size=batch_size,
param_transform=softplus,
outputscale_prior=GammaPrior(2.0, 0.15),
)