GithubHelp home page GithubHelp logo

haozhg / oml Goto Github PK

View Code? Open in Web Editor NEW
29.0 1.0 5.0 1.25 MB

AI4Science: Efficient data-driven Online Model Learning (OML) / system identification and control

Home Page: https://github.com/haozhg/oml

License: MIT License

Python 97.13% Makefile 2.87%
machine-learning data-driven-model dynamical-systems inverse-problems system-identification model-reduction control-theory online-learning online-optimization model-learning reduced-order-models applied-mathematics python ai ai4science

oml's Introduction

oml

License python version pypi version Open In Collab Downloads PRs Welcome Code style: black

AI4Science: Efficient data-driven Online Model Learning (OML) / system identification and control. The algorithm is proposed in this paper.

To get started,

pip install ai4sci.oml --upgrade

This 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.

Showcase: Lorenz system control

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.

No control

If 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.

With control

If 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).

Highlights

Here are some hightlights about this algorithm, and for more detail refer to this paper

  • 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.
  • It finds the exact optimal solution (in the sense of least square error), without any approximation (unlike stochastic gradient descent).
  • It achieves theoretical optimal time and space complexity.
  • 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 >> n and essentially will go to infinity.
  • The space complexity is O(n^2), which is far more efficient than standard algorithm O(n * t) (t >> n).
  • A weighting factor (in (0, 1]) can be used to place more weight on recent data, thus making the model more adaptive.
  • This local model can be used for short-horizon prediction and data-driven real-time closed loop control.
  • It has been successfully applied to flow separation control problem, and achived real-time closed loop control. See this paper for details.

Online model learning algorithm description

This is a brief introduction to the algorithm. For full technical details, see this paper, and chapter 3 and chapter 7 of this PhD thesis.

Unknown dynamical system

Suppose we have a (discrete) nonlinear and/or time-varying dynamical system, and the state space representation is

  • x(t+1) = f(t, x(t), u(t))
  • y(t) = g(t, x(t), u(t))

where 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.

  • It is assumed that we have measurements x(i), u(i), y(i) for i = 0,1,...t.
  • However, we do not know functions f and g.
  • We aim to learn a model for the unknown dynamical system from measurement data up to time t.
  • We want to the model to be updated efficiently in real-time as new measurement data becomes available.

Online linear model learning

We would like to learn an adaptive linear model

  • x(t+1) = A x(t) + B u(t)
  • y(t) = C x(t) + D u(t)

that 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, 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.

This 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.

  • ai4sci.oml.OnlineLinearModel class implements the optimal algorithm.

Online nonlinear model learning

If 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.

In particular, we want to fit a nonlinear model of this form

  • x(t+1) = F * phi(x(t), u(t))
  • y(t) = G * psi(x(t), u(t))

where phi(~, ) and psi(, ~) are known vector-valued nonlinear functions (e.g, quadratic) that we specify, F and G are unknown matrices of proper size.

  • We aim to learn F and G from measurement data.
  • Notice that this model form is general, and encompass many systems such as Lorenze attractor, Logistic map, Auto-regressive model, polynomial systems.
  • F and G can be updated efficiently in real-time when new data comes in.

This can also be formulated as the same optimization problem, and the same efficient algorithm works in this case.

  • ai4sci.oml.OnlineModel class implements the optimal algorithm.

Use

Install

From PyPi

pip install ai4sci.oml --upgrade

From source

git clone https://github.com/haozhg/oml.git
cd oml/
pip install -e .

Tests

cd tests/
python -m pytest .

Demo

See ./demo for python notebook to demo the algorithm for data-driven real-time closed loop control.

  • demo_lorenz.ipynb shows control of Lorenz attractor.
  • demo_online_linear_model.ipynb shows control of an unstable linear time-varying system.

Authors:

Hao Zhang

Reference

If you you used these algorithms or this python package in your work, please consider citing

Zhang, Hao, Clarence W. Rowley, Eric A. Deem, and Louis N. Cattafesta. 
"Online dynamic mode decomposition for time-varying systems." 
SIAM Journal on Applied Dynamical Systems 18, no. 3 (2019): 1586-1609.

BibTeX

@article{zhang2019online,
  title={Online dynamic mode decomposition for time-varying systems},
  author={Zhang, Hao and Rowley, Clarence W and Deem, Eric A and Cattafesta, Louis N},
  journal={SIAM Journal on Applied Dynamical Systems},
  volume={18},
  number={3},
  pages={1586--1609},
  year={2019},
  publisher={SIAM}
}

Date created

April 2017

License

MIT

If you want to use this package, but find license permission an issue, pls contact me at haozhang at alumni dot princeton dot edu.

Issues

If there is any comment/suggestion, or if you find any bug, feel free to

  • create an issue here, and/or
  • fork this repo, make suggested changes, and create a pull request (merge from your fork to this repo). See this as an example guidance for contribution and PRs.

oml's People

Contributors

haozhg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

oml's Issues

几个问题

问题1:这个算法提交论文的链接失效了,能否讲一下。
Efficient data-driven Online Model Learning (OML) / system identification and control. The algorithm is proposed in this paper.

问题2:对于这个算法的实现,主要应用于哪些场景?
1:LIT 系统
2:NLIT系统
3:nonlinear and/or time-varying [dynamical system]
到底是哪一种?

我运行了一下测试用例,也没看出来这个算法到底是干什么的,求教。

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.