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, pre_knowledge_mask: ndarray, num_coordinate: int)

[AHHHHHH] I need to transpose the force vector bruh Perform a recursive search to find the part ot the catalog that could be activated by the force vector.

Args

exp_matrix (np.ndarray): The experimental matrix. pre_knowledge_mask (np.ndarray): The pre-knowledge mask. noise_level (float): The noise level to consider for activation. sample_number (int): The number of samples in the experimental matrix. num_coordinate (int): The number of generalized coordinates.

Returns:

Activated catalog. np.ndarray (1,catalog_lenght): Activated coordinate.

Return type:

np.ndarray (num_coordinate,1)

xlsindy.optimization.amputate_experiment_matrix(experiment_matrix: ndarray, mask: ndarray) 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 (pre_knowledge_mask) – Experimental matrix.

  • mask (pre_knowledge_mask) – a mask to indicate the position of the pre-knowledge column.

Returns:

Reduced experiment matrix . np.ndarray : Left Hand Side vector (forces vector)

Return type:

np.ndarray

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 | ~numpy.ndarray, 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: ndarray, max_iterations: int = 10000, tolerance: float = 1e-05, eps: float = 0.0005) ndarray

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.lasso_regression_rapids(whole_exp_matrix: ndarray, mask: ndarray, max_iterations: int = 10000, tolerance: float = 1e-05) ndarray

Performs Lasso regression on the GPU using the correct cuml pattern: Lasso + GridSearchCV.

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: ndarray) 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.proximal_gradient_descent(whole_exp_matrix: ndarray, mask: ndarray, sparsity_factor: float = 0.01, learning_rate: float = None, max_iterations: int = 10000, tolerance: float = 1e-05, adaptive_lr: bool = True) ndarray

Performs proximal gradient descent with L1 regularization for sparse feature selection.

This implements the iterative soft-thresholding algorithm (ISTA), which is equivalent to Lasso regression but with explicit control over the optimization process.

Parameters:
  • whole_exp_matrix (np.ndarray) – Experimental matrix including forces column.

  • mask (int) – The forces column index.

  • sparsity_factor (float) – L1 regularization parameter (lambda). Higher values increase sparsity.

  • learning_rate (float) – Step size. If None, uses 1/(largest eigenvalue of X^T X).

  • max_iterations (int) – Maximum number of iterations.

  • tolerance (float) – Convergence tolerance based on coefficient change.

  • adaptive_lr (bool) – Whether to use adaptive learning rate (Lipschitz constant).

Returns:

Coefficients of the fitted model. shape (-1, 1)

Return type:

np.ndarray

xlsindy.optimization.soft_threshold(x: ndarray, threshold: float) ndarray

Soft-thresholding operator (proximal operator for L1 norm).

Parameters:
  • x (np.ndarray) – Input array.

  • threshold (float) – Threshold value.

Returns:

Soft-thresholded array.

Return type:

np.ndarray

xlsindy.optimization.sparse_tradeoff_score(estimator, X, y, alpha=0.2)
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