% A Program to predict treated water turbidity for low turbid water
clc; close all;
%load e3.mat
%reading in the data from excel
% data = xlsread('ik2.xlsx');
data = xlsread('Hot_Air_Dry.xlsx');
input_name = str2mat('DTemp','Dvel','EUR');
%dividing the data into 3: one for training, one for checking and the other for
%verification
trn_data = data(1:1:end, :);
chk_data = data(2:2:end, :);
% separating the inputs from the output
% input_data = data(:,1:3);
% output_data= data(:,4);
%using exhaustive search for input selection
input_index = exhsrch(1, trn_data, chk_data,input_name);
% new_trn_data = trn_data(:, [input_index, size(trn_data,2)]);
% new_chk_data = chk_data(:, [input_index, size(chk_data,2)]);
% separating the inputs from the output
input_data = data(:,1:2);
output_data= data(:,3);
%predt = genfis1(trn_data, 2, 'gbellmf', 'linear');
predt = genfis2(input_data,output_data,0.6) ;
%generating the ANFIS model
%[trn_out ] = ...
% anfis(trn_data,predt, [100 nan 0.01 0.5 1.5], [0,0,0,0], chk_data, 1);
[trn_out trn_error step_size chk_out_fismat chk_error] = ...
anfis(trn_data, predt, [100 nan 0.01 0.5 1.5], ...
nan, chk_data, 1);
%plotting the membership function of the four inputs
figure(3)
plotmf(trn_out,'input',1)
figure(4)
plotmf(trn_out,'input',2)
figure(5)
%plotmf(trn_out,'input',3)
figure(6)
%plotmf(trn_out,'input',4)
%evaluating the model
output= evalfis(data(:, 1 :2 ),trn_out);
%getting th RMS error
[a, b] = min(chk_error);
figure(2);
plot(1:100, trn_error, 'g-', 1:100, chk_error, 'r-', b, a, 'ko');
title('Training (green) and checking (red) error curve');
xlabel('Epoch numbers');
ylabel('RMS errors');
% %plotting the experimental against the predicted data
exptdata = data(:,3);
figure(3)
i = 1:1: length(data);
plot(i,exptdata ,'r')
hold on
plot(i,output ,'g')
ylabel('Value')
xlabel('Experiment Number')
legend('Experitmental Data','Predicted Data')
rmse = norm(data(:,3)-output)/sqrt(length(data));
% trn_out = setfis(trn_out, 'input', 1, 'name', 'FVFAB');
% trn_out = setfis(trn_out, 'input', 2, 'name', 'GOR');
% trn_out = setfis(trn_out, 'input', 3, 'name', 'PRESSI');
% trn_out = setfis(trn_out, 'output', 1, 'name', 'FVFBB');
% % writing the fis to a file
%
% writefis(trn_out,'myFIS');
% writefis(trn_out,'myFIS');
N = size(trn_data,1);
A = [trn_data(:,1:2) ones(N,1)];
B = trn_data(:,3);
coef = A\B; % Solving for regression parameters from training data
Nc = size(chk_data,1);
A_ck = [chk_data(:,1:2) ones(Nc,1)];
B_ck = chk_data(:,3);
lr_rmse = norm(A_ck*coef-B_ck)/sqrt(Nc);
[m,b,r]=postreg(output',(data(:,3))');
chk_data = setfis(chk_out_fismat, 'input', 1, 'name', 'Drying Temperature');
chk_out_fismat = setfis(chk_out_fismat, 'input', 1, 'name', 'Drying Temperature');
chk_out_fismat = setfis(chk_out_fismat, 'input', 2, 'name', 'drying time');
%chk_out_fismat = setfis(chk_out_fismat, 'input', 1, 'name', 'Drying Temperature');
%chk_out_fismat = setfis(chk_out_fismat, 'input', 3, 'name', 'RH');
%chk_data = setfis(chk_out_fismat, 'input', 3, 'name', 'ST');
%chk_out_fismat = setfis(chk_out_fismat, 'input', 4, 'name', 'TWT');
%chk_out_fismat = setfis(chk_out_fismat, 'output', 1, 'name', 'TWT');
%Generating the FIS output surface plot
gensurf(chk_out_fismat);
评论0