77from sklearn .utils .validation import check_is_fitted
88
99from ..basis import Identity
10+ from ..optimizers import CCQR
1011from ..optimizers import QR
1112from ..utils import validate_input
1213
@@ -149,7 +150,8 @@ def fit(self, x, quiet=False, prefit_basis=False, seed=None, **optimizer_kws):
149150 n_basis_modes = self .n_basis_modes
150151 )
151152
152- # Check that n_sensors doesn't exceed dimension of basis vectors
153+ # Check that n_sensors doesn't exceed dimension of basis vectors and
154+ # that it doesn't exceed the number of samples when using the CCQR optimizer.
153155 self ._validate_n_sensors ()
154156
155157 # Find sparse sensor locations
@@ -489,7 +491,8 @@ def score(x, y):
489491 def _validate_n_sensors (self ):
490492 """
491493 Check that number of sensors does not exceed the maximimum number
492- allowed by the chosen basis.
494+ allowed by the chosen basis. Also check for potential conflicts between
495+ number of sensors and the optimizer.
493496 """
494497 check_is_fitted (self , "basis_matrix_" )
495498
@@ -503,3 +506,14 @@ def _validate_n_sensors(self):
503506 max_sensors
504507 )
505508 )
509+
510+ # If n_sensors exceeds n_samples, the cost-constrained QR algorithm may
511+ # place sensors in constrained areas.
512+ if (
513+ isinstance (self .optimizer , CCQR )
514+ and self .n_sensors > self .basis_matrix_ .shape [1 ]
515+ ):
516+ warnings .warn (
517+ "Number of sensors exceeds number of samples, which may cause CCQR to "
518+ "select sensors in constrained regions."
519+ )
0 commit comments