forked from mikhailpt/smartpid-toolbox-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentSmartPID.m
70 lines (61 loc) · 2.57 KB
/
identSmartPID.m
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function identSmartPID(trainDataName, testDataName, bDoGridSearch, app)
%% load data to table
data1_table = readtable(trainDataName,...
'Delimiter', 'tab', 'ReadVariableNames', false);
data2_table = readtable(testDataName,...
'Delimiter', 'tab', 'ReadVariableNames', false);
dt = 1;
data1 = iddata(data1_table.Var2, data1_table.Var3, dt);
data2 = iddata(data2_table.Var2, data2_table.Var3, dt);
if bDoGridSearch
%% construct model
nk = 1;%3;
fileID = fopen('data\feed_forward_net_fit_data.txt','w');
fprintf(fileID, '');
for size1 = 2:6
%for size2 = 2:6
for na = 1:1:6
for nb = 1:1:6
net_params = size1;%[size1 size2];
model_params = [na nb nk];
disp(net_params)
disp(model_params)
net = feedforwardnet(net_params);
fprintf(fileID,'%d\t%d\t', net_params);
net_estimator = neuralnet(net);
model = nlarx(data1, model_params, net_estimator);
fprintf(fileID,'%d\t%d\t%d\t', model_params);
[data1_sim, data1_fit, data1_y0] = compare(data1, model);
[data2_sim, data2_fit, data2_y0] = compare(data2, model);
disp([data1_fit data2_fit])
fprintf(fileID,'%f\t%f\r\n', data1_fit, data2_fit);
if app.stop == true
disp('stopped by user request');
return;
end
end
end
%end
end
fclose(fileID);
end
% chose the best model structure
fitData = dlmread('data\feed_forward_net_fit_data.txt');%,...//'D:\piv\matlab_nets\ps\data-2018-11-08-19-45-39.txt'
% 'Delimiter', 'tab', 'ReadVariableNames', false);
columns = size(fitData, 2);
fitData(:,columns + 1) = fitData(:,columns - 1) + fitData(:,columns);
fitDataSorted = sortrows(fitData, columns + 1, 'descend');
disp(fitDataSorted(1,:));
net_params = fitDataSorted(1,1);
model_params = [fitDataSorted(1,2) fitDataSorted(1,3) fitDataSorted(1,4)];
net = feedforwardnet(net_params);
%view(net)
net_estimator = neuralnet(net);
model = nlarx(data1, model_params, net_estimator);
disp(getreg(model));
%gensim(gensim(model.Nonlinearity.Network))
%[a1, a2, a3] = compare(data2, model)
disp(model);
assignin('base','model',model);
save('models\model','model');
end