liveBook · Manning

Quadratic mean function

As explained in Bayesian Optimization in Action

A quadratic mean function maps an input to an expected value represented by a second-degree polynomial with learned coefficients.

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:

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

How Bayesian Optimization in Action covers it

How deep it goes
Defines the polynomial and implements parameter registration and forward evaluation, but does not develop broader GP inference internals.
Examples
Uses housing living area and price, a quadratic-versus-linear comparison, and a custom QuadraticMean implementation.
What it assumes
Assumes Gaussian-process mean and covariance roles, while teaching quadratic coefficients and parameter registration through implementation.
What you can do after
Build it from scratch in GPyTorch by registering polynomial parameters and evaluating the quadratic mean in forward().
How it connects
Connects Gaussian processes, covariance functions, hyperparameters, PyTorch parameters, and gradient descent.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bayesian Optimization in Action. The section links point to the parts of the book it draws on.