Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9a7fa50

Browse files
add tests for ridge regression and new tests for NARXNN
1 parent 4a6e5b2 commit 9a7fa50

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

‎sysidentpy/model_structure_selection/forward_regression_orthogonal_least_squares.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class FROLS(Estimators, BaseMSS):
8686
filter.
8787
mu : float, default=0.01
8888
The convergence coefficient (learning rate) of the filter.
89-
eps : float
89+
eps : float, default=np.finfo(np.float64).eps
9090
Normalization factor of the normalized filters.
91-
ridge_param : float
91+
ridge_param : float, default=np.finfo(np.float64).eps
9292
Regularization parameter used in ridge regression
9393
gama : float, default=0.2
9494
The leakage factor of the Leaky LMS method.

‎sysidentpy/model_structure_selection/tests/test_frols.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_default_values():
9696
"offset_covariance": 0.2,
9797
"mu": 0.01,
9898
"eps": np.finfo(np.float64).eps,
99+
"ridge_param": np.finfo(np.float64).eps,
99100
"gama": 0.2,
100101
"weight": 0.02,
101102
"model_type": "NARMAX",
@@ -115,6 +116,7 @@ def test_default_values():
115116
model.offset_covariance,
116117
model.mu,
117118
model.eps,
119+
model.ridge_param,
118120
model.gama,
119121
model.weight,
120122
model.model_type,

‎sysidentpy/neural_network/tests/test_narxnn.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,30 @@ def forward(self, xb):
446446
assert_almost_equal(yhat.mean(), y_test.mean(), decimal=2)
447447

448448

449+
def test_raise_batch_size():
450+
assert_raises(
451+
ValueError, NARXNN, batch_size=0.3, basis_function=Polynomial(degree=2)
452+
)
453+
454+
455+
def test_raise_epochs():
456+
assert_raises(ValueError, NARXNN, epochs=0.3, basis_function=Polynomial(degree=2))
457+
458+
459+
def test_raise_train_percentage():
460+
assert_raises(
461+
ValueError, NARXNN, train_percentage=-1, basis_function=Polynomial(degree=2)
462+
)
463+
464+
465+
def test_raise_verbose():
466+
assert_raises(TypeError, NARXNN, verbose=None, basis_function=Polynomial(degree=2))
467+
468+
469+
def test_raise_device():
470+
assert_raises(ValueError, NARXNN, device="CPU", basis_function=Polynomial(degree=2))
471+
472+
449473
def test_model_predict_fourier():
450474
basis_function = Fourier(degree=1)
451475

‎sysidentpy/parameter_estimation/estimators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _validate_params(self):
5151
"offset_covariance": self.offset_covariance,
5252
"mu": self.mu,
5353
"eps": self.eps,
54-
"ridge_param": self.ridge_param,# for regularized ridge regression
54+
"ridge_param": self.ridge_param,
5555
"gama": self.gama,
5656
"weight": self.weight,
5757
}

‎sysidentpy/parameter_estimation/tests/test_estimators.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ def test_least_squares():
4242
assert_almost_equal(model.theta, theta, decimal=2)
4343

4444

45+
def test_ridge_regression():
46+
x, y, theta = create_test_data()
47+
basis_function = Polynomial(degree=2)
48+
model = FROLS(
49+
n_terms=5,
50+
extended_least_squares=False,
51+
ylag=[1, 2],
52+
xlag=2,
53+
estimator="ridge_regression",
54+
ridge_param=np.finfo(np.float64).eps,
55+
basis_function=basis_function,
56+
)
57+
model.fit(X=x, y=y)
58+
assert_almost_equal(model.theta, theta, decimal=2)
59+
60+
61+
def test_raise_ridge_regression():
62+
assert_raises(
63+
ValueError, Estimators, ridge_param=-0.3, basis_function=Polynomial(degree=2)
64+
)
65+
66+
67+
def test_raise():
68+
assert_raises(
69+
ValueError, Estimators, lam="0.97", basis_function=Polynomial(degree=2)
70+
)
71+
72+
73+
def test_lam_raise():
74+
assert_raises(ValueError, Estimators, lam=1.01, basis_function=Polynomial(degree=2))
75+
76+
4577
def test_total_least_squares():
4678
x, y, theta = create_test_data()
4779
model = FROLS(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /