The Polynomial kernel. Functions drawn from a GP with this kernel are polynomials of degree `d`. The kernel equation is k(x, y) = (σ²xy + γ)ᵈ where: σ² is the variance parameter, γ is the offset parameter, d is the degree parameter.
| 69 | |
| 70 | |
| 71 | class Polynomial(Linear): |
| 72 | """ |
| 73 | The Polynomial kernel. Functions drawn from a GP with this kernel are |
| 74 | polynomials of degree `d`. The kernel equation is |
| 75 | |
| 76 | k(x, y) = (σ²xy + γ)ᵈ |
| 77 | |
| 78 | where: |
| 79 | σ² is the variance parameter, |
| 80 | γ is the offset parameter, |
| 81 | d is the degree parameter. |
| 82 | """ |
| 83 | |
| 84 | @check_shapes( |
| 85 | "variance: [broadcast n_active_dims]", |
| 86 | ) |
| 87 | def __init__( |
| 88 | self, |
| 89 | degree: TensorType = 3.0, |
| 90 | variance: TensorType = 1.0, |
| 91 | offset: TensorType = 1.0, |
| 92 | active_dims: Optional[ActiveDims] = None, |
| 93 | ) -> None: |
| 94 | """ |
| 95 | :param degree: the degree of the polynomial |
| 96 | :param variance: the (initial) value for the variance parameter(s), |
| 97 | to induce ARD behaviour this must be initialised as an array the same |
| 98 | length as the the number of active dimensions e.g. [1., 1., 1.] |
| 99 | :param offset: the offset of the polynomial |
| 100 | :param active_dims: a slice or list specifying which columns of X are used |
| 101 | """ |
| 102 | super().__init__(variance, active_dims) |
| 103 | self.degree = degree |
| 104 | self.offset = Parameter(offset, transform=positive()) |
| 105 | |
| 106 | @inherit_check_shapes |
| 107 | def K(self, X: TensorType, X2: Optional[TensorType] = None) -> tf.Tensor: |
| 108 | return (super().K(X, X2) + self.offset) ** self.degree |
| 109 | |
| 110 | @inherit_check_shapes |
| 111 | def K_diag(self, X: TensorType) -> tf.Tensor: |
| 112 | return (super().K_diag(X) + self.offset) ** self.degree |
no outgoing calls
searching dependent graphs…