This repository contains codes for reconstructing dynamical systems using the least square method.
Suppose, the problem is to find a description of a continuous dynamical system in a form of an autonomous odrinary differential equation:
Let us have a number of sample points of the trajectiory
Suppose, every line of a function
where
For example, we have a recorded three-dimensional trajectory
We randomly select some sample points, shown green-yellow in the middle pane, and reconstruct sparse, readable equations of the system:
Then, we can solve this reconstructed system with a standard matlab solver like ode45
. Such a solution is shown yellow in the right pane.
Download a zip file or via git, switch present working directory to ODERECON directory and run setup
script with argument path
. This step will add all necessary paths for correct script execution.
>> setup path
Present working directory can be obtained with pwd
command. Check whether the output is like .../ODERECON
, where ...
substitutes your archive unpack folder.
If you want, save path not to execute the script next time:
>> setup path
>> savepath %optional
Script file setup
was made to simplify the operations. Command setup
has specific syntax:
setup arg...
Argument arg
can be one of those values:
path
- adding all necessary paths for scripts execution;octave
- setting environment variable for GNU Octave support;format
- settingformat short g
for numeric output.
Example: if you are using GNU Octave instead of Matlab, you can set paths by running setup
script with two parameters like this:
>> setup path octave
Let us find the equations of the Lorenz system. First, generate a full trajectory with a stepsize
%simulate Lorenz system
Tmax = 45;
h = 0.01;
[t,y] = ode45(@Lorenz,[0:h:Tmax],[0.1,0,-0.1]); %solve ODE
w = transpose(Lorenz(0,transpose(y))); %find derivatives
Then, select
%get uniformly distributed points from the simulated attractor
N = 19; %data points
M = 3; %dimension
[Ns, ~] = size(y); %get the number of data point
W = zeros(N,M); %sample derivatives
Y = zeros(N,M); %sample phase coordinates
for i = 1:N %take random points from trajectory
id = ceil(rand*Ns);
W(i,:) = w(id,:);
Y(i,:) = y(id,:);
end
After that, we can obtain the Lorenz equations from these PolyRegression
to obtain two cell arrays
dmax = 2; % maximum power of the monomial
[H,T] = PolyRegression(Y,W,dmax);
To show the reconstruction result, we use a function prettyABM
:
prettyABM(H,T)
which outputs into the console:
f1 = -10*x1 + 10*x2
f2 = 28*x1 - x2 - x1*x3
f3 = -2.6667*x3 + x1*x2
Then, we can simulate the results using a function oderecon
:
[~,y] = ode45(@(t,x)oderecon(H,T,t,x),[0:h:Tmax],[0.1,0,-0.1]); %solve ODE
First, introduce some formalism. Representation of an arbitrary
On the first stage of the algorithm, for each line, full matrices
Ordering deglexord(dmin,dmax,M)
. Sparse reconstruction of the equations needs eliminating all excessive terms in
Suppose, we have a trajectory
First, the approximate Buchberger-Moller (ABM) algorithm runs, which excludes all monomials in
[~, O] = ApproxBM(Y, eps, sigma); %use approximate Buchberger-Moller algorithm
Roughly speaking, vanishing means that the monomial takes values near zero on the entire set ApproxBM
returns a border basis as the first unused argument, and an order ideal O
. The latter is utilized as an initial guess for
Then, a time comes for a simple trick to find EvalPoly(chi,Y,tau)
is used to estimate a value returned by the function described with a pair EvalPoly
returns a matrix
E = EvalPoly(eye(L),X,tau);
This matrix is used for estimating
[Q,R] = qr(E);
Q1 = Q(:,1:L);
R1 = R(1:L,1:L);
chi = R1\(Q1'*V);
If we do not need a sparse regression, the code stops its work. Otherwise, a function delMinorTerms
runs for each dimension:
%Use LSM for fitting the equations with the proper coefficients
H = cell(1,M);
T = cell(1,M);
%reconstruct each equation
for i = 1:M
V = W(:,i);
[chi,tau] = delMinorTerms(Y,V,O,eta); %get equation and basis
H{1,i} = chi;
T{1,i} = tau;
end
The function delMinorTerms(Y,V,O,eta)
estimates coefficients by each monomial as shown before, and then evaluates the contribution of this monomial to the whole function on the set 1/N*norm(V - EvalPoly(chi,Y,tau)) <= eta
, i.e. the normalized error between the values of the reconstructed function and real values is not greater than eta
, the current term which contribution is the lowest is removed from the regression, new
Optionally, iteratively reweighted least squares (IRLS) method can be used instead of an ordinary LSM, or the LASSO regression, which in some cases gives more sparse solution.
The described algorithm is implemented in the function PolyRegression
.
For reconstructing ODE systems using orthogonal polynomials we introduce some new MATLAB functions and matrix forms.
Description of all used matrices and functions in a simple form is represented in the following scheme:
Some examples provided are stored in examples
directory. For detailed explanation see EXAMPLES.md file.
The ApproxBM
and delMinorTerms
functions are written following pseudocodes provided in the work
Kera, H.; Hasegawa, Y. Noise-tolerant algebraic method for reconstruction of nonlinear dynamical systems. Nonlinear Dynamics 2016, 85(1), 675-692, https://doi.org/10.1007/s11071-016-2715-3
If you use this code or its parts in scientific work, please, cite the following papers:
-
Karimov, A.; Nepomuceno, E.G.; Tutueva, A.; Butusov, D. Algebraic Method for the Reconstruction of Partially Observed Nonlinear Systems Using Differential and Integral Embedding. Mathematics 2020, 8, 300. https://doi.org/10.3390/math8020300
-
Karimov, A.; Rybin, V.; Kopets, E.; Karimov, T.; Nepomuceno, E.; Butusov, D. Identifying empirical equations of chaotic circuit from data. Nonlinear Dyn. 2023, 111:871–886 https://doi.org/10.1007/s11071-022-07854-0
MIT License