Skip to content

svgp_model

SVGP

Bases: gpytorch.models.ApproximateGP

Stochastic Variational Gaussian Process (SVGP) Regression Model.

A scalable Gaussian Process (GP) model based on stochastic variational inference. Inherits from the gpytorch.models.ApproximateGP class.

Parameters:

Name Type Description Default
inducing_points torch.Tensor

Inducing points tensor.

required
dtype torch.dtype

Data type of the model. Defaults to torch.float32.

torch.float32
device torch.device

Device can be specified to the desired cpu or cuda for GPU

None

Attributes:

Name Type Description
mean_module gpytorch.means.ConstantMean

Constant mean module.

covar_module gpytorch.kernels.ScaleKernel

Scaled RBF kernel.

Source code in uncertaintyplayground/models/svgp_model.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class SVGP(gpytorch.models.ApproximateGP):
    """
    Stochastic Variational Gaussian Process (SVGP) Regression Model.

    A scalable Gaussian Process (GP) model based on stochastic variational inference.
    Inherits from the gpytorch.models.ApproximateGP class.

    Args:
        inducing_points (torch.Tensor): Inducing points tensor.
        dtype (torch.dtype, optional): Data type of the model. Defaults to torch.float32.
        device (torch.device): Device can be specified to the desired `cpu` or `cuda` for GPU

    Attributes:
        mean_module (gpytorch.means.ConstantMean): Constant mean module.
        covar_module (gpytorch.kernels.ScaleKernel): Scaled RBF kernel.
    """

    def __init__(self, inducing_points, dtype=torch.float32, device = None):
        self.device = device
        self.inducing_points = inducing_points.to(device = self.device)
        variational_distribution = gpytorch.variational.CholeskyVariationalDistribution(
            self.inducing_points.size(0), dtype=dtype
        )
        variational_strategy = gpytorch.variational.VariationalStrategy(
            self,
            self.inducing_points,
            variational_distribution,
            learn_inducing_locations=True
        ).to(dtype = dtype)

        super().__init__(variational_strategy)
        self.mean_module = gpytorch.means.ConstantMean(dtype=dtype)
        self.covar_module = gpytorch.kernels.ScaleKernel(
            gpytorch.kernels.RBFKernel())

    def forward(self, x):
        """
        Forward pass for the SVGPRegressionModel.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            gpytorch.distributions.MultivariateNormal: Multivariate normal distribution with the given mean and covariance.
        """
        x = x.to(device = self.device)
        mean_x = self.mean_module(x)
        covar_x = self.covar_module(x)
        return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)

forward(x)

Forward pass for the SVGPRegressionModel.

Parameters:

Name Type Description Default
x torch.Tensor

Input tensor.

required

Returns:

Type Description

gpytorch.distributions.MultivariateNormal: Multivariate normal distribution with the given mean and covariance.

Source code in uncertaintyplayground/models/svgp_model.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def forward(self, x):
    """
    Forward pass for the SVGPRegressionModel.

    Args:
        x (torch.Tensor): Input tensor.

    Returns:
        gpytorch.distributions.MultivariateNormal: Multivariate normal distribution with the given mean and covariance.
    """
    x = x.to(device = self.device)
    mean_x = self.mean_module(x)
    covar_x = self.covar_module(x)
    return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)