%% [NN]: MATLAB Code for Neural Network function rul=NN(TransFunc,nh,outliCrite) clear global; global DegraUnit TimeUnit time y thres signiLevel ns ny nt %=== PROBLEM DEFINITION 1 (Required Variables) ============== WorkName=' '; % work results are saved by WorkName DegraUnit=' '; % degradation unit TimeUnit=' '; % time unit (Cycles, Weeks, etc.) time=[ ]'; %[cv]: time at both measurement and prediction y=[ ]'; %[ny x 1]: measured data nT= ; % num. of training set including the current one nt=[ ]';%[nT x 1]: num. of training data in each training set thres= ; % threshold (critical value) degraTrue=[ ]'; %[cv]: true values of degradation signiLevel= ; % significance level for C.I. and P.I. ns= ; % number of repetition for NN process %=== PROBLEM DEFINITION 2 (Training Matrix) ================= xTrain=[ ]; yTrain=[ ]; %============================================================ % % % PROGNOSIS using NN ny=length(y); for i=1:ns; %% NN Process disp(['repetition: ' num2str(i) '/' num2str(ns)]); % create FFNN net=feedforwardnet(nh); net.layers.transferfcn=TransFunc; net.divideParam.valRatio=0.3; net.divideParam.testRatio=0; % train FFNN [netModel,trainRecod]=train(net,xTrain',yTrain'); %=== PROBLEM DEFINITION 2 (Input Matrix for Prediction) ===== for k=1:length(time(ny:end)); %% Degradation Prediction xNew=[ ]; zHat(k,i)=sim(netModel,xNew'); end; %============================================================ end z1=zHat(end,:); %% Prediction Results Regulation loca1=find(abs(z1-mean(z1)) < outliCrite*std(z1)); i0=1; for i=1:ns; if y(1)-y(nt(1))>0; z2=wrev(zHat(:,i)); else z2=zHat(:,i); end; if issorted(z2)==1; loca2(i0)=i; i0=i0+1; end end loca=intersect(loca1,loca2); %% Final Results degraPredi=zHat(:,loca); ns=size(degraPredi,2); disp(['Final num. of samples: ' num2str(ns)]) % % % POST-PROCESSING rul=POST([],degraPredi,degraTrue); %% RUL & Result Disp Name=[WorkName ' at ' num2str(time(ny)) '.mat']; save(Name); end