Skip to content

Commit d096c6a

Browse files
yalsaffarfacebook-github-bot
authored andcommitted
Enhance Docstrings in aepsych/kernels (facebookresearch#427)
Summary: One of several PRs addressing issue facebookresearch#366 to improve docstring coverage. Improves documentation in `aepsych/kernels` for better clarity and consistency. - Adds missing docstrings to functions and methods across kernel modules. - Updates existing docstrings with refined type hints and a unified structure. Pull Request resolved: facebookresearch#427 Reviewed By: crasanders Differential Revision: D65827615 Pulled By: JasonKChow fbshipit-source-id: 76673b5810cc2560853c8a6d6767d0baade694a2
1 parent 851d38f commit d096c6a

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

aepsych/kernels/pairwisekernel.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ class PairwiseKernel(Kernel):
1616
"""
1717

1818
def __init__(
19-
self, latent_kernel: Any, is_partial_obs: bool = False, **kwargs
19+
self, latent_kernel: Kernel, is_partial_obs: bool=False, **kwargs
2020
) -> None:
21+
"""
22+
Args:
23+
latent_kernel (Kernel): The underlying kernel used to compute the covariance for the GP.
24+
is_partial_obs (bool): If the kernel should handle partial observations. Defaults to False.
25+
"""
2126
super(PairwiseKernel, self).__init__(**kwargs)
2227

2328
self.latent_kernel = latent_kernel
@@ -30,20 +35,20 @@ def forward(
3035
TODO: make last_batch_dim work properly
3136
3237
d must be 2*k for integer k, k is the dimension of the latent space
38+
3339
Args:
34-
:attr:`x1` (Tensor `n x d` or `b x n x d`):
35-
First set of data
36-
:attr:`x2` (Tensor `m x d` or `b x m x d`):
37-
Second set of data
38-
:attr:`diag` (bool):
39-
Should the Kernel compute the whole kernel, or just the diag?
40+
x1 (torch.Tensor): A `b x n x d` or `n x d` tensor, where `d = 2k` and `k` is the dimension of the latent space.
41+
x2 (torch.Tensor): A `b x m x d` or `m x d` tensor, where `d = 2k` and `k` is the dimension of the latent space.
42+
diag (bool): Should the Kernel compute the whole covariance matrix or just the diagonal? Defaults to False.
43+
4044
4145
Returns:
42-
:class:`Tensor` or :class:`gpytorch.lazy.LazyTensor`.
43-
The exact size depends on the kernel's evaluation mode:
46+
torch.Tensor (or :class:`gpytorch.lazy.LazyTensor`) : A `b x n x m` or `n x m` tensor representing
47+
the covariance matrix between `x1` and `x2`.
48+
The exact size depends on the kernel's evaluation mode:
49+
* `full_covar`: `n x m` or `b x n x m`
50+
* `diag`: `n` or `b x n`
4451
45-
* `full_covar`: `n x m` or `b x n x m`
46-
* `diag`: `n` or `b x n`
4752
"""
4853
if self.is_partial_obs:
4954
d: Union[torch.Tensor, int] = x1.shape[-1] - 1

aepsych/kernels/rbf_partial_grad.py

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ class RBFKernelPartialObsGrad(RBFKernelGrad):
3030
def forward(
3131
self, x1: torch.Tensor, x2: torch.Tensor, diag: bool = False, **params: Any
3232
) -> torch.Tensor:
33+
"""Computes the covariance matrix between x1 and x2 based on the RBF
34+
35+
Args:
36+
x1 (torch.Tensor): A `b x n x d` or `n x d` tensor, where `d = 2k` and `k` is the dimension of the latent space.
37+
x2 (torch.Tensor): A `b x m x d` or `m x d` tensor, where `d = 2k` and `k` is the dimension of the latent space.
38+
diag (bool): Should the Kernel compute the whole covariance matrix (False) or just the diagonal (True)? Defaults to False.
39+
40+
41+
42+
Returns:
43+
torch.Tensor: A `b x n x m` or `n x m` tensor representing the covariance matrix between `x1` and `x2`.
44+
The exact size depends on the kernel's evaluation mode:
45+
* `full_covar`: `n x m` or `b x n x m`
46+
* `diag`: `n` or `b x n`
47+
"""
3348
# Extract grad index from each
3449
grad_idx1 = x1[..., -1].to(dtype=torch.long)
3550
grad_idx2 = x2[..., -1].to(dtype=torch.long)

0 commit comments

Comments
 (0)