Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect docstrings for kernel functions #253

Open
thawes-rse opened this issue Jan 27, 2024 · 0 comments
Open

Incorrect docstrings for kernel functions #253

thawes-rse opened this issue Jan 27, 2024 · 0 comments

Comments

@thawes-rse
Copy link

thawes-rse commented Jan 27, 2024

Summary

This issue relates to the docstring of the kernel_f method in mogp_emulator.Kernel.KernelBase. The docstring says the params argument should be "1-D with length one greater than the last dimension of x1 and x2". This does not appear to match the current implementation, which I think expects params to be a 1-dim Numpy array with length equal to the last dimensions of x1 and x2.

Aside from this, the documentation should make clear what these params refer to mathematically. Having looked at the implementation of SquaredExponential, I think these are meant to be the 'raw' version of the correlation length scale parameters (as outlined in the docstring for GPParams), although it would be good to get a package maintainer to confirm this. This would also seem to indicate that the kernels assume that the covariance is equal to 1 (again using the terminology of the docstring for GPParams). If true, this again needs to be made clear in the documentation, because it differs from other mathematical treatments of kernel functions (see e.g. https://uk.mathworks.com/help/stats/kernel-covariance-function-options.html).

Versions used

Python 3.9.18
mogp-emulator 0.7.2
numpy 1.26.3
scipy 1.11.4
patsy 0.5.6

Reproducible example of error

We consider only SquaredExponential and Matern52 below, but similar problems arise for the other named kernels, ProductMat52, UniformSqExp and UniformMat52.

>>> import numpy as np
>>> from mogp_emulator.Kernel import Matern52, SquaredExponential
>>> x1 = np.random.random(3)
>>> x2 = np.random.random(3)
>>> params = np.array([1, 2, 3, 4])  # len = x1.shape[-1] + 1 = x2.shape[-1] + 1, as per documentation for kernel_f
>>> Matern52().kernel_f(x1, x2, params)
>>> SquaredExponential().kernel_f(x1, x2, params)

Expected behaviour

The expressions Matern52().kernel_f(x1, x2, params) and SquaredExponential().kernel_f(x1, x2, params) evaluate to a single-element Numpy array of shape (1, 1).

Actual behaviour

>>> Matern52().kernel_f(x1, x2, params)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path/to/lib/python3.9/site-packages/mogp_emulator/Kernel.py", line 129, in kernel_f
    x1, n1, x2, n2, params, D = self._check_inputs(x1, x2, params)
  File "path/to/lib/python3.9/site-packages/mogp_emulator/Kernel.py", line 79, in _check_inputs
    x1 = np.reshape(x1, (1, D))
  File "path/to/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 285, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "path/to/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 3 into shape (1,4)
>>> SquaredExponential().kernel_f(x1, x2, params)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path/to/lib/python3.9/site-packages/mogp_emulator/Kernel.py", line 129, in kernel_f
    x1, n1, x2, n2, params, D = self._check_inputs(x1, x2, params)
  File "path/to/lib/python3.9/site-packages/mogp_emulator/Kernel.py", line 79, in _check_inputs
    x1 = np.reshape(x1, (1, D))
  File "path/to/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 285, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "path/to/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 3 into shape (1,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant