pysensors.utils package¶
Module contents¶
- pysensors.utils.constrained_binary_solve(w, psi, quiet=False, fit_intercept=True, normalize=True, precompute='auto')[source]¶
- pysensors.utils.constrained_multiclass_solve(w, psi, alpha=1.0, quiet=False, **lasso_kws)[source]¶
Solve
\[\begin{split}\text{argmin}_s \|s\|_0 \\ \text{subject to} \|w - \psi s\|_2^2 \leq tol\end{split}\]
- pysensors.utils.validate_input(x, sensors=None)[source]¶
Ensure that x is of compatible type and shape.
- Parameters
x (numpy ndarray, shape [n_features,] or [n_examples, n_features]) – Data to be validated.
- pysensors.utils.get_constraind_sensors_indices(x_min, x_max, y_min, y_max, nx, ny, all_sensors)[source]¶
Function for mapping constrained sensor locations on the grid with the column indices of the basis_matrix.
- Parameters
x_min (int, lower bound for the x-axis constraint) –
x_max (int, upper bound for the x-axis constraint) –
y_min (int, lower bound for the y-axis constraint) –
y_max (int, upper bound for the y-axis constraint) –
nx (int, image pixel (x dimensions of the grid)) –
ny (int, image pixel (y dimensions of the grid)) –
all_sensors (np.ndarray, shape [n_features], ranked list of sensor locations.) –
- Returns
idx_constrained – locations of the grid in terms of column indices of basis_matrix.
- Return type
np.darray, shape [No. of constrained locations], array which contains the constrained
- pysensors.utils.get_constrained_sensors_indices_linear(x_min, x_max, y_min, y_max, df)[source]¶
Function for obtaining constrained column indices from already existing linear sensor locations on the grid.
- Parameters
x_min (int, lower bound for the x-axis constraint) –
x_max (int, upper bound for the x-axis constraint) –
y_min (int, lower bound for the y-axis constraint) –
y_max (int, upper bound for the y-axis constraint) –
df (pandas.DataFrame, a dataframe containing the features and samples) –
- Returns
idx_constrained – locations of the grid in terms of column indices of basis_matrix.
- Return type
np.darray, shape [No. of constrained locations], array which contains the constrained
- pysensors.utils.exact_n(lin_idx, dlens, piv, j, n_const_sensors, **kwargs)[source]¶
Function for mapping constrained sensor locations with the QR procedure.
- Parameters
lin_idx (np.ndarray, shape [No. of constrained locations]) – Array which contains the constrained locationsof the grid in terms of column indices of basis_matrix.
dlens (np.ndarray, shape [Variable based on j]) – Array which contains the norm of columns of basis matrix.
piv (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
n_const_sensors (int,) – Number of sensors to be placed in the constrained area.
j (int,) – Iterative variable in the QR algorithm.
- Returns
dlens
- Return type
np.darray, shape [Variable based on j] with constraints mapped into it.
- pysensors.utils.max_n(lin_idx, dlens, piv, j, n_const_sensors, **kwargs)[source]¶
Function for mapping constrained sensor locations with the QR procedure (Optimally).
- Parameters
lin_idx (np.ndarray, shape [No. of constrained locations]) – Array which contains the constrained locations of the grid in terms of column indices of basis_matrix.
dlens (np.ndarray, shape [Variable based on j]) – Array which contains the norm of columns of basis matrix.
piv (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
j (int,) – Iterative variable in the QR algorithm.
const_sensors (int,) – Number of sensors to be placed in the constrained area.
all_sensors (np.ndarray, shape [n_features]) – Ranked list of sensor locations.
n_sensors (integer,) – Total number of sensors
- Returns
dlens
- Return type
np.darray, shape [Variable based on j] with constraints mapped into it.
- pysensors.utils.predetermined(lin_idx, dlens, piv, j, n_const_sensors, **kwargs)[source]¶
Function for mapping constrained sensor locations with the QR procedure.
- Parameters
lin_idx (np.ndarray, shape [No. of constrained locations], array which contains) – the constrained locationsof the grid in terms of column indices of basis_matrix.
dlens (np.ndarray, shape [Variable based on j], array which contains the norm of columns of basis matrix.) –
piv (np.ndarray, shape [n_features], ranked list of sensor locations.) –
n_const_sensors (int, number of sensors to be placed in the constrained area.) –
j (int, iterative variable in the QR algorithm.) –
- Returns
dlens
- Return type
np.darray, shape [Variable based on j] with constraints mapped into it.
- pysensors.utils.determinant(top_sensors, n_features, basis_matrix)[source]¶
Function for calculating |C.T phi.T C phi|.
- Parameters
top_sensors (np.darray,) – Column indices of choosen sensor locations
n_features (int,) – No. of features of dataset
basis_matrix (np.darray,) – The basis matrix calculated by model.basis_matrix_
- Returns
optimality – The dterminant value obtained.
- Return type
Float,
- pysensors.utils.relative_reconstruction_error(data, prediction)[source]¶
Function for calculating relative error between actual data and the reconstruction
- Parameters
- data: np.darray,
The actual data from the dataset evaluated
- predictionnp.darray,
The predicted values from model.predict(X[:,top_sensors])
- error_valFloat,
The relative error calculated.