11"""Unit tests for optimizers"""
2-
32import numpy as np
43
5- from pysensors .optimizers import CCQR , GQR , QR
4+ from pysensors .optimizers import CCQR
5+ from pysensors .optimizers import QR
6+ from pysensors .optimizers import GQR
67
78
89def test_num_sensors (data_vandermonde ):
@@ -50,7 +51,6 @@ def test_ccqr_negative_costs(data_vandermonde):
5051 chosen_sensors = set (sensors [: min (x .shape )])
5152 assert all (s in chosen_sensors for s in set (desirable_sensors ))
5253
53-
5454def test_gqr_qr_equivalence (data_vandermonde ):
5555 x = data_vandermonde
5656
@@ -60,7 +60,6 @@ def test_gqr_qr_equivalence(data_vandermonde):
6060
6161 np .testing .assert_array_equal (gqr_sensors , qr_sensors )
6262
63-
6463def test_gqr_ccqr_equivalence (data_random ):
6564 x = data_random
6665
@@ -77,16 +76,7 @@ def test_gqr_ccqr_equivalence(data_random):
7776 # Get ranked sensors from GQR
7877 # first we should pass all_sensors to GQR
7978 all_sensors = np .arange (x .shape [1 ]) #QR().fit(x.T).get_sensors()
80- sensors_GQR = (
81- GQR ()
82- .fit (
83- x .T ,
84- idx_constrained = forbidden_sensors ,
85- n_const_sensors = 0 ,
86- constraint_option = "exact_n_const_sensors" ,
87- )
88- .get_sensors ()
89- )
79+ sensors_GQR = GQR ().fit (x .T , all_sensors = all_sensors , idx_constrained = forbidden_sensors ,n_const_sensors = 0 , constraint_option = 'exact_n' ).get_sensors ()
9080
9181 # Forbidden sensors should not be included
9282 chosen_sensors_GQR = set (sensors_GQR [: (x .shape [1 ] - len (forbidden_sensors ))])
@@ -116,73 +106,15 @@ def test_gqr_exact_constrainted_case1(data_random):
116106 assert set (sensors_CCQR ).isdisjoint (set (totally_forbidden_sensors ))
117107
118108
109+
119110 # Get ranked sensors from GQR
120111 sensors_GQR = GQR ().fit (x .T , idx_constrained = forbidden_sensors ,all_sensors = sensors_QR , n_sensors = total_sensors ,n_const_sensors = exact_n_const_sensors , constraint_option = 'exact_n' ).get_sensors ()[:total_sensors ]
121112 assert sensors_CCQR .all () == sensors_GQR .all ()
122113
123- def test_gqr_max_constrained_case1 (data_random ):
124- # In this case we want to place a total of 10 sensors
125- # with a constrained region that is allowed to have a maximum of 3 sensors
126- # but 4 of the first 10 are in the constrained region
127- x = data_random
128- # unconstrained sensors (optimal)
129- sensors_QR = QR ().fit (x .T ).get_sensors ()
130- # exact number of sensors allowed in the constrained region
131- total_sensors = 10
132- max_n_const_sensors = 3
133- forbidden_sensors = [8 , 5 , 2 , 6 ]
134- totally_forbidden_sensors = [x for x in forbidden_sensors if x in sensors_QR ][
135- :max_n_const_sensors
136- ]
137- totally_forbidden_sensors = [
138- y for y in forbidden_sensors if y not in totally_forbidden_sensors
139- ]
140- costs = np .zeros (x .shape [1 ])
141- costs [totally_forbidden_sensors ] = 100
142- # Get ranked sensors
143- sensors = CCQR (sensor_costs = costs ).fit (x .T ).get_sensors ()[:total_sensors ]
144-
145- # Forbidden sensors should not be included
146- chosen_sensors = set (sensors [: (x .shape [1 ] - len (totally_forbidden_sensors ))])
147- assert chosen_sensors .isdisjoint (set (totally_forbidden_sensors ))
148114
149- # Get ranked sensors from GQR
150- sensors_GQR = (
151- GQR ()
152- .fit (
153- x .T ,
154- idx_constrained = forbidden_sensors ,
155- n_sensors = total_sensors ,
156- n_const_sensors = max_n_const_sensors ,
157- constraint_option = "max_n_const_sensors" ,
158- )
159- .get_sensors ()[:total_sensors ]
160- )
161- assert sensors_GQR .intersection (forbidden_sensors ) == 3
162-
163-
164- def test_gqr_predetermined_case1 (data_random ):
165- # In this case we want to place a total of 10 sensors
166- # 2 of the sensors are predetermined by the user
167- x = data_random
168- # unconstrained sensors (optimal)
169- sensors_QR = QR ().fit (x .T ).get_sensors () # noqa: F841
170- # Predtermined sensors
171- total_sensors = 10
172- n_sensors_pre = 2
173- predetermined_sensors = [8 , 5 ]
115+ ## TODO
116+ def test_gqr_max_constrained ():
117+ pass
174118
175- # Predetermined sensors shopuld be included
176- # Get ranked sensors from GQR
177- sensors_GQR = (
178- GQR ()
179- .fit (
180- x .T ,
181- idx_constrained = predetermined_sensors ,
182- n_sensors = total_sensors ,
183- n_const_sensors = n_sensors_pre ,
184- constraint_option = "predetermined" ,
185- )
186- .get_sensors ()[:total_sensors ]
187- )
188- assert sensors_GQR .intersection (predetermined_sensors ) == 2
119+ def test_gqr_radii_constrained ():
120+ pass
0 commit comments