-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
91 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import numpy as np | ||
|
||
from ezyrb import (GPR, Linear, RBF, ANN, KNeighborsRegressor, | ||
RadiusNeighborsRegressor) | ||
import sklearn | ||
import pytest | ||
|
||
import torch.nn as nn | ||
np.random.seed(17) | ||
|
||
def get_xy(): | ||
npts = 10 | ||
dinput = 4 | ||
|
||
inp = np.random.uniform(-1, 1, size=(npts, dinput)) | ||
out = np.array([ | ||
np.sin(inp[:, 0]) + np.sin(inp[:, 1]**2), | ||
np.cos(inp[:, 2]) + np.cos(inp[:, 3]**2) | ||
]).T | ||
|
||
return inp, out | ||
|
||
@pytest.mark.parametrize("model,kwargs", [ | ||
(GPR, {}), | ||
(ANN, {'layers': [20, 20], 'function': nn.Tanh(), 'stop_training': 1e-8, 'last_identity': True}), | ||
(KNeighborsRegressor, {'n_neighbors': 1}), | ||
(RadiusNeighborsRegressor, {'radius': 0.1}), | ||
(Linear, {}), | ||
]) | ||
class TestApproximation: | ||
def test_constructor_empty(self, model, kwargs): | ||
model = model(**kwargs) | ||
|
||
def test_fit(self, model, kwargs): | ||
x, y = get_xy() | ||
approx = model(**kwargs) | ||
approx.fit(x[:, 0].reshape(-1, 1), y[:, 0].reshape(-1, 1)) | ||
|
||
approx = model(**kwargs) | ||
approx.fit(x, y) | ||
|
||
def test_predict_01(self, model, kwargs): | ||
x, y = get_xy() | ||
approx = model(**kwargs) | ||
approx.fit(x, y) | ||
test_y = approx.predict(x) | ||
if isinstance(approx, ANN): | ||
np.testing.assert_array_almost_equal(y, test_y, decimal=3) | ||
else: | ||
np.testing.assert_array_almost_equal(y, test_y, decimal=6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters