xlsindy.optimization module
This module include every function in order to run the optimisation step for getting the sparse solution
- xlsindy.optimization.activated_catalog(exp_matrix: ndarray, force_vector: ndarray, num_coordinate: int)
Perform a recursive search to find the part ot the catalog that could be activated by the force vector.
- Args
exp_matrix (np.ndarray): Experimental matrix. force_vector (np.ndarray): Force vector. num_coordinate (int): Number of coordinates.
- Returns:
Activated catalog.
- Return type:
np.ndarray
- xlsindy.optimization.amputate_experiment_matrix(experiment_matrix: ndarray, mask: int) Tuple[ndarray, ndarray]
Simple function to split the experiment matrix into an reduced experiment matrix and an external vector.
Can be used to split experiment matrix in the case of implicit or explicit regression
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
mask (int) – the column to erase
- Returns:
Reduced experiment matrix . np.ndarray : Left Hand Side vector (forces vector)
- Return type:
np.ndarray
- xlsindy.optimization.bipartite_link(exp_matrix, num_coordinate, x_names, b_names)
This function is used to create the list of edges for the bipartite graph
- xlsindy.optimization.condition_value(exp_matrix: ndarray, solution: ndarray) ndarray
Calculate condition values based on the variance of the experimental matrix.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
solution (np.ndarray) – Solution vector.
- Returns:
Array of condition values.
- Return type:
np.ndarray
- xlsindy.optimization.covariance_vector(exp_matrix: ndarray, covariance_matrix: ndarray, num_time_steps: int) ndarray
Calculates the covariance vector across time steps for an experimental matrix.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
covariance_matrix (np.ndarray) – Covariance matrix.
num_time_steps (int) – Number of time steps.
- Returns:
Covariance vector summed across time steps.
- Return type:
np.ndarray
- xlsindy.optimization.hard_threshold_sparse_regression(whole_exp_matrix: ~numpy.ndarray, mask: int, condition_func: ~typing.Callable = <function condition_value>, threshold: float = 0.03) ndarray
Performs sparse regression with a hard threshold to select significant features.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
mask (int) – the forces column
condition_func (Callable) – Function to calculate condition values.
threshold (float) – Threshold for feature selection.
- Returns:
solution vector. shape (-1,1)
- Return type:
np.ndarray
- xlsindy.optimization.hard_threshold_sparse_regression_old(forces_vector: ~numpy.ndarray, exp_matrix: ~numpy.ndarray, condition_func: ~typing.Callable = <function condition_value>, threshold: float = 0.03) ndarray
(DEPRECATED) should use the new formalism for regression function (experiment_matrix, position of b vector (mask)) Performs sparse regression with a hard threshold to select significant features.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
forces_vector (np.ndarray) – Forces vector.
condition_func (Callable) – Function to calculate condition values.
threshold (float) – Threshold for feature selection.
- Returns:
solution vector. shape (-1,)
- Return type:
np.ndarray
- xlsindy.optimization.lasso_regression(whole_exp_matrix: ndarray, mask: int, max_iterations: int = 10000, tolerance: float = 1e-05, eps: float = 0.0005) ndarray
(DEPRECATED) should use the new formalism for regression function (experiment_matrix, position of b vector (mask)) Performs Lasso regression to select sparse features.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix.
mask (int) – the forces column
max_iterations (int) – Maximum number of iterations.
tolerance (float) – Convergence tolerance.
eps (float) – Regularization parameter.
- Returns:
Coefficients of the fitted model. shape (-1,)
- Return type:
np.ndarray
- xlsindy.optimization.lasso_regression_old(forces_vector: ndarray, exp_matrix: ndarray, max_iterations: int = 10000, tolerance: float = 1e-05, eps: float = 0.0005) ndarray
(DEPRECATED) should use the new formalism for regression function (experiment_matrix, position of b vector (mask)) Performs Lasso regression to select sparse features.
- Parameters:
forces_vector (np.ndarray) – Dependent variable vector.
exp_matrix (np.ndarray) – Normalized experimental matrix.
max_iterations (int) – Maximum number of iterations.
tolerance (float) – Convergence tolerance.
eps (float) – Regularization parameter.
- Returns:
Coefficients of the fitted model. shape (-1,)
- Return type:
np.ndarray
- xlsindy.optimization.normalize_experiment_matrix(exp_matrix: ndarray, null_effect: bool = False) Tuple[ndarray, ndarray, ndarray]
(Deprecated) Clearly not in use for a long time… Normalizes an experimental matrix by its variance and mean.
- Parameters:
exp_matrix (np.ndarray) – Experimental matrix to normalize.
null_effect (bool) – Whether to consider null effect in normalization.
- Returns:
Normalized matrix, reduction indices, and variance.
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- xlsindy.optimization.optimal_sampling(theta_values: ndarray, distance_threshold: float) ndarray
(experimetnal) Selects optimal samples from a set of points based on a distance threshold.
- Parameters:
theta_values (np.ndarray) – Array of points.
distance_threshold (float) – Minimum distance to include a point.
- Returns:
Indices of selected points.
- Return type:
np.ndarray
- xlsindy.optimization.populate_solution(solution: ndarray, mask: int) ndarray
Opposite of amputate_experiment_matrix add a -1 in the solution where the mask should have been. (Because Left Hand Side is -1 )
- xlsindy.optimization.unnormalize_experiment(coefficients: ndarray, variance: ndarray, reduction_indices: ndarray, exp_matrix: ndarray) ndarray
(Deprecated) Clearly not in use for a long time… Reverts normalization of a solution vector.
- Parameters:
coefficients (np.ndarray) – Normalized coefficients.
variance (np.ndarray) – Variance used for normalization.
reduction_indices (np.ndarray) – Indices used for dimensionality reduction.
exp_matrix (np.ndarray) – Original experimental matrix.
- Returns:
Unnormalized solution vector.
- Return type:
np.ndarray