www.pudn.com > orth_qr.zip > orth_qr.m
function [TrainingTime, TrainingAccuracy, TestingAccuracy]=orth_qr(TrainingData_File, TestingData_File, NumberofHiddenNeurons, ActivationFunction, Problem_Type)
% How to run like this : orth_qr( 'abalone_train', 'abalone_test', 10, 'sig', 0);
% chenlei
REGRESSION = 0;
CLASSIFIER = 1;
%%%%%%%%%%% Load training dataset
train_data=load(TrainingData_File);
T=train_data(:,1)';
I=train_data(:,2:size(train_data,2))';
clear train_data; % Release raw training data array
%%%%%%%%%%% Load testing dataset
test_data=load(TestingData_File);
t_testing=test_data(:,1)';
x_testing=test_data(:,2:size(test_data,2))';
clear test_data;
NumberofTrainingData=size(I,2);
NumberofTestingData=size(x_testing,2);
NumberofInputNeurons=size(I,1);
NumberofOutputNeurons=size(T,1);
if Problem_Type~=REGRESSION
%%%%%%%%%%%% Preprocessing the data of classification
sorted_target=sort(cat(2,T,t_testing),2);
label=zeros(1,1); % Find and save in 'label' class label from training and testing data sets
label(1,1)=sorted_target(1,1);
j=1;
for i = 2:(NumberofTrainingData+NumberofTestingData)
if sorted_target(1,i) ~= label(1,j)
j=j+1;
label(1,j) = sorted_target(1,i);
end
end
number_class=j;
NumberofOutputNeurons=number_class;
%%%%%%%%%% Processing the targets of training
temp_T=zeros(NumberofOutputNeurons, NumberofTrainingData);
for i = 1:NumberofTrainingData
for j = 1:number_class
if label(1,j) == T(1,i)
break;
end
end
temp_T(j,i)=1;
end
T = temp_T*2-1;
%%%%%%%%%% Processing the targets of testing
temp_TV_T=zeros(NumberofOutputNeurons, NumberofTestingData);
for i = 1:NumberofTestingData
for j = 1:number_class
if label(1,j) == t_testing(1,i)
break;
end
end
temp_TV_T(j,i)=1;
end
t_testing = temp_TV_T*2-1;
end
clear temp_T;
% Q=zeros(NumberofTrainingData,NumberofTrainingData);
Htrainout=zeros(NumberofTrainingData,NumberofHiddenNeurons);
InputWeight=zeros(NumberofInputNeurons,NumberofHiddenNeurons);
HiddenBias=zeros(1,NumberofHiddenNeurons);
L=0;
starting_cpu=cputime;
%%%%%%%%%%%%%%% Train matrix %%%%%%%%
while L1
y1=0;
elseif x1>0
y1=1-x1;
else
y1=x1+1;
end
case {'hardlim'}
%%%%%%%% Hardlimit
x1=w'*x+b;
y1=sign(x1);
case {'gau'}
%%%%%%%% Gaussian
x1=w'*x+b;
y1=exp(-x1.^2);
case {'sig','sigmoid'}
%%%%%%%% Sigmoid
bias_vector = b*ones(1,size(x,2));
y1=1./(1+exp(-(w'*x+bias_vector)));
case {'windows'}
%%%%%%%% windows
x1=w'*x+b;
traina = x1<=1;
trainb = x1>=-1;
y1 = traina.*trainb+0.0001;
%%%%%%%% More activation functions can be added here
end