A quadratic mean function supplies a Gaussian process with an expected objective shape that follows ax² + bx + c. Unlike a linear mean, it allows the predicted response to change faster as the input grows. In a housing example, this expresses prices increasing faster for larger living areas. section 3.2 section 3.3.4
A custom quadratic mean function contains:
- A second-order coefficient for x². section 3.3.4
- A first-order coefficient for x. section 3.3.4
- An optional bias for the constant term. section 3.3.4
- Registered torch.nn.Parameter values that can be trained through gradient descent. section 3.3.4
In GPyTorch, QuadraticMean extends gpytorch.means.Mean. Its __init__() method registers the coefficients, while forward() computes the polynomial for each input. Pairing it with a covariance function lets the GP combine this prior shape with observed data. section 3.3.4 section 3.2
class QuadraticMean(gpytorch.means.Mean):
def __init__(self, batch_shape=torch.Size(), bias=True):
super().__init__()
self.register_parameter(
name="second",
parameter=torch.nn.Parameter(torch.randn(*batch_shape, 1, 1))
) #1
self.register_parameter(
name="first",
parameter=torch.nn.Parameter(torch.randn(*batch_shape, 1, 1))
) #2
if bias:
self.register_parameter(
name="bias",
parameter=torch.nn.Parameter(torch.randn(*batch_shape, 1))
) #3
else:
self.bias = None
Inspect the parameter-registration implementation for the second-order coefficient, first-order coefficient, and optional bias. section 3.3.4
Figure 3.10 Predictions by a GP with a quadratic mean function. This GP predicts that with a larger living area, the price increases at a faster rate.
View the resulting GP behavior: predicted prices rise at an increasing rate as living area grows. section 3.3.4
