Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jungtaekkim committed Nov 15, 2024
1 parent e6567ac commit a7e2ded
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
25 changes: 21 additions & 4 deletions tests/common/test_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def test_cov_se():
package_target.cov_se(
np.zeros((1, 2)), np.zeros((1, 2)), np.array([1.0, 1.0]), 1
)
np.testing.assert_allclose(package_target.cov_se(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0], 0.01)
np.testing.assert_allclose(
package_target.cov_se(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0], 0.01
)

X = np.array([[1.0, 2.0, 0.0]])
Xp = np.array([[2.0, 1.0, 1.0]])
Expand Down Expand Up @@ -350,7 +352,10 @@ def test_cov_matern32():
package_target.cov_matern32(
np.zeros((1, 2)), np.zeros((1, 2)), np.array([1.0, 1.0]), 1
)
np.testing.assert_allclose(package_target.cov_matern32(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0], 0.01)
np.testing.assert_allclose(
package_target.cov_matern32(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0],
0.01,
)

X = np.array([[1.0, 2.0, 0.0]])
Xp = np.array([[2.0, 1.0, 1.0]])
Expand Down Expand Up @@ -478,7 +483,10 @@ def test_cov_matern52():
package_target.cov_matern52(
np.zeros((1, 2)), np.zeros((1, 2)), np.array([1.0, 1.0]), 1
)
np.testing.assert_allclose(package_target.cov_matern52(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0], 0.01)
np.testing.assert_allclose(
package_target.cov_matern52(np.zeros((1, 2)), np.zeros((1, 2)), 1.0, 0.1)[0, 0],
0.01,
)

X = np.array([[1.0, 2.0, 0.0]])
Xp = np.array([[2.0, 1.0, 1.0]])
Expand Down Expand Up @@ -642,7 +650,16 @@ def test_cov_set():
np.array([1.0, 1.0, 1.0]),
1,
)
np.testing.assert_allclose(package_target.cov_set(str_cov, np.zeros((num_instances, num_dim)), np.zeros((num_instances, num_dim)), 1.0, 0.1), 0.01)
np.testing.assert_allclose(
package_target.cov_set(
str_cov,
np.zeros((num_instances, num_dim)),
np.zeros((num_instances, num_dim)),
1.0,
0.1,
),
0.01,
)

bx = np.array([[1.0, 2.0, 0.0], [2.0, 1.0, 0.0]])
bxp = np.array([[2.0, 1.0, 1.0], [2.0, 2.0, 2.0]])
Expand Down
11 changes: 3 additions & 8 deletions tests/common/test_gp_gp.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: March 22, 2021
# author: Jungtaek Kim ([email protected])
# last updated: November 15, 2024
#
"""test_gp"""
"""test_gp_gp"""

import typing
import pytest
import numpy as np

from bayeso import constants
from bayeso.gp import gp as package_target
from bayeso.gp import gp_kernel
from bayeso.utils import utils_covariance


TEST_EPSILON = 1e-7


def test_sample_functions_typing():
Expand Down
40 changes: 30 additions & 10 deletions tests/common/test_trees_trees_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,34 +345,54 @@ def test__split():
assert dict_split["value"] == 35.0

assert np.all(dict_split["left_right"][0][0][0] == np.array([0, 1, 2, 3]))
np.testing.assert_allclose(dict_split["left_right"][0][0][1], np.array([0.49671415]))
np.testing.assert_allclose(
dict_split["left_right"][0][0][1], np.array([0.49671415])
)

assert np.all(dict_split["left_right"][0][1][0] == np.array([4, 5, 6, 7]))
np.testing.assert_allclose(dict_split["left_right"][0][1][1], np.array([-0.1382643]))
np.testing.assert_allclose(
dict_split["left_right"][0][1][1], np.array([-0.1382643])
)

assert np.all(dict_split["left_right"][0][2][0] == np.array([8, 9, 10, 11]))
np.testing.assert_allclose(dict_split["left_right"][0][2][1], np.array([0.64768854]))
np.testing.assert_allclose(
dict_split["left_right"][0][2][1], np.array([0.64768854])
)

assert np.all(dict_split["left_right"][0][3][0] == np.array([12, 13, 14, 15]))
np.testing.assert_allclose(dict_split["left_right"][0][3][1], np.array([1.52302986]))
np.testing.assert_allclose(
dict_split["left_right"][0][3][1], np.array([1.52302986])
)

assert np.all(dict_split["left_right"][0][4][0] == np.array([16, 17, 18, 19]))
np.testing.assert_allclose(dict_split["left_right"][0][4][1], np.array([-0.23415337]))
np.testing.assert_allclose(
dict_split["left_right"][0][4][1], np.array([-0.23415337])
)

assert np.all(dict_split["left_right"][0][5][0] == np.array([20, 21, 22, 23]))
np.testing.assert_allclose(dict_split["left_right"][0][5][1], np.array([-0.23413696]))
np.testing.assert_allclose(
dict_split["left_right"][0][5][1], np.array([-0.23413696])
)

assert np.all(dict_split["left_right"][0][6][0] == np.array([24, 25, 26, 27]))
np.testing.assert_allclose(dict_split["left_right"][0][6][1], np.array([1.57921282]))
np.testing.assert_allclose(
dict_split["left_right"][0][6][1], np.array([1.57921282])
)

assert np.all(dict_split["left_right"][0][7][0] == np.array([28, 29, 30, 31]))
np.testing.assert_allclose(dict_split["left_right"][0][7][1], np.array([0.76743473]))
np.testing.assert_allclose(
dict_split["left_right"][0][7][1], np.array([0.76743473])
)

assert np.all(dict_split["left_right"][0][8][0] == np.array([32, 33, 34, 35]))
np.testing.assert_allclose(dict_split["left_right"][0][8][1], np.array([-0.46947439]))
np.testing.assert_allclose(
dict_split["left_right"][0][8][1], np.array([-0.46947439])
)

assert np.all(dict_split["left_right"][1][0][0] == np.array([36, 37, 38, 39]))
np.testing.assert_allclose(dict_split["left_right"][1][0][1], np.array([0.54256004]))
np.testing.assert_allclose(
dict_split["left_right"][1][0][1], np.array([0.54256004])
)

dict_split = package_target._split(X, Y, num_features, True)
print(dict_split)
Expand Down

0 comments on commit a7e2ded

Please sign in to comment.