www.pudn.com > ELM.rar > ELM_MultiOutputRegression.m, change:2004-10-23,size:5059b


function [TrainingTime, TestingTime, TrainingAccuracy, TestingAccuracy] = elm_MultiOutputRegression(TrainingData_File, TestingData_File, No_of_Output, NumberofHiddenNeurons, ActivationFunction) 
 
% Usage: elm-MultiOutputRegression(TrainingData_File, TestingData_File, No_of_Output, NumberofHiddenNeurons, ActivationFunction) 
% OR:    [TrainingTime, TestingTime, TrainingAccuracy, TestingAccuracy] = elm-MultiOutputRegression(TrainingData_File, TestingData_File, No_of_Output, NumberofHiddenNeurons, ActivationFunction) 
% 
% Input: 
% TrainingData_File     - Filename of training data set 
% TestingData_File      - Filename of testing data set 
% No_of_Output          - Number of outputs for regression 
% NumberofHiddenNeurons - Number of hidden neurons assigned to the ELM 
% ActivationFunction    - Type of activation function: 
%                           'sig' for Sigmoidal function 
%                           'sin' for Sine function 
%                           'hardlim' for Hardlim function 
% 
% Output:  
% TrainingTime          - Time (seconds) spent on training ELM 
% TestingTime           - Time (seconds) spent on predicting ALL testing data 
% TrainingAccuracy      - Training accuracy:  
%                           RMSE for regression 
% TestingAccuracy       - Testing accuracy:  
%                           RMSE for regression 
 
% 
    %%%%    Authors:    MR QIN-YU ZHU AND DR GUANG-BIN HUANG 
    %%%%    NANYANG TECHNOLOGICAL UNIVERSITY, SINGAPORE 
    %%%%    EMAIL:      EGBHUANG@NTU.EDU.SG; GBHUANG@IEEE.ORG 
    %%%%    WEBSITE:    http://www.ntu.edu.sg/eee/icis/cv/egbhuang.htm 
    %%%%    DATE:       APRIL 2004 
 
%%%%%%%%%%% Load training dataset 
train_data=load(TrainingData_File); 
T=train_data(:,1:No_of_Output)'; 
P=train_data(:,No_of_Output+1:size(train_data,2))'; 
clear train_data;                                   %   Release raw training data array 
 
%%%%%%%%%%% Load testing dataset 
test_data=load(TestingData_File); 
TV.T=test_data(:,1:No_of_Output)'; 
TV.P=test_data(:,No_of_Output+1:size(test_data,2))'; 
clear test_data;                                    %   Release raw testing data array 
 
NumberofTrainingData=size(P,2); 
NumberofTestingData=size(TV.P,2); 
NumberofInputNeurons=size(P,1); 
 
%%%%%%%%%%% Calculate weights & biases 
start_time_train=cputime; 
 
%%%%%%%%%%% Random generate input weights InputWeight (w_i) and biases BiasofHiddenNeurons (b_i) of hidden neurons 
InputWeight=rand(NumberofHiddenNeurons,NumberofInputNeurons)*2-1; 
BiasofHiddenNeurons=rand(NumberofHiddenNeurons,1); 
tempH=InputWeight*P; 
clear P;                                            %   Release input of training data  
ind=ones(1,NumberofTrainingData); 
BiasMatrix=BiasofHiddenNeurons(:,ind);              %   Extend the bias matrix BiasofHiddenNeurons to match the demention of H 
tempH=tempH+BiasMatrix; 
 
%%%%%%%%%%% Calculate hidden neuron output matrix H 
switch lower(ActivationFunction) 
    case {'sig','sigmoid'} 
        %%%%%%%% Sigmoid  
        H = 1 ./ (1 + exp(-tempH)); 
    case {'sin','sine'} 
        %%%%%%%% Sine 
        H = sin(tempH);     
    case {'hardlim'} 
        %%%%%%%% Hard Limit 
        H = hardlim(tempH);             
        %%%%%%%% More activation functions can be added here                 
end 
clear tempH;                                        %   Release the temparary array for calculation of hidden neuron output matrix H 
 
%%%%%%%%%%% Calculate output weights OutputWeight (beta_i) 
OutputWeight=pinv(H') * T'; 
end_time_train=cputime; 
TrainingTime=end_time_train-start_time_train        %   Calculate CPU time (seconds) spent for training ELM 
 
%%%%%%%%%%% Calculate the training accuracy 
Y=(H' * OutputWeight)';                             %   Y: the actual output of the training data 
TrainingAccuracy=sqrt(mse(T - Y))               %   Calculate training accuracy (RMSE) for regression case 
clear H; 
 
%%%%%%%%%%% Calculate the output of testing input 
start_time_test=cputime; 
tempH_test=InputWeight*TV.P; 
clear TV.P;             %   Release input of testing data              
ind=ones(1,NumberofTestingData); 
BiasMatrix=BiasofHiddenNeurons(:,ind);              %   Extend the bias matrix BiasofHiddenNeurons to match the demention of H 
tempH_test=tempH_test + BiasMatrix; 
switch lower(ActivationFunction) 
    case {'sig','sigmoid'} 
        %%%%%%%% Sigmoid  
        H_test = 1 ./ (1 + exp(-tempH_test)); 
    case {'sin','sine'} 
        %%%%%%%% Sine 
        H_test = sin(tempH_test);         
    case {'hardlim'} 
        %%%%%%%% Hard Limit 
        H_test = hardlim(tempH_test);         
        %%%%%%%% More activation functions can be added here         
end 
TY=(H_test' * OutputWeight)';                       %   TY: the actual output of the testing data 
end_time_test=cputime; 
TestingTime=end_time_test-start_time_test           %   Calculate CPU time (seconds) spent by ELM predicting the whole testing data 
 
TestingAccuracy=sqrt(mse(TV.T - TY))            %   Calculate testing accuracy (RMSE) for regression case