-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsparsifyDynamicsAlt.m
More file actions
35 lines (25 loc) · 918 Bytes
/
sparsifyDynamicsAlt.m
File metadata and controls
35 lines (25 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Xi = sparsifyDynamicsAlt(Theta,dXdt,lambda,n)
% Augmentation of the code by Steven L. Brunton
% For Paper, "Discovering Governing Equations from Data:
% Sparse Identification of Nonlinear Dynamical Systems"
% by S. L. Brunton, J. L. Proctor, and J. N. Kutz
%SVD
[U,S,V]=svd(Theta,0);
Xi = V*((U'*dXdt)./diag(S));
%Xi = pinv(Theta)*dXdt;
k = 1;
Xi_new = Xi;
% lambda is our sparsification knob.
while sum(sum(abs(Xi - Xi_new))) > 0 || k == 1
Xi = Xi_new;
smallinds = (abs(Xi)<lambda); % find small coefficients
Xi_new(smallinds)=0; % and threshold
for ind = 1:n % n is state dimension
biginds = ~smallinds(:,ind);
% Regress dynamics onto remaining terms to find sparse Xi
[U,S,V]=svd(Theta(:,biginds),0);
Xi_new(biginds,ind) = V*((U'*dXdt(:,ind))./diag(S));
end
k = k + 1;
end
Xi = Xi_new;