xlsindy.dynamics_modeling module
This module contain every function in order to integrate and generate the dynamic function.
- xlsindy.dynamics_modeling.dynamics_function(acceleration_function: Callable[[ndarray], ndarray], external_forces: Callable[[ndarray], ndarray]) Callable[[float, ndarray], ndarray]
Transforms the acceleration function into something understandable by usual integration method.
The acceleration function ( output of euler_lagrange.generate_acceleration_function() ) takes as input a numerical symbol matrix. It is not suitable for the majority of the integration function that need to take as input (t,[q0,q0_d,…,qn,qn_d]) and output (q0_d,q0_dd,…,qn_d,qn_dd).
- Parameters:
acceleration_function (function) – Array of functions representing accelerations.
external_forces (function) – Function returning external forces at time t.
- Returns:
Dynamics function compatible with classical integration solver.
- Return type:
function
- xlsindy.dynamics_modeling.dynamics_function_RK4_env(acceleration_function: Callable[[ndarray], ndarray]) Callable[[ndarray], Callable[[float, ndarray], ndarray]]
Transforms the acceleration function into something compatible for the RK4 integration method. (into reinforcement-learning-sindy )
The acceleration function ( output of euler_lagrange.generate_acceleration_function() ) takes as input a numerical symbol matrix. It is not suitable for the integration function of RK4 environment that need to take as input ([q0,q0_d,…,qn,qn_d],[f0,…,fn]) and output (q0_d,q0_dd,…,qn_d,qn_dd). Use jax jnp instead of numpy for better performance. need to be use in accordance with euler_lagrange.generate_acceleration_function(lambdify_module=”jax”)
- Parameters:
acceleration_function (function) – Array of functions representing accelerations.
- Returns:
return a function that take in input fixed force vector and forces and return a Dynamics function compatible with classical integration solver.
- Return type:
function
- xlsindy.dynamics_modeling.dynamics_function_fixed_external(acceleration_function: Callable[[ndarray], ndarray]) Callable[[ndarray], Callable[[float, ndarray], ndarray]]
Transforms the acceleration function into something understandable by usual integration method. (will be deprecated in v2.0)
The acceleration function ( output of euler_lagrange.generate_acceleration_function() ) takes as input a numerical symbol matrix. It is not suitable for the majority of the integration function that need to take as input (t,[q0,q0_d,…,qn,qn_d]) and output (q0_d,q0_dd,…,qn_d,qn_dd). Due to the fact that it has been modified to perform one time step RK4, it introduces slight overhead
- Parameters:
acceleration_function (function) – Array of functions representing accelerations.
- Returns:
return a function that take in input fixed force vector and return a Dynamics function compatible with classical integration solver.
- Return type:
function
- xlsindy.dynamics_modeling.generate_acceleration_function(regression_solution: ndarray, catalog_repartition: CatalogRepartition, symbol_matrix: ndarray, time_symbol: Symbol, lambdify_module: str = 'numpy') Tuple[Callable[[ndarray], ndarray], bool]
Generate a function for computing accelerations based on the Lagrangian.
This is actually a multi step process that will convert a Lagrangian into an acceleration function through euler lagrange theory.
Some information about clever solve : there is two mains way to retrieve the acceleration from the other variable. The first one is to ask sympy to symbolically solve our equation and after to lambify it for use afterward. The main drawback of this is that when system is not perfectly retrieved it is theorically extremely hard to get a simple equation giving acceleration from the other variable. This usually lead to code running forever trying to solve this symbolic issue.
The other way is to create a linear system of b=Ax where x are the acceleration coordinate and b is the force vector. At runtime one’s need to replace every term in b and A and solve the linear equation (of dimension n so really fast)
- Parameters:
regression_solution (np.ndarray) – the solution vector from the regression
catalog_repartition (List[tuple]) – a listing of the different part of the catalog used need to follow the following structure : [(“lagrangian”,lagrangian_catalog),…,(“classical”,classical_catalog,expand_matrix)]
symbol_matrix (np.ndarray) – Matrix containing symbolic variables (external forces, positions, velocities, accelerations).
time_symbol (sp.Symbol) – The time symbol in the Lagrangian.
- Returns:
A function that computes the accelerations given system state. takes as input a numerical symbol matrix bool: Whether the acceleration function generation was successful.
- Return type:
function
- xlsindy.dynamics_modeling.generate_random_force(time_end: float, current_augmentation: int, target_augmentation: int, period_initial: float, period_shift_initial: float, component_count: int, random_gen: Generator) Callable[[float], ndarray]
Recursively generates a random external force function with specified augmentations.
- Parameters:
time_end (float) – End time for the generated force.
current_augmentation (int) – Current augmentation step in recursion.
target_augmentation (int) – Target augmentation level.
period_initial (float) – Initial period for the force oscillations.
period_shift_initial (float) – Initial shift for random variations in the period.
component_count (int) – Number of components in the force vector.
- Returns:
A function that generates a random force vector over time.
- Return type:
Callable[[float], np.ndarray]
- xlsindy.dynamics_modeling.optimized_force_generator(component_count: int, scale_vector: ndarray, time_end: float, period: float, period_shift: float, augmentations: int = 50, random_seed: List[int] = [20]) Callable[[float], ndarray]
Generates an optimized force function, applying a scale vector to the generated force.
- Parameters:
component_count (int) – Number of components in the force vector.
scale_vector (np.ndarray) – Scaling factors for each component.
time_end (float) – End time for the generated force.
period (float) – Base period for force oscillations.
period_shift (float) – Base shift applied to the period for randomness.
augmentations (int) – Number of augmentations in the recursive force generation.
- Returns:
A function that returns the optimized force at time t.
- Return type:
Callable[[float], np.ndarray]
- xlsindy.dynamics_modeling.run_rk45_integration(dynamics: Callable[[float, ndarray], ndarray], initial_state: ndarray, time_end: float, max_step: float = 0.05, min_step: float = 0.0001) List[ndarray]
Runs an RK45 integration on a dynamics model.
- Parameters:
dynamics (function) – Dynamics function for integration.
initial_state (np.ndarray) – Initial state of the system.
time_end (float) – End time for the integration.
max_step (float, optional) – Maximum step size for the integration. Defaults to 0.05.
- Returns:
Arrays of time values and states.
- Return type:
tuple
- xlsindy.dynamics_modeling.vectorised_acceleration_generation(dynamic_system: Callable, qpos, qvel, force)
Take a dynamic system function after being vectorised model_dynamics_system = vmap(model_dynamics_system, in_axes=(1,1),out_axes=1) and return a batch of acceleration