Skip to content

Commit

Permalink
Small changes (docstring mistake and unit test improvement)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uri Granta committed Sep 24, 2024
1 parent 4b100d6 commit 95ed3a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions gpflux/layers/basis_functions/fourier_features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def call(self, inputs: TensorType) -> tf.Tensor:
:param inputs: The evaluation points, a tensor with the shape ``[N, D]``.
:return: A tensor with the shape ``[N, M]``, or shape ``[P, N, M]'' in the batched case.
:return: A tensor with the shape ``[N, M]``, or shape ``[P, N, M]'' in the multioutput case.
"""
if self.is_batched:
X = [tf.divide(inputs, k.lengthscales) for k in self.sub_kernels]
Expand All @@ -82,9 +82,9 @@ def call(self, inputs: TensorType) -> tf.Tensor:
bases = self._compute_bases(X) # [N, M] or [P, N, M]
output = const * bases

# For combination kernels, remove batch dimension and instead concatenate into the
# feature dimension.
if self.is_batched and not self.is_multioutput:
# For combination kernels, remove batch dimension and instead concatenate into the
# feature dimension.
output = tf.transpose(output, perm=[1, 2, 0]) # [N, M, P]
output = tf.reshape(output, [tf.shape(output)[0], -1]) # [N, M*P]

Expand Down
8 changes: 4 additions & 4 deletions gpflux/layers/basis_functions/fourier_features/random/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ class RandomFourierFeatures(RandomFourierFeaturesBase):
"""

def compute_output_dim(self, input_shape: ShapeType) -> int:
# For combination kernels, the number of features is multiplied by the number of
# sub-kernels.
dim = 2 * self.n_components
if self.is_batched and not self.is_multioutput:
# For combination kernels, the number of features is multiplied by the number of
# sub-kernels.
dim *= self.batch_size
return dim

Expand Down Expand Up @@ -287,10 +287,10 @@ def _bias_init(self, shape: TensorType, dtype: Optional[DType] = None) -> Tensor
return tf.random.uniform(shape=shape, maxval=2.0 * np.pi, dtype=dtype)

def compute_output_dim(self, input_shape: ShapeType) -> int:
# For combination kernels, the number of features is multiplied by the number of
# sub-kernels.
dim = self.n_components
if self.is_batched and not self.is_multioutput:
# For combination kernels, the number of features is multiplied by the number of
# sub-kernels.
dim *= self.batch_size
return dim

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def _kernel_cls_fixture(request):
gpflow.kernels.Matern32(lengthscales=0.1),
]
),
gpflow.kernels.Sum([gpflow.kernels.SquaredExponential(), gpflow.kernels.Matern52()]),
gpflow.kernels.Sum(
[
gpflow.kernels.SquaredExponential(),
gpflow.kernels.Matern32(),
gpflow.kernels.Matern52(),
]
),
],
)
def _multi_kernel_cls_fixture(request):
Expand Down

0 comments on commit 95ed3a8

Please sign in to comment.