AI4Science: Python/Matlab implementation of online and window dynamic mode decomposition (Online DMD and Window DMD)
A python package for online dynamic mode decomposition (Online DMD) and window dynamic mode decomposition (Window DMD) algorithms proposed in this paper. For matlab implementation, see this repo.
To get started,
pip install odmd --upgrade
A variant of this algorithm for efficient data-driven online model learning (system identification) and control is implemented in ai4sci.oml (try pip install ai4sci.oml --upgrade
). This algorithm has been show to be effective for flow separation control, see this paper for more details.
We take a 2D time-varying system given by
where x = [x1,x2]', A(t) = [0, w(t); -w(t), 0], w(t)=1+epsilon*t, epsilon=0.1. The slowly time-varying eigenvlaues of A(t) are pure imaginary, +(1+0.1t)j and -(1+0.1t)j, where j is the imaginary unit.
Here we show how the proposed algorithm can be used to learn a model of the system. For more detail, see demo.
The system is oscillating with increasing frequency (frequency increased from 1 to 2 in 10 secs).
If we apply online/window DMD, the learned model can track the time-varying eigenvalues very well.
Here are some hightlights about this algorithm, and for more detail please refer to this paper
pip install odmd --upgrade
Create virtual env if needed
python3 -m venv .venv
source .venv/bin/activate
Clone from github and install
git clone https://github.com/haozhg/odmd.git
cd odmd/
python3 -m pip install -e .
To run tests
cd tests/
pip install r requirements.txt
python -m pytest .
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.
Suppose we have a (discrete) nonlinear and/or time-varying dynamical system, and the state space representation is
where t is (discrete) time, z(t) is state vector.
In general, a variant of this algorithm (try pip install ai4sci.oml --upgrade
, see here) also works if we have a nonlinear and/or time-varying map
where x(t) is the input and y(t) is the output. Notice that dynamical system is a special case of nonlinear maps, by taking y(t) = z(t) and x(t) = z(t-1).
From now on, we will denote y(t) = z(t) and x(t) = z(t-1), so that the dynamical system can be written in this form
The algorithm is implemented in class OnlineDMD.
At time step t, define two matrix
that contain all the past snapshot pairs, where x(t), y(t) are the n dimensional state vector, y(t) = f(t, x(t)) is the image of x(t), f() is the dynamics. Here, if the (discrete-time) dynamics are given by z(t) = f(t, z(t-1)), then x(t), y(t) should be measurements corresponding to consecutive states z(t-1) and z(t).
We would like to learn an adaptive online linear model M (a matrix) st
The matrix M is updated in real-time when new measurement becomes available. We aim to find the best M that leads to least-squre errors.
An exponential weighting factor rho=sigma^2 (0<rho<=1) that places more weight on recent data can be incorporated into the definition of X(t) and Y(t) such that
At time t+1, the matrices become
We need to incorporate a new snapshot pair x(t+1), y(t+1) into the least-square objective function. We can update the DMD matrix A(t) online by efficient rank-1 updating online DMD algorithm.
The algorithm is implemented in class WindowDMD.
At time step t, define two matrix
that contain the recent w snapshot pairs from a finite time window, where x(t), y(t) are the n dimensional state vector, y(t) = f(t, x(t)) is the image of x(t), f() is the dynamics. Here, if the (discrete-time) dynamics are given by z(t) = f(t, z(t-1)), then x(t), y(t) should be measurements corresponding to consecutive states z(t-1) and z(t).
Similarly, we formulate this as a least-square optimization problem.
An exponential weighting factor rho=sigma^2 (0<rho<=1) that places more weight on recent data can be incorporated into the definition of X(t) and Y(t) such that
At time t+1, the data matrices become
The models needs to forget the oldest snapshot pair x(t-w+1),y(t-w+1), and remember the newest snapshot pair x(t+1),y(t+1). We can update the DMD matrix A(t) online by efficient rank-2 updating window DMD algroithm.
See demo for python notebooks.
demo_online.ipynb
shows how to use online DMD to learn adaptive online model for 2D time varying system.demo_window.ipynb
shows how to use online DMD to learn adaptive online model for 2D time varying system.Hao Zhang
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}
}
April 2017
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
.
If there is any comment/suggestion, or if you find any bug, feel free to