11"""
2- Unit tests for SensorSelector class (and any other classes implemented
2+ Unit tests for SSPOR class (and any other classes implemented
33in pysensors.py).
44
55Note: all tests should be encapsulated in functions whose
2121from sklearn .exceptions import NotFittedError
2222from sklearn .utils .validation import check_is_fitted
2323
24- from pysensors import SensorSelector
2524from pysensors .basis import Identity
2625from pysensors .basis import RandomProjection
2726from pysensors .basis import SVD
2827from pysensors .optimizers import CCQR
28+ from pysensors .reconstruction import SSPOR
2929
3030
3131def test_not_fitted (data_vandermonde ):
3232 x = data_vandermonde
33- model = SensorSelector ()
33+ model = SSPOR ()
3434
3535 # Should not be able to call any of these methods before fitting
3636 with pytest .raises (NotFittedError ):
@@ -51,7 +51,7 @@ def test_set_number_of_sensors(data_vandermonde):
5151 x = data_vandermonde
5252 max_sensors = x .shape [1 ]
5353
54- model = SensorSelector ()
54+ model = SSPOR ()
5555 model .fit (x )
5656
5757 with pytest .raises (ValueError ):
@@ -75,7 +75,7 @@ def test_get_all_sensors(data):
7575 x = data
7676 max_sensors = x .shape [1 ]
7777
78- model = SensorSelector ()
78+ model = SSPOR ()
7979 model .fit (x )
8080 assert len (model .get_all_sensors ()) == max_sensors
8181
@@ -85,7 +85,7 @@ def test_get_all_sensors(data):
8585)
8686def test_basis_compatibility (data_vandermonde , basis ):
8787 x = data_vandermonde
88- model = SensorSelector (basis = basis )
88+ model = SSPOR (basis = basis )
8989 model .fit (x )
9090 check_is_fitted (model )
9191
@@ -94,17 +94,17 @@ def test_n_sensors(data_random):
9494
9595 # Check for bad inputs
9696 with pytest .raises (ValueError ):
97- model = SensorSelector (n_sensors = 0 )
97+ model = SSPOR (n_sensors = 0 )
9898 with pytest .raises (ValueError ):
99- model = SensorSelector (n_sensors = 5.4 )
99+ model = SSPOR (n_sensors = 5.4 )
100100 with pytest .raises (ValueError ):
101- model = SensorSelector (n_sensors = "1" )
101+ model = SSPOR (n_sensors = "1" )
102102 with pytest .raises (ValueError ):
103- model = SensorSelector (n_sensors = [1 ])
103+ model = SSPOR (n_sensors = [1 ])
104104
105105 n_sensors = 5
106106 x = data_random
107- model = SensorSelector (n_sensors = n_sensors )
107+ model = SSPOR (n_sensors = n_sensors )
108108 model .fit (x )
109109
110110 assert len (model .get_selected_sensors ()) == n_sensors
@@ -114,7 +114,7 @@ def test_predict(data_random):
114114 data = data_random
115115
116116 n_sensors = 5
117- model = SensorSelector (n_sensors = n_sensors )
117+ model = SSPOR (n_sensors = n_sensors )
118118 model .fit (data )
119119
120120 # Wrong size input for predict
@@ -130,7 +130,7 @@ def test_predict(data_random):
130130def test_square_predict (data_random_square ):
131131 data = data_random_square
132132
133- model = SensorSelector ()
133+ model = SSPOR ()
134134 model .fit (data )
135135 sensors = model .get_selected_sensors ()
136136 assert data .shape == model .predict (data [:, sensors ]).shape
@@ -140,7 +140,7 @@ def test_predict_accuracy(data_vandermonde_testing):
140140 # Polynomials up to degree 10 on [0, 1]
141141 data , x_test = data_vandermonde_testing
142142
143- model = SensorSelector ()
143+ model = SSPOR ()
144144 model .fit (data , seed = 1 )
145145 model .set_number_of_sensors (8 )
146146 sensors = model .get_selected_sensors ()
@@ -154,7 +154,7 @@ def test_predict_accuracy(data_vandermonde_testing):
154154def test_reconstruction_error (data_vandermonde_testing ):
155155 data , x_test = data_vandermonde_testing
156156
157- model = SensorSelector (n_sensors = 3 )
157+ model = SSPOR (n_sensors = 3 )
158158 model .fit (data )
159159
160160 assert len (model .reconstruction_error (x_test )) == min (
@@ -168,14 +168,14 @@ def test_reconstruction_error(data_vandermonde_testing):
168168def test_score (data_vandermonde ):
169169 data = data_vandermonde
170170
171- weak_model = SensorSelector (n_sensors = 3 )
171+ weak_model = SSPOR (n_sensors = 3 )
172172 weak_model .fit (data )
173173
174174 # You must pass in data with as many features as the training set
175175 with pytest .raises (ValueError ):
176176 weak_model .score (data [:, :5 ])
177177
178- strong_model = SensorSelector (n_sensors = 8 )
178+ strong_model = SSPOR (n_sensors = 8 )
179179 strong_model .fit (data )
180180
181181 assert weak_model .score (data ) < strong_model .score (data )
@@ -189,15 +189,15 @@ def test_prefit_basis(data_random):
189189 # This data should be ignored during the fit
190190 data_to_ignore = nan * data_random
191191
192- model = SensorSelector (basis = basis )
192+ model = SSPOR (basis = basis )
193193 model .fit (data_to_ignore , prefit_basis = True )
194194 assert not any (isnan (model .get_selected_sensors ()))
195195
196196
197197def test_update_n_basis_modes_errors (data_random ):
198198 data = data_random
199199 n_basis_modes = 5
200- model = SensorSelector (basis = Identity (n_basis_modes = n_basis_modes ))
200+ model = SSPOR (basis = Identity (n_basis_modes = n_basis_modes ))
201201
202202 model .fit (data )
203203
@@ -215,7 +215,7 @@ def test_update_n_basis_modes_errors(data_random):
215215
216216def test_update_n_basis_modes (data_random ):
217217 data = data_random
218- model = SensorSelector ()
218+ model = SSPOR ()
219219 model .fit (data )
220220 assert model .basis .n_basis_modes == data .shape [0 ]
221221 assert model .basis_matrix_ .shape [1 ] == data .shape [0 ]
@@ -229,7 +229,7 @@ def test_update_n_basis_modes(data_random):
229229def test_update_n_basis_modes_refit (data_random ):
230230 data = data_random
231231 n_basis_modes = 5
232- model = SensorSelector (basis = Identity (n_basis_modes = n_basis_modes ))
232+ model = SSPOR (basis = Identity (n_basis_modes = n_basis_modes ))
233233 model .fit (data )
234234 assert model .basis_matrix_ .shape [1 ] == n_basis_modes
235235
@@ -240,7 +240,7 @@ def test_update_n_basis_modes_refit(data_random):
240240def test_update_n_basis_modes_unfit_basis (data_random ):
241241 data = data_random
242242 n_basis_modes = 5
243- model = SensorSelector ()
243+ model = SSPOR ()
244244 model .update_n_basis_modes (n_basis_modes , data )
245245
246246 assert model .basis_matrix_ .shape [1 ] == n_basis_modes
@@ -252,14 +252,14 @@ def test_ccqr_integration(data_random):
252252 costs [[1 , 3 , 5 ]] = 100
253253
254254 optimizer = CCQR (sensor_costs = costs )
255- model = SensorSelector (optimizer = optimizer ).fit (data )
255+ model = SSPOR (optimizer = optimizer ).fit (data )
256256
257257 check_is_fitted (model )
258258
259259
260260def test_sensor_selector_properties (data_random ):
261261 data = data_random
262- model = SensorSelector ().fit (data )
262+ model = SSPOR ().fit (data )
263263
264264 assert all (model .get_all_sensors () == model .all_sensors )
265265 assert all (model .get_selected_sensors () == model .selected_sensors )
0 commit comments