神经网络elm算法

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

function[TrainingTime,TestingTime,TrainingAccuracy,TestingAccuracy]=elm(TrainingData_File,TestingData_File,Elm_Type,NumberofHiddenNeurons,ActivationFunction)%Usage:elm(TrainingData_File,TestingData_File,Elm_Type,NumberofHiddenNeurons,ActivationFunction)%OR:[TrainingTime,TestingTime,TrainingAccuracy,TestingAccuracy]=elm(TrainingData_File,TestingData_File,Elm_Type,NumberofHiddenNeurons,ActivationFunction)%%Input:%TrainingData_File-Filenameoftrainingdataset%TestingData_File-Filenameoftestingdataset%Elm_Type-0forregression;1for(bothbinaryandmulti-classes)classification%NumberofHiddenNeurons-NumberofhiddenneuronsassignedtotheELM%ActivationFunction-Typeofactivationfunction:%'sig'forSigmoidalfunction%'sin'forSinefunction%'hardlim'forHardlimfunction%'tribas'forTriangularbasisfunction%'radbas'forRadialbasisfunction(foradditivetypeofSLFNsinsteadofRBFtypeofSLFNs)%%Output:%TrainingTime-Time(seconds)spentontrainingELM%TestingTime-Time(seconds)spentonpredictingALLtestingdata%TrainingAccuracy-Trainingaccuracy:%RMSEforregressionorcorrectclassificationrateforclassification%TestingAccuracy-Testingaccuracy:%RMSEforregressionorcorrectclassificationrateforclassification%%MULTI-CLASSECLASSIFICATION:NUMBEROFOUTPUTNEURONSWILLBEAUTOMATICALLYSETEQUALTONUMBEROFCLASSES%FOREXAMPLE,ifthereare7classesinall,therewillhave7output%neurons;neuron5hasthehighestoutputmeansinputbelongsto5-thclass%%Sample1regression:[TrainingTime,TestingTime,TrainingAccuracy,TestingAccuracy]=elm('sinc_train','sinc_test',0,20,'sig')%Sample2classification:elm('diabetes_train','diabetes_test',1,20,'sig')%%%%%Authors:MRQIN-YUZHUANDDRGUANG-BINHUANG%%%%NANYANGTECHNOLOGICALUNIVERSITY,SINGAPORE%%%%EMAIL:EGBHUANG@NTU.EDU.SG;GBHUANG@IEEE.ORG%%%%WEBSITE::APRIL2004%%%%%%%%%%%MacrodefinitionREGRESSION=0;CLASSIFIER=1;%%%%%%%%%%%Loadtrainingdatasettrain_data=load(TrainingData_File);T=train_data(:,1)';P=train_data(:,2:size(train_data,2))';cleartrain_data;%Releaserawtrainingdataarray%%%%%%%%%%%Loadtestingdatasettest_data=load(TestingData_File);TV.T=test_data(:,1)';TV.P=test_data(:,2:size(test_data,2))';cleartest_data;%ReleaserawtestingdataarrayNumberofTrainingData=size(P,2);NumberofTestingData=size(TV.P,2);NumberofInputNeurons=size(P,1);ifElm_Type~=REGRESSION%%%%%%%%%%%%Preprocessingthedataofclassificationsorted_target=sort(cat(2,T,TV.T),2);label=zeros(1,1);%Findandsavein'label'classlabelfromtrainingandtestingdatasetslabel(1,1)=sorted_target(1,1);j=1;fori=2:(NumberofTrainingData+NumberofTestingData)ifsorted_target(1,i)~=label(1,j)j=j+1;label(1,j)=sorted_target(1,i);endendnumber_class=j;NumberofOutputNeurons=number_class;%%%%%%%%%%Processingthetargetsoftrainingtemp_T=zeros(NumberofOutputNeurons,NumberofTrainingData);fori=1:NumberofTrainingDataforj=1:number_classiflabel(1,j)==T(1,i)break;endendtemp_T(j,i)=1;endT=temp_T*2-1;%%%%%%%%%%Processingthetargetsoftestingtemp_TV_T=zeros(NumberofOutputNeurons,NumberofTestingData);fori=1:NumberofTestingDataforj=1:number_classiflabel(1,j)==TV.T(1,i)break;endendtemp_TV_T(j,i)=1;endTV.T=temp_TV_T*2-1;end%endifofElm_Type%%%%%%%%%%%Calculateweights&biasesstart_time_train=cputime;%%%%%%%%%%%RandomgenerateinputweightsInputWeight(w_i)andbiasesBiasofHiddenNeurons(b_i)ofhiddenneuronsInputWeight=rand(NumberofHiddenNeurons,NumberofInputNeurons)*2-1;BiasofHiddenNeurons=rand(NumberofHiddenNeurons,1);tempH=InputWeight*P;clearP;%Releaseinputoftrainingdataind=ones(1,NumberofTrainingData);BiasMatrix=BiasofHiddenNeurons(:,ind);%ExtendthebiasmatrixBiasofHiddenNeuronstomatchthedementionofHtempH=tempH+BiasMatrix;%%%%%%%%%%%CalculatehiddenneuronoutputmatrixHswitchlower(ActivationFunction)case{'sig','sigmoid'}%%%%%%%%SigmoidH=1./(1+exp(-tempH));case{'sin','sine'}%%%%%%%%SineH=sin(tempH);case{'hardlim'}%%%%%%%%HardLimitH=double(hardlim(tempH));case{'tribas'}%%%%%%%%TriangularbasisfunctionH=tribas(tempH);case{'radbas'}%%%%%%%%RadialbasisfunctionH=radbas(tempH);%%%%%%%%MoreactivationfunctionscanbeaddedhereendcleartempH;%ReleasethetempararyarrayforcalculationofhiddenneuronoutputmatrixH%%%%%%%%%%%CalculateoutputweightsOutputWeight(beta_i)OutputWeight=pinv(H')*T';%slowerimplementation%OutputWeight=inv(eye(size(H,1))/C+H*H')*H*T';%fastermethod1%implementation;onecansetregularizaitonfactorCproperlyinclassificationapplications%OutputWeight=(eye(size(H,1))/C+H*H')\H*T';%fastermethod2%implementation;onecansetregularizaitonfactorCproperlyinclassificationapplications%Ifyouusefastermethodsorkernelmethod,PLEASECITEinyourpaperproperly:%Guang-BinHuang,HongmingZhou,XiaojianDing,andRuiZhang,ExtremeLearningMachineforRegressionandMulti-ClassClassification,submittedtoIEEETransactionsonPatternAnalysisandMachineIntelligence,October2010.end_time_train=cputime;TrainingTime=end_time_train-start_time_train%CalculateCPUtime(seconds)spentfortrainingELM%%%%%%%%%%%CalculatethetrainingaccuracyY=(H'*OutputWeight)';%Y:theactualoutputofthetrainingdataifElm_Type==REGRESSIONTrainingAccuracy=sqrt(mse(T-Y))%Calculatetrainingaccuracy(RMSE)forregressionca

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功