pysensors.optimizers package
Module contents
- classpysensors.optimizers.CCQR(sensor_costs=None)[source]
Bases:
QR
Greedy cost-constrained QR optimizer for sensor selection. This algorithm augments the pivot selection criteria used in the QR algorithm (with householder reflectors) to take into account costs associated with each sensors. It is similar to the
pysensors.optimizers.QR
algorithm in that it returns an array of sensor locations ranked by importance, but with a definition of importance that takes sensor costs into account.- Parameters:
sensor_costs (np.ndarray, shape [n_features,], optional (default None)) – Costs (weights) associated with each sensor. Positive values will encourage sensors to be avoided and negative values will cause them to be preferred. If None, costs will all be set to zero.
- Attributes:
pivots_ (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
- fit(basis_matrix)[source]
- Parameters:
basis_matrix (np.ndarray, shape [n_features, n_samples]) – Matrix whose columns are the basis vectors in which to represent the measurement data.
optimizer_kws (dictionary, optional) – Keyword arguments to be passed to the qr method.
- Returns:
self
- Return type:
a fitted
pysensors.optimizers.CCQR
instance
- set_fit_request(*, basis_matrix:bool|None|str='$UNCHANGED$') → CCQR
Configure whether metadata should be requested to be passed to the
fit
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- basis_matrixstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
basis_matrix
parameter infit
.
- selfobject
The updated object.
- classpysensors.optimizers.QR[source]
Bases:
BaseEstimator
- Attributes:
pivots_ (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
- fit(basis_matrix, **optimizer_kws)[source]
- Parameters:
basis_matrix (np.ndarray, shape [n_features, n_samples]) – Matrix whose columns are the basis vectors in which to represent the measurement data.
optimizer_kws (dictionary, optional) – Keyword arguments to be passed to the qr method.
- get_sensors()[source]
Get ranked array of sensors.
- Returns:
sensors – Array of sensors ranked in descending order of importance. Note that if n_features exceeds n_samples, then only the first n_samples entries of sensors are guaranteed to be in ranked order.
- Return type:
np.ndarray, shape [n_features,]
- set_fit_request(*, basis_matrix:bool|None|str='$UNCHANGED$') → QR
Configure whether metadata should be requested to be passed to the
fit
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- basis_matrixstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
basis_matrix
parameter infit
.
- selfobject
The updated object.
- classpysensors.optimizers.GQR[source]
Bases:
QR
- Attributes:
pivots_ (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
idx_constrained (np.ndarray, shape [No. of constrained locations]) – Column Indices of the sensors in the constrained locations.
n_sensors (integer,) – Total number of sensors
n_const_sensors (integer,) – Total number of sensors required by the user in the constrained region.
all_sensors (np.ndarray, shape [n_features]) – Optimally placed list of sensors obtained from QR pivoting algorithm.
constraint_option (string,) –
- max_n_const_sensorsThe number of sensors in the constrained region should
be less than or equal to n_const_sensors.
- exact_n_const_sensorsThe number of sensors in the constrained region
should be exactly equal to n_const_sensors.
- fit(basis_matrix, **optimizer_kws)[source]
- Parameters:
basis_matrix (np.ndarray, shape [n_features, n_samples]) – Matrix whose columns are the basis vectors in which to represent the measurement data.
optimizer_kws (dictionary, optional) – Keyword arguments to be passed to the qr method.
- Returns:
self
- Return type:
a fitted
pysensors.optimizers.GQR
instance
- set_fit_request(*, basis_matrix:bool|None|str='$UNCHANGED$') → GQR
Configure whether metadata should be requested to be passed to the
fit
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- basis_matrixstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
basis_matrix
parameter infit
.
- selfobject
The updated object.
- classpysensors.optimizers.TPGR(n_sensors, prior='decreasing', noise=None)[source]
Bases:
BaseEstimator
Two-Point Greedy Algorithm for Sensor Selection.
See the following reference for more information
Klishin, Andrei A., et. al. Data-Induced Interactions of Sparse Sensors. 2023. arXiv:2307.11838 [cond-mat.stat-mech]
- Parameters:
n_sensors (int) – The number of sensors to select.
prior (str or np.ndarray shape (n_basis_modes,), optional (default='decreasing')) – Prior Covariance Vector, typically a scaled identity vector or a vector containing normalized singular values. If ‘decreasing’, normalized singular values are used.
noise (float (default None)) – Magnitude of the gaussian uncorrelated sensor measurement noise.
- Attributes:
sensors_ (list of int) – Indices of the selected sensors (rows from the basis matrix).
- fit(basis_matrix, singular_values)[source]
- Parameters:
basis_matrix (np.ndarray, shape (n_features, n_basis_modes)) – Matrix whose columns are the basis vectors in which to represent the measurement data.
singular_values (np.ndarray, shape (n_basis_modes,)) – Normalized singular values to be used if
prior="decreasing"
.
- Returns:
self
- Return type:
a fitted
pysensors.optimizers.TPGR
instance
- set_fit_request(*, basis_matrix:bool|None|str='$UNCHANGED$', singular_values:bool|None|str='$UNCHANGED$') → TPGR
Configure whether metadata should be requested to be passed to the
fit
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- basis_matrixstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
basis_matrix
parameter infit
.- singular_valuesstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
singular_values
parameter infit
.
- selfobject
The updated object.