Skip to content

Commit 58dd9d6

Browse files
authored
Add files via upload
1 parent a8fd9ef commit 58dd9d6

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
%% This file will swipe the noise level
2+
clc;clear all;close all;
3+
%% First load the noise and simulation data
4+
load('GeneratedNoise.mat')
5+
addpath("Result")
6+
addpath("Functions")
7+
%% Define the parameters for the WeakSINDy_AG
8+
% Library order
9+
polyorder=2;
10+
usesine=0;
11+
12+
% Optimization parameter
13+
gamma=0;
14+
tau = 1;
15+
16+
% Number of test function
17+
K = 200;
18+
19+
% Test function order
20+
poly = 14;
21+
22+
% Test function support size
23+
s = 31;
24+
r_whm = 8;
25+
26+
% Parameters for the WeakSINDy
27+
wsindy_params = {s, K, poly, tau};
28+
29+
% Define the thresholding parameters
30+
lam=linspace(0.01,0.95,30);
31+
lamNum=length(lam);
32+
33+
% Define a matrix to store the values
34+
Theta_test=poolData(x_test,stateVar,polyorder,usesine);
35+
Xi0=zeros(lamNum,size(Theta_test,2),stateVar);
36+
TestingScore=zeros(lamNum,1);
37+
SuccessOrNot_WS=zeros(N_run,NoiseNum);
38+
Xi_WS=zeros(lamNum,size(Theta_test,2),stateVar);
39+
40+
% Store the parameter error
41+
Eparm_WS=zeros(N_run,NoiseNum);
42+
43+
Xi_base=[-10,28,0;
44+
10,-1,0;
45+
0,0,-8/3;
46+
0,0,0;
47+
0,0,1;
48+
0,-1,0;
49+
0,0,0;
50+
0,0,0;
51+
0,0,0];
52+
%% Next run a for loop to test each noise level
53+
pin=0;
54+
55+
for i=1:N_run
56+
fprintf(strcat("This is the run:",string(i),"\n"))
57+
for j=1:NoiseNum
58+
fprintf(strcat("\t","Using noise level as: ",string(NoisePercentageToSwipe(j)),"\n"))
59+
pin=pin+1;
60+
% Get the observation data
61+
xes=squeeze(xes_List(pin,:,:));
62+
Theta=poolData(xes,stateVar,polyorder,usesine);
63+
64+
% Swipe the thresholding parameter
65+
parfor k=1:lamNum
66+
fprintf(strcat("\t\t","Swiping lambda, using lambda as: ",string(lam(k)),"\n"))
67+
68+
% Get the result for current lam
69+
Xi0(k,:,:)=WeakSINDy_AG(t,xes,Theta,stateVar,lam(k),gamma,r_whm,wsindy_params);
70+
71+
% Calculate the error on the test data
72+
TestingScore(k,1)=norm(dx_test-Theta_test*squeeze(Xi0(k,:,:)))/norm(dx_test);
73+
74+
end
75+
76+
% Test whether the structure of the model is correct
77+
for k=1:lamNum
78+
if norm((Xi_base~=0)-(squeeze(Xi0(k,:,:))~=0))==0
79+
SuccessOrNot_WS(i,j)=1;
80+
Xi_dummy=squeeze(Xi0(k,:,:));
81+
Xi_WS(pin,:,:)=Xi_dummy;
82+
end
83+
end
84+
85+
% If no model has the correct structure, choose the model that has
86+
% lowest testing error as final model
87+
if SuccessOrNot_WS(i,j)==0
88+
% Now select the best Xi
89+
[minVal,index]=min(TestingScore);
90+
91+
% Store the current result
92+
Xi_dummy=squeeze(Xi0(index,:,:));
93+
Xi_WS(pin,:,:)=Xi_dummy;
94+
end
95+
96+
% Store the parameter error
97+
Eparm_WS(i,j)=norm(Xi_base-Xi_dummy)/norm(Xi_base);
98+
99+
end
100+
end
101+
102+
%% Save the results
103+
Ep_WS_01=Eparm_WS;
104+
SuccessOrNot_WS_01=SuccessOrNot_WS;
105+
106+
%save ("Result\W_SINDy_dt_01.mat","Ep_WS_01","SuccessOrNot_WS_01")

0 commit comments

Comments
 (0)