I created a ZIP file which has the word document for both the Training and Testing data on there. In the training program, start from the "% clear engine cycle opsset sensor" part and ignore everything above and replace it with "clear all" and "load('test_FD002.txt')" like in the testing program. Make sure to place the training and testing data in notepad and save as a txt file.
Training and Testing data for GRNN
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a training program and a testing program for a Generalized Regression Neural Network.
The result of the training program is the same as the input which it should be. The final answer is "poutput". After the row of percent signs, I have the testing program. For some reason, all 259 values for one row are the same (which it sould not be and the values for all rows should be different). I'm not sure if it is something to do with the program or something I did.
%% Using train_FD002 dataset, 1) Cluster Data, 2) Fit Exp Model 3) Train Network
% Load training data structure
clear all %#ok<CLALL>
load('train_FD002_eng')
%% ~~ K-Means Separation - trainFD002~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%% Merge All trainFD002 Data and Cluster by Operational Setting
opsset_groups = [];
for i = 1:length(train_FD002_eng) % One for each engine
engine = i*ones(length(train_FD002_eng(i).cycle),1);
cycle = train_FD002_eng(i).cycle;
opsset = train_FD002_eng(i).opsset;
sensor = train_FD002_eng(i).sensor;
opsset_groups = [opsset_groups; engine cycle opsset sensor]; %#ok<AGROW>
end; clear i
idx = kmeans(opsset_groups(:,3:5),6);
% clear engine cycle opsset sensor
%% Reassemble into Structure by Clusters
for i=1:max(idx) % #clusters
train_FD002_clust(i).eng = opsset_groups(idx==i,1); %#ok<SAGROW>
train_FD002_clust(i).cycle = opsset_groups(idx==i,2); %#ok<SAGROW>
train_FD002_clust(i).opsset = opsset_groups(idx==i,3:5); %#ok<SAGROW>
train_FD002_clust(i).sensor = opsset_groups(idx==i,6:26); %#ok<SAGROW>
end
% clear i idx opsset_groups
%% Plot Clustered Data
for i=1:6
plotCMAPPS(train_FD002_clust(i),['FD002 Cluster ', num2str(i),' Data']);
end; clear i
%% ~~Generate Best Fit Exponential for Each Engine~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%% Sensors that display Ae^(Bt)+C behavior (health indicies) (11)
HI = [2 3 4 7 8 9 11 12 13 14 17];
% Generalized exponential function
expfun = @(C,cyc)C(1)*exp(C(2)*cyc)+C(3);
%% Preallocate Cell Array for Fit Parameters
C_all = cell(6,1); % A separate cell for each cluster
% C_all contains ( EngineNumber(260) x FitParameters(3) x HIs(11) )
for i=1:6; C_all{i} = zeros(260,3,length(HI)); end; clear i
%% Fit Ae^(Bt)+C for each engine trajectory
fail_cycle = zeros(260,6); % Array containing final cycles for each engine
opts = optimset('Display','off'); % supress lsqcurvefit output
for i=1:6 % each cluster (6)
tic
for j=1:260 % each engine (260)
all_eng_j = train_FD002_clust(i).eng==j; % indecies for just engine j
cycle = train_FD002_clust(i).cycle(all_eng_j); % extract engine j cycles
fail_cycle(j,i) = max(cycle); % record failure cycle
for k=1:length(HI) % each HI sensor (11)
sensor = train_FD002_clust(i).sensor(all_eng_j,HI(k)); % extract sensor data
C = lsqcurvefit(expfun,[0 0 0],cycle,sensor,[-1000 0 0],[],opts); % determine exponential fit parameters
C_all{i}(j,:,k) = C; % add to library of fit paramters
end
end
toc
end; clear i j k
fail_cycle1 = max(fail_cycle,[],2);
% clear m opts all_eng_j C cycle sensor
%% Overlay Exponential Fits on Cluster Plots
for i=1:6 % each cluster (6)
for j=1:length(HI) % each HI (11)
figure(i); subplot(5,5,3+HI(j)) % focus on sensor axis
y_lim = ylim; % extract y-axis limits
for k=1:260 % each engine (260)
fitline = expfun(C_all{i}(k,:,j),0:400); % best fit exp points
plot(0:400,fitline,'g') % plot best fit exp points
end
ylim(y_lim) % reset y-axis limits
end
end; clear i j k
% clear fitline y_lim HI expfun
%% Use data for a General Regression Neural Network
for i=1:6
for j=1:11
Input=(C_all{i,1}(:,:,j))';
Target=fail_cycle1';
Input_all{i,j}=Input;
Norm_all{i,j}=Target;
end
end
for i=1:6
for j=1:11
input_all{i,1}=[Input_all{i,1};Input_all{i,2};Input_all{i,3};...
Input_all{i,4};Input_all{i,5};Input_all{i,6};Input_all{i,7};...
Input_all{i,8};Input_all{i,9};Input_all{i,10};Input_all{i,11}];
target_all{i,1}=Norm_all{i,1};
end
end
%Create Neural Networks of all Health Indicators for all 6 Clusters.
net1=newgrnn(input_all{1,1},target_all{1,1},0.01);
net2=newgrnn(input_all{2,1},target_all{2,1},0.01);
net3=newgrnn(input_all{3,1},target_all{3,1},0.01);
net4=newgrnn(input_all{4,1},target_all{4,1},0.01);
net5=newgrnn(input_all{5,1},target_all{5,1},0.01);
net6=newgrnn(input_all{6,1},target_all{6,1},0.01);
chrisnet1=net1;
chrisnet2=net2;
chrisnet3=net3;
chrisnet4=net4;
chrisnet5=net5;
chrisnet6=net6;
save chrisnet1
save chrisnet2
save chrisnet3
save chrisnet4
save chrisnet5
save chrisnet6
poutput1=sim(chrisnet1,input_all{1,1});
poutput2=sim(chrisnet2,input_all{2,1});
poutput3=sim(chrisnet3,input_all{3,1});
poutput4=sim(chrisnet4,input_all{4,1});
poutput5=sim(chrisnet5,input_all{5,1});
poutput6=sim(chrisnet6,input_all{6,1});
poutput={poutput1;poutput2;poutput3;poutput4;poutput5;poutput6};
for i=1:6
HI=[Norm_all(1,1);Norm_all(1,2);Norm_all(1,3);Norm_all(1,4);...
Norm_all(1,5);Norm_all(1,6);Norm_all(1,7);Norm_all(1,8);...
Norm_all(1,9);Norm_all(1,10);Norm_all(1,11)];
HI_sensor{i,1}=cell2mat(HI);
%Measure Absolute Errors
Errors=(poutput{i,1}-HI_sensor{i,1});
Squared_Error=Errors.^2;
MSE=mean(Errors.^2); %Mean Squared Error
RMSE(i,:)=sqrt(MSE); %Root Mean Squared Error. Horizontal
%indicates 260 points for each induvidual sensor measurement for
%all six clusters
end
% clear i j k Errors fail_cycle1 Input MSE NormFact NormInputt poutput Target
% clear Squared_Error TargetFact TargetNorm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Using test_FD002.txt, 1) Cluster Data, 2) Fit Exp Model 3) Test Network
% Load testing data structure. "t" denotes testing values
clear all %#ok<CLALL>
opsset_groupst=load('test_FD002.txt');
RUL=load('RUL_FD002.txt');
%load neural networks
load chrisnet1
load chrisnet2
load chrisnet3
load chrisnet4
load chrisnet5
load chrisnet6
%% Run kmeans and reassemble into clusters
idxt = kmeans(opsset_groupst(:,3:5),6);
for i=1:max(idxt) % #clusters
test_FD002_clustt(i).eng = opsset_groupst(idxt==i,1); %#ok<SAGROW>
test_FD002_clustt(i).cycle = opsset_groupst(idxt==i,2); %#ok<SAGROW>
test_FD002_clustt(i).opsset = opsset_groupst(idxt==i,3:5); %#ok<SAGROW>
test_FD002_clustt(i).sensor = opsset_groupst(idxt==i,6:26); %#ok<SAGROW>
end
% clear i idxt opsset_groupst
%% Plot Clustered Data
for i=1:6
plotCMAPPS(test_FD002_clustt(i),['FD002 Cluster ', num2str(i),' Data']);
end; clear i
%% ~~Generate Best Fit Exponential for Each Engine~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%% Sensors that display Ae^(Bt)+C behavior (health indicies) (11)
HIt = [2 3 4 7 8 9 11 12 13 14 17];
% Generalized exponential function
expfunt = @(Ct,cyc)Ct(1)*exp(Ct(2)*cyc)+Ct(3);
%% Preallocate Cell Array for Fit Parameters
C_allt = cell(6,1); % A separate cell for each cluster
% C_all contains ( EngineNumber(260) x FitParameters(3) x HIs(11) )
for i=1:6; C_allt{i} = zeros(259,3,length(HIt)); end; clear i
%% Fit Ae^(Bt)+C for each engine trajectory
fail_cyclet = zeros(259,6); % Array containing final cycles for each engine
optst = optimset('Display','off'); % supress lsqcurvefit output
for i=1:6 % each cluster (6)
tic
for j=1:259 % each engine (259)
all_eng_jt = test_FD002_clustt(i).eng==j; % indecies for just engine j
cyclet = test_FD002_clustt(i).cycle(all_eng_jt); % extract engine j cycles
if length(cyclet)<3; continue; end % check for at least 3 cycles
fail_cyclet(j,i) = max(cyclet); % record failure cycle
for k=1:length(HIt) % each HI sensor (11)
sensort = test_FD002_clustt(i).sensor(all_eng_jt,HIt(k)); % extract sensor data
Ct = lsqcurvefit(expfunt,[0 0 0],cyclet,sensort,[-1000 0 0],[],optst); % determine exponential fit parameters
C_allt{i}(j,:,k) = Ct; % add to library of fit paramters
end
end
toc
end; clear i j k
fail_cycle1t = max(fail_cyclet,[],2);
% fail_cycle1t=fail_cycle1t+RUL;
% clear mt optst all_eng_jt Ct cycle sensort
%% Overlay Exponential Fits on Cluster Plots
for i=1:6 % each cluster for testing data only(6)
for j=1:length(HIt) % each HI (11)
figure(i); subplot(5,5,3+HIt(j)) % focus on sensor axis
y_limt = ylim; % extract y-axis limits
for k=1:259 % each engine (259)
fitlinet = expfunt(C_allt{i}(k,:,j),0:400); % best fit exp points
plot(0:400,fitlinet,'g') % plot best fit exp points
end
ylim(y_limt) % reset y-axis limits
end
end; clear i j k
% clear fitlinet y_limt HIt expfunt
%% Use data for a General Regression Neural Network
for i=1:6
for j=1:11
Inputt=(C_allt{i,1}(:,:,j))';
Targett=fail_cycle1t';
Input_allt{i,j}=Inputt;
Norm_allt{i,j}=Targett;
end
end
for i=1:6
for j=1:11
input_allt{i,1}=[Input_allt{i,1};Input_allt{i,2};Input_allt{i,3};...
Input_allt{i,4};Input_allt{i,5};Input_allt{i,6};Input_allt{i,7};...
Input_allt{i,8};Input_allt{i,9};Input_allt{i,10};Input_allt{i,11}];
target_allt{i,1}=Norm_allt{i,1};
end
end
%input testing data
poutput1t=sim(chrisnet1,input_allt{1,1});
poutput2t=sim(chrisnet2,input_allt{2,1});
poutput3t=sim(chrisnet3,input_allt{3,1});
poutput4t=sim(chrisnet4,input_allt{4,1});
poutput5t=sim(chrisnet5,input_allt{5,1});
poutput6t=sim(chrisnet6,input_allt{6,1});
poutputt={poutput1t;poutput2t;poutput3t;poutput4t;poutput5t;poutput6t};
for i=1:6
HIt=[Norm_allt(1,1);Norm_allt(1,2);Norm_allt(1,3);Norm_allt(1,4);...
Norm_allt(1,5);Norm_allt(1,6);Norm_allt(1,7);Norm_allt(1,8);...
Norm_allt(1,9);Norm_allt(1,10);Norm_allt(1,11)];
HI_sensort{i,1}=cell2mat(HIt);
%Measure Absolute Errors
Errorst=(poutputt{i,1}-HI_sensort{i,1});
Squared_Errort=Errorst.^2;
MSEt=mean(Errorst.^2); %Mean Squared Error
RMSEt(i,:)=sqrt(MSEt); %Root Mean Squared Error. Horizontal
%indicates 260 points for each induvidual sensor measurement for
%all six clusters
end
poutputt_full=cell2mat(poutputt);
fout=mean(poutputt_full);
% clear i j k Errors fail_cycle1 Input MSE NormFact NormInputt poutput Target
% clear Squared_Error TargetFact TargetNorm
Risposte (0)
Vedere anche
Categorie
Scopri di più su Classification in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!