xlsindy.symbolic_util module

This file is mainly to create and manage catalog of function that will be use in the xl-sindy algorithm afterward.

It contains two clear part : - the first one manage the symbolic expression in any given paradigm (lagrangian, classical, external forces,…) - the second one create and manage the catalog of function that summurize all the work done in the first part.

xlsindy.symbolic_util.augment_catalog(num_coordinates: int, sup_catalog: List[Expr], coeff_matrix: ndarray, expand_matrix: ndarray, base_catalog: ndarray, requested_lenght: int, random_seed: int) Tuple[ndarray, ndarray, List[Expr]]

Extend a base catalog with another from requested_lenght-len(base_catalog) new term

Parameters:
  • num_coordinates (int) – number of coordinate

  • sup_catalog (List[sympy.Expr]) – additionnal catalog where you take data

  • coeff_matrix (np.ndarray) – base coeff matrix

  • binary_matrix (np.ndarray) – base expand matrix

  • base_catalog (np.ndarray) – base catalog

  • requested_lenght (int) – the reqested lenght of the catalog

  • random_seed (int) – the random seed to pick catalog

Returns:

new coeff matrix np.ndarray : new expand matrix np.ndarray : new catalog

Return type:

np.ndarray

xlsindy.symbolic_util.cross_catalog(catalog1: List[Expr], catalog2: List[Expr])

Compute the outer product of two catalog and concatenate everything back (catalog1,catalog2,catalog1 X catalog2)

Parameters:
  • catalog1 (List[sympy.Expr]) – First catalog

  • catalog2 (List[sympy.Expr]) – Second catalog

xlsindy.symbolic_util.generate_full_catalog(function_catalog: List[Expr], q_terms: int, degree: int, power: int = None) List[Expr]

Generates a catalog of linear combinations from a function array until a certain degree/power.

Parameters:
  • function_catalog (List[sympy.Expr]) – List of functions to use.

  • q_terms (int) – Number of general coordinate.

  • degree (int) – Maximum degree of combinations.

  • power (int, optional) – Maximum power level of singleton. Defaults to None, in which case it uses degree. Need to be inferior or equal to depth in order to generate at least function_i^power in the catalog

Returns:

List of combined functions.

Return type:

List[sympy.Expr]

xlsindy.symbolic_util.generate_symbolic_matrix(coord_count: int, t: Symbol) ndarray

Creates a symbolic matrix representing external forces and state variables for a number of coordinates.

This function create the matrix containing all the state variable with following derivatives and external forces.

Fext0(t)

Fext2(t)

Fextn(t)

q0(t)

q2(t)

qn(t)

q0_d(t)

q2_d(t)

qn_d(t)

q0_dd(t)

q2_dd(t)

qn_dd(t)

Parameters:
  • coord_count (int) – Number of coordinates.

  • t (sympy.Symbol) – Symbol representing time.

Returns:

matrix of shape (4, n) containing symbolic expression.

Return type:

np.ndarray

xlsindy.symbolic_util.get_additive_equation_term(equation: Expr)

Extracts all additive terms from a SymPy expression and stores them in an array along with their coefficients.

Parameters:

expr (sympy.Expr) – The input SymPy expression.

Returns:

A list of tuples, where each tuple contains (coefficient, term).

Return type:

list

xlsindy.symbolic_util.sindy_create_coefficient_matrices(lists)

Given a list of lists, where each inner list contains tuples of (coefficient, expression),

Returns:

a sorted list of unique sympy expressions. coeff_matrix: a 2D numpy array (dtype=object) of shape (number of unique expressions, n) with the coefficient for the corresponding expression in each list. binary_matrix: a 2D numpy integer array with 1 if the corresponding coefficient is non-zero, 0 otherwise.

Return type:

unique_exprs