Skip to content

Commit

Permalink
Fix behaviour of s2=None. (#29)
Browse files Browse the repository at this point in the history
* fix: s2=None means noisyless case so keep it as None.

* fix: tests
1. reduce number of points in test_fitting for speedup.
2. fix test_convert_shapes.

* fix: typo

* fix: GaussianNoise.compute() when s2=None
  • Loading branch information
pipme authored Jun 2, 2023
1 parent 27bdd7b commit 6a4ba49
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gpyreg/gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ def _convert_shapes(
elif isinstance(s2, np.ndarray):
s2 = s2.reshape(N, 1)
elif s2 is None:
s2 = np.zeros((N, 1))
s2 = None # noiseless case
else:
raise TypeError(
"s2 type need to be \
Expand Down
2 changes: 2 additions & 0 deletions gpyreg/noise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def compute(
dsn2[:, i] = 2 * sn2
i += 1

if s2 is None:
s2 = 0
if self.parameters[1] == 1:
sn2 += s2
elif self.parameters[1] == 2:
Expand Down
8 changes: 2 additions & 6 deletions gpyreg/testing/test_gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def test_fitting_options():


def test_fitting():
N = 1000
N = 500
D = 1
X = np.reshape(np.linspace(-10, 10, N), (-1, 1))

Expand Down Expand Up @@ -1151,11 +1151,7 @@ def test_convert_shapes():
assert X.shape == (N, D) and y.shape == (N, 1) and s2.shape == (N, 1)
s2 = None
X, y, s2 = gp._convert_shapes(X, y, s2)
assert (
X.shape == (N, D)
and y.shape == (N, 1)
and np.allclose(s2, np.zeros((N, 1)))
)
assert X.shape == (N, D) and y.shape == (N, 1) and s2 is None
s2 = 1
X, y, s2 = gp._convert_shapes(X, y, s2)
assert (
Expand Down
2 changes: 1 addition & 1 deletion gpyreg/testing/test_gaussian_process_isotropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def test_fitting_options():


def test_fitting():
N = 1000
N = 500
D = 1
X = np.reshape(np.linspace(-10, 10, N), (-1, 1))

Expand Down

0 comments on commit 6a4ba49

Please sign in to comment.