This repository contains the code for the paper "Linear quadratic control of nonlinear systems with Koopman operator learning and the Nyström method", by Edoardo Caldarelli, Antoine Chatalic, Adrià Colomé, Cesare Molinari, Carlos Ocampo-Martinez, Carme Torras, and Lorenzo Rosasco, 2024, submitted to Automatica.
Contact author: ecaldarelli@iri.upc.edu
The code simulating the Duffing oscillator contains the Matlab implementation deployed by Milan Korda [https://homepages.laas.fr/mkorda/Eigfuns.zip], accompanying the paper "Optimal construction of Koopman eigenfunctions for prediction and control", M. Korda, I. Mézic, IEEE TAC, 2020.
The implementation of the cloth simulation uses the Matlab code deployed by Franco Coltraro, accompanying the paper "An inextensible model for the robotic manipulation of textiles", F. Coltraro, J. Amorós, M. Alberich-Carramiñana, C. Torras, Applied Mathematical Modelling, 2022.
The required packages can be installed by running the following command:
pip install -r requirements.txt
The script benchmark_lqr_hjb.py
allows to compare the Nyström-Koopman regression with an exact kernel-based estimator, on the proof-of-concept nonlinear dynamics studied by Guo et al. (2022). The script allows to:
- cross-validate the regression hyperparameters (regularization constant, kernel lengthscale);
- validate the open-loop forecasts of the data-driven dynamical system;
- solve the LQR problem with the data-driven system, computing the optimal Riccati gain;
- test the state-feedback law with the real nonlinear system.
The script benchmark_lqr_classic.py
allows to compare the Nyström-Koopman regression with the spline-based
competitor, on the Duffing oscillator simulation. The script allows to:
- cross-validate the regression hyperparameters (regularization constant, kernel lengthscale);
- validate the open-loop forecasts of the data-driven dynamical system;
- solve the LQR problem with the data-driven system, computing the optimal Riccati gain;
- test the state-feedback law with the real nonlinear system.
In order to evaluate the baseline based on Korda and Mézic, 2020, one needs to run the Matlab script Duffing.m
, located in
the directory eigfuns
.
The results of this simulation are available in the directory duffing
.
First of all, the training set for the cloth manipulation experiment can be generated by running the script simulation_cloth.m
,
located in the directory cloth_simulator
.
The script benchmark_lqr_cloth.py
allows to compare the Nyström-Koopman regression with the spline-based
competitor, on the cloth manipulation task. The script allows to:
- cross-validate the regression hyperparameters (regularization constant, kernel lengthscale);
- validate the open-loop forecasts of the data-driven dynamical system;
- solve the LQR problem with the data-driven system, computing the optimal Riccati gain.
In order to assess the closed-loop behavior with the state-feedback employing the Riccati gain,
one can run the file closed_loop_lqr_control.m
, located in the directory cloth_simulator
.
The results of this simulation are located in the directory 8x8_cloth_swing_xyz/sim_results
.
The file dynamical_systems.py
contains the classes used to simulate nonlinear dynamics by Guo et al. (2022) and the Duffing oscillator in Python.
The file regressors.py
contains the Python implementation of the Nyström-Koopman estimator, the spline-based baseline, the exact kernel-based estimator,
and the kernels employed.
The remainder of the codes can be used to generate the plots appearing in the article.
The directory proofs
contains the pdf
files with the extended proofs of Lemma 5 and Theorem 7 in the main paper.