The linear kernel. Functions drawn from a GP with this kernel are linear, i.e. f(x) = cx. The kernel equation is k(x, y) = σ²xy where σ² is the variance parameter.
| 23 | |
| 24 | |
| 25 | class Linear(Kernel): |
| 26 | """ |
| 27 | The linear kernel. Functions drawn from a GP with this kernel are linear, i.e. f(x) = cx. |
| 28 | The kernel equation is |
| 29 | |
| 30 | k(x, y) = σ²xy |
| 31 | |
| 32 | where σ² is the variance parameter. |
| 33 | """ |
| 34 | |
| 35 | @check_shapes( |
| 36 | "variance: [broadcast n_active_dims]", |
| 37 | ) |
| 38 | def __init__( |
| 39 | self, variance: TensorType = 1.0, active_dims: Optional[ActiveDims] = None |
| 40 | ) -> None: |
| 41 | """ |
| 42 | :param variance: the (initial) value for the variance parameter(s), |
| 43 | to induce ARD behaviour this must be initialised as an array the same |
| 44 | length as the the number of active dimensions e.g. [1., 1., 1.] |
| 45 | :param active_dims: a slice or list specifying which columns of X are used |
| 46 | """ |
| 47 | super().__init__(active_dims) |
| 48 | self.variance = Parameter(variance, transform=positive()) |
| 49 | self._validate_ard_active_dims(self.variance) |
| 50 | |
| 51 | @property |
| 52 | def ard(self) -> bool: |
| 53 | """ |
| 54 | Whether ARD behaviour is active. |
| 55 | """ |
| 56 | ndims: int = self.variance.shape.ndims |
| 57 | return ndims > 0 |
| 58 | |
| 59 | @inherit_check_shapes |
| 60 | def K(self, X: TensorType, X2: Optional[TensorType] = None) -> tf.Tensor: |
| 61 | if X2 is None: |
| 62 | return tf.matmul(X * self.variance, X, transpose_b=True) |
| 63 | else: |
| 64 | return tf.tensordot(X * self.variance, X2, [[-1], [-1]]) |
| 65 | |
| 66 | @inherit_check_shapes |
| 67 | def K_diag(self, X: TensorType) -> tf.Tensor: |
| 68 | return tf.reduce_sum(tf.square(X) * self.variance, axis=-1) |
| 69 | |
| 70 | |
| 71 | class Polynomial(Linear): |
no outgoing calls
searching dependent graphs…