Skip to content

Instantly share code, notes, and snippets.

@nikos-kekatos
Last active February 1, 2023 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikos-kekatos/d25fd4f8457031115cd97fb7ff61413b to your computer and use it in GitHub Desktop.
Save nikos-kekatos/d25fd4f8457031115cd97fb7ff61413b to your computer and use it in GitHub Desktop.
Hybrid_System_Identification

A short note on Hybrid System Identification

Hybrid System Identification

Hybrid Identification Toolbox [HIT], link [not maintained]

Multi-Parametric Toolbox [MPT], link [none native support]

SARXSAT, tool for identifying ARX (autoregressive models with exogenous inputs) and piecewise ARX, Github repo

HySynth, synthesis of hybrid automata from data, Github repo [recent]

Predictor Based Subspace IDentification (PBSID) Toolbox, Github repo

Suggested literature:

  1. Paoletti, S., Juloski, A.L., Ferrari-Trecate, G., Vidal, R.: Identification of hybrid systems: A tutorial. Eur. J. Control 13(2-3), 242–260 (2007), https://doi.org/10. 3166/ejc.13.242-260

  2. Ozay, N.: An exact and efficient algorithm for segmentation of ARX models. In: ACC. pp. 38–41. IEEE (2016), https://doi.org/10.1109/ACC.2016.7524888

  3. Synthesis of Hybrid Automata with Affine Dynamics from Time-Series Data https://arxiv.org/pdf/2102.12734.pdf

Workaround to integrate HIT with MPT version 3

  1. Download HIT from the official website. I also backed up the files here.

  2. Unzip HIT and add it to the Matlab path. You can do it via right-click on the root folder and choose Add files to path and Select Folders and Subfolders or via addpath(genpath(...)).

    Adding HIT to the path is needed everytime you open Matlab and want to use HIT. You can use savepath command or modify startup.m or change the environment variable MATLABPATH if you want to store the path indefinitely. Useful link: 1

  3. Download MPT version 3 from the offical website. The website provides an installation manual. The easiest option is to opt for the automatic installation option and download the file install_mpt3.m. I have backed up the file here.

  4. Run the install_mpt.m from Matlab and choose the directory where you want to place MPT.

    The MPT files are added to the path automatically, everytime you open Matlab.

  5. Run mpt_init.m to initialize MPT and check the tool status (e.g. available or missing solvers).

    Note that we want to run the files located in `hit/examples/`
    
  6. Find and open the files hit/hit_init.m and hit/plotting/hit_plot_regions3D.m. Replace the global variable mptoptions by MPTOPTIONS.

  7. Again go to hit_plot_regions3D.m and delete or comment out the lines 70-72 (an if-then statement that uses the extreme solver). This option is deprecated in MPT version 3. Also, replace line 74 Options.newfigure=MPTOPTIONS.newfigure; by Options.newfigure=1;

  8. Change the default solver for quadratic programming problems in MPT.

    • Run which quadprog -all
    • If the answer is something like /Applications/MATLAB_R2022a.app/toolbox/optim/optim/quadprog.m, then find and open the file mpt_solvers_options.m.

    It should be somewhere like tbxmanager/toolboxes/mpt/3.2.1/all/mpt3-3_2_1/mpt/modules/solvers/mpt_solvers_options.m

    • Search for the following lines (~lines 588-589):

      options.quadprog.Algorithm = 'trust-region-reflective’;

      %options.quadprog.Algorithm = 'interior-point-convex’;

    • Comment out the first one and uncomment the second one.

    • Save the file and re-run mpt_init.m

  9. Edit examples/ex_pwarx_1d_5modes.m and change line 94 from

     idpar.patt_rec_algo='svc'; 
    

    to

     idpar.patt_rec_algo='psvc';
    
  10. Now you should be able to run all the models/examples located in examples/

Applying HIT to a control imitation problem

  1. Original model: Mathworks' nonlinear MPC for a flying robot
  2. Run the data generation part of our FlyingRobot_model. You can use the pregenerated data stored as a .mat file.
  3. In our case, we have an identification problem and we start from a collection of inputs-outputs. Our input is $X$ eight-dimensional and our output is $U$ which is two-dimensional.
  4. HIT works for single outputs so we need to split the problem into two: going from $X$->$U_1$ and from $X$->$U_2$.
  5. Need to modify ex_cake_1.m to match our case. It seems that you need to choose the number of PWA regions beforehand.
  6. to be continued.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment