{"id":38655853,"url":"https://github.com/haozhg/oml","last_synced_at":"2026-01-17T09:27:21.492Z","repository":{"id":49427287,"uuid":"95597973","full_name":"haozhg/oml","owner":"haozhg","description":"AI4Science: Efficient data-driven Online Model Learning (OML) / system identification and control","archived":false,"fork":false,"pushed_at":"2022-10-20T22:59:13.000Z","size":1279,"stargazers_count":33,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T10:32:55.238Z","etag":null,"topics":["ai","ai4science","applied-mathematics","control-theory","data-driven-model","dynamical-systems","inverse-problems","machine-learning","model-learning","model-reduction","online-learning","online-optimization","python","reduced-order-models","system-identification"],"latest_commit_sha":null,"homepage":"https://github.com/haozhg/oml","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haozhg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-27T20:29:27.000Z","updated_at":"2025-11-24T02:22:11.000Z","dependencies_parsed_at":"2022-09-19T16:20:33.957Z","dependency_job_id":null,"html_url":"https://github.com/haozhg/oml","commit_stats":null,"previous_names":["haozhg/osysid"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/haozhg/oml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haozhg%2Foml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haozhg%2Foml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haozhg%2Foml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haozhg%2Foml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haozhg","download_url":"https://codeload.github.com/haozhg/oml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haozhg%2Foml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28505553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai4science","applied-mathematics","control-theory","data-driven-model","dynamical-systems","inverse-problems","machine-learning","model-learning","model-reduction","online-learning","online-optimization","python","reduced-order-models","system-identification"],"created_at":"2026-01-17T09:27:20.881Z","updated_at":"2026-01-17T09:27:21.475Z","avatar_url":"https://github.com/haozhg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oml\n[![License](https://img.shields.io/github/license/haozhg/oml)](https://github.com/haozhg/oml/blob/master/LICENSE)\n[![python version](https://img.shields.io/badge/python-3.7+-green)](https://docs.python.org/3.8/)\n[![pypi version](https://img.shields.io/badge/pypi-0.2.2-green)](https://pypi.org/project/ai4sci.oml/)\n[![Open In Collab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1dWeKuiEsVUjlNaKSFW6b7J-UyyFwov8C?usp=sharing)\n[![Downloads](https://pepy.tech/badge/ai4sci.oml)](https://pepy.tech/project/ai4sci.oml)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/haozhg/oml/pulls)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nAI4Science: Efficient data-driven Online Model Learning (OML) / system identification and control. The algorithm is proposed in this [paper](https://arxiv.org/abs/1707.02876.).\n\nTo get started,\n```\npip install ai4sci.oml --upgrade\n```\nThis python package is based on the online dynamic mode decomposition algorithm, which is also available as a python package `pip install odmd --upgrade`, see [here](https://github.com/haozhg/odmd).\n\n## Showcase: Lorenz system control\n[Lorenz system](https://en.wikipedia.org/wiki/Lorenz_system) is one of the most classical nonlinear dynamical systems. Here we show how the proposed algorithm can be used to controll that. For more details, see [demo](https://github.com/haozhg/oml/tree/master/demo).\n\n### No control\nIf there is no control, we can see the mysterious butterfly trajectory. It starts close to the bottom plane and enters into the butterfly wing region, then oscillates there.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/lorenz_state.png\" width=\"300\" /\u003e\n  \u003cimg src=\"assets/lorenz_control.png\" width=\"300\" /\u003e \n\u003c/p\u003e\n\n### With control\nIf we apply data-driven real-time closed loop control, it can be stabilized at an unstable fixed point (near the center of the butterfly wing).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/lorenz_state_controlled.png\" width=\"300\" /\u003e\n  \u003cimg src=\"assets/lorenz_control_controlled.png\" width=\"300\" /\u003e \n\u003c/p\u003e\n\n## Highlights\nHere are some hightlights about this algorithm, and for more detail refer to this [paper](https://epubs.siam.org/doi/pdf/10.1137/18M1192329)\n\n- Efficient data-driven online linear/nonlinear model learning (system identification). Any nonlinear and/or time-varying system is locally linear, as long as the model is updated in real-time wrt to new measurements.\n- It finds the exact optimal solution (in the sense of least square error), without any approximation (unlike stochastic gradient descent). \n- It achieves theoretical optimal time and space complexity. \n- The time complexity (flops for one iteration) is O(n^2), where n is state dimension. This is much faster than standard algorithm O(n^2 * t), where t is the current time step (number of measurements). In online applications, t \u003e\u003e n and essentially will go to infinity.\n- The space complexity is O(n^2), which is far more efficient than standard algorithm O(n * t) (t \u003e\u003e n).\n- A weighting factor (in (0, 1]) can be used to place more weight on recent data, thus making the model more adaptive.\n- This local model can be used for short-horizon prediction and data-driven real-time closed loop control.\n- It has been successfully applied to flow separation control problem, and achived real-time closed loop control. See this [paper](https://doi.org/10.1017/jfm.2020.546) for details.\n\n## Online model learning algorithm description\nThis is a brief introduction to the algorithm. For full technical details, see this [paper](https://epubs.siam.org/doi/pdf/10.1137/18M1192329), and chapter 3 and chapter 7 of this [PhD thesis](http://arks.princeton.edu/ark:/88435/dsp0108612r49q).\n\n### Unknown dynamical system\nSuppose we have a (discrete) nonlinear and/or time-varying [dynamical system](https://en.wikipedia.org/wiki/State-space_representation), and the state space representation is\n- x(t+1) = f(t, x(t), u(t))\n- y(t) = g(t, x(t), u(t))\n\nwhere t is (discrete) time, x(t) is state vector, u(t) is control (input) vector, y(t) is observation (output) vector. f(~, ~, ~) and g(~, ~, ~) are unknown vector-valued nonlinear functions.\n\n- It is assumed that we have measurements x(i), u(i), y(i) for i = 0,1,...t. \n- However, we do not know functions f and g. \n- We aim to learn a model for the unknown dynamical system from measurement data up to time t.\n- We want to the model to be updated efficiently in real-time as new measurement data becomes available.\n\n### Online linear model learning\nWe would like to learn an adaptive [linear model](https://en.wikipedia.org/wiki/State-space_representation)\n- x(t+1) = A x(t) + B u(t)\n- y(t) = C x(t) + D u(t)\n\nthat fits/explains the observation optimally. By Taylor expansion approximation, any nonlinear and/or time-varying system is linear locally. There are many powerful tools for linear control, e.g, [Linear Quadratic Regulator](https://en.wikipedia.org/wiki/Linear%E2%80%93quadratic_regulator), [Kalman filter](https://en.wikipedia.org/wiki/Kalman_filter). However, to accurately approximate the original (unknown) dynamical system, we need to update this linear model efficiently in real-time whenever new measurement becomes available.\n\nThis problem can be formulated as an optimization problem, and at each time step t we need to solve a related but slightly different optimization problem. The optimal algorithm is achived through efficient reformulation of the problem. \n\n- `ai4sci.oml.OnlineLinearModel` class implements the optimal algorithm.\n\n### Online nonlinear model learning\nIf we need to fit a nonlinear model to the observed data, this algorithm also applies in this case. Keep in mind that linear adaptive model is good approximation as long as it is updated in real-time. Also, the choice of nonlinear form can be tricky. Based on Taylor expansion, if we add higher order nonlinearity (e.g., quadratic, cubic), the approximation can be more accurate. However, given the learned nonlinear model, it is still not easy to apply control.\n\nIn particular, we want to fit a nonlinear model of this form\n- x(t+1) = F * phi(x(t), u(t))\n- y(t) = G * psi(x(t), u(t))\n\nwhere phi(~, ~) and psi(~, ~) are known vector-valued nonlinear functions (e.g, quadratic) that we specify, F and G are unknown matrices of proper size. \n\n- We aim to learn F and G from measurement data. \n- Notice that this model form is general, and encompass many systems such as Lorenze attractor, Logistic map, Auto-regressive model, polynomial systems.\n- F and G can be updated efficiently in real-time when new data comes in.\n\nThis can also be formulated as the same optimization problem, and the same efficient algorithm works in this case.\n\n- `ai4sci.oml.OnlineModel` class implements the optimal algorithm.\n\n## Use\n### Install\nFrom PyPi\n```\npip install ai4sci.oml --upgrade\n```\n\nFrom source\n```\ngit clone https://github.com/haozhg/oml.git\ncd oml/\npip install -e .\n```\n\n### Tests\n```\ncd tests/\npython -m pytest .\n```\n\n### Demo\nSee `./demo` for python notebook to demo the algorithm for data-driven real-time closed loop control.\n- `demo_lorenz.ipynb` shows control of [Lorenz attractor](https://en.wikipedia.org/wiki/Lorenz_system).\n- `demo_online_linear_model.ipynb` shows control of an unstable linear time-varying system.\n\n## Authors:\nHao Zhang \n\n## Reference\nIf you you used these algorithms or this python package in your work, please consider citing\n\n```\nZhang, Hao, Clarence W. Rowley, Eric A. Deem, and Louis N. Cattafesta. \n\"Online dynamic mode decomposition for time-varying systems.\" \nSIAM Journal on Applied Dynamical Systems 18, no. 3 (2019): 1586-1609.\n```\n\nBibTeX\n```\n@article{zhang2019online,\n  title={Online dynamic mode decomposition for time-varying systems},\n  author={Zhang, Hao and Rowley, Clarence W and Deem, Eric A and Cattafesta, Louis N},\n  journal={SIAM Journal on Applied Dynamical Systems},\n  volume={18},\n  number={3},\n  pages={1586--1609},\n  year={2019},\n  publisher={SIAM}\n}\n```\n\n## Date created\nApril 2017\n\n## License\nMIT\n\nIf you want to use this package, but find license permission an issue, pls contact me at `haozhang at alumni dot princeton dot edu`.\n\n## Issues\nIf there is any comment/suggestion, or if you find any bug, feel free to \n- create an issue [here](https://github.com/haozhg/oml/issues), and/or\n- fork this repo, make suggested changes, and create a pull request (merge from your fork to this repo). See [this](https://numpy.org/devdocs/dev/index.html#development-process-summary) as an example guidance for contribution and PRs.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaozhg%2Foml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaozhg%2Foml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaozhg%2Foml/lists"}