您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > rbf核神经网络程序matlab程序
#includeRadialBasisNetwork.h#includeException.h#includeMatrix.h#includeFile.husingnamespacestd;namespaceannie{/**CreatesaRadialbasisfunctionnetwork.Alltheoutputswillhaveabias.*@paraminputsNumberofinputstakeninbythenetwork*@paramcentersNumberofcentersthenetworkhas.Eachcenterwillbe*aninputs-dimensionalpoint*@paramoutputsThenumberofoutputsgivenbytheneuron.Allofthemwillhave*abias*/RadialBasisNetwork::RadialBasisNetwork(intinputs,intcenters,intoutputs,real(*CenterArray)[1024]):Network(inputs,outputs){inti,j;//externrealCenterArray[WORDNUM][inputs];centroid=newreal[inputs];///Layerofinput.EachmemberisanInputNeuron//InputLayer*_inputLayer;_inputLayer=newInputLayer(0,inputs);/**Numberofcentersinthenetwork.*Ifyouplantoextendthisclass,thentheonusofkeepingthisvalue*consistentliesonyou*/_nCenters=centers;///Layerofcenters,eachmemberisaCenterNEuron_centerLayer=newLayer(1);for(i=0;i_nCenters;i++){for(j=0;jinputs;j++){centroid[j]=CenterArray[i][j];}//CenterNeuron*c=newCenterNeuron(Layer::MAX_LAYER_SIZE*1+i,inputs);CenterNeuron*c=newCenterNeuron(Layer::MAX_LAYER_SIZE*1+i,inputs,centroid);for(j=0;jinputs;j++){c-connect(&_inputLayer-getNeuron(j));}_centerLayer-addNeuron(c);}///Layerofoutput,eachmemberifaSimpleNeuron_outputLayer=newLayer(2);for(i=0;ioutputs;i++){SimpleNeuron*n=newSimpleNeuron(Layer::MAX_LAYER_SIZE*2+i,true);n-setActivationFunction(identity,didentity);for(j=0;jcenters;j++)n-connect(&_centerLayer-getNeuron(j));_outputLayer-addNeuron(n);}}///Copyconstructor,NOTYETIMPLEMENTEDRadialBasisNetwork::RadialBasisNetwork(RadialBasisNetwork&src):Network(src){inti,j,lbl;intinputs=src._inputLayer-getSize();intcenters=src._centerLayer-getSize();intoutputs=src._outputLayer-getSize();_inputLayer=newInputLayer(src._inputLayer-getLabel(),src._inputLayer-getSize());_nCenters=src._nCenters;lbl=src._centerLayer-getLabel();_centerLayer=newLayer(lbl);for(i=0;icenters;i++){CenterNeuron*c=newCenterNeuron(Layer::MAX_LAYER_SIZE*lbl+i,inputs);CenterNeuron&cSrc=(CenterNeuron&)src._centerLayer-getNeuron(i);c-setCenter(cSrc.getCenter());for(j=0;jinputs;j++)c-connect(&_inputLayer-getNeuron(j));_centerLayer-addNeuron(c);}lbl=src._outputLayer-getLabel();_outputLayer=newLayer(lbl);for(i=0;ioutputs;i++){SimpleNeuron*n=newSimpleNeuron(Layer::MAX_LAYER_SIZE*lbl+i);SimpleNeuron&nSrc=(SimpleNeuron&)src._outputLayer-getNeuron(i);n-setBias(nSrc.getBias());n-setActivationFunction(identity,didentity);for(j=0;jcenters;j++){throwException(RadialBasisNetwork::RadialBasisNetwork()-Copyconstructornotfullyimplemented);}_outputLayer-addNeuron(n);}}/**Loadsanetworkfromatextfile*@seesave*@paramfilenameNameofthefilefromwhichtoloadnetworkstructure*@throwsExceptionOnanyerror*/RadialBasisNetwork::RadialBasisNetwork(constchar*filename):Network(0,0){Filefile;inti,j;try{file.open(filename);}catch(Exception&e){stringerror(getClassName());error=error+::+getClassName()+()-+e.what();throwException(error);}strings;s=file.readWord();if(s.compare(getClassName())!=0){stringerror(getClassName());error=error+::+getClassName()+()-Filesuppliedisnotaboutthistypeofnetwork.;throwException(error);}intmaxLayerSize=Layer::MAX_LAYER_SIZE;while(!file.eof()){s=file.readWord();if(!s.compare(INPUTS)){_nInputs=file.readInt();_inputLayer=newInputLayer(0,_nInputs);}elseif(!s.compare(OUTPUTS)){_nOutputs=file.readInt();_outputLayer=newLayer(2);for(i=0;igetOutputCount();i++){SimpleNeuron*n=newSimpleNeuron(maxLayerSize*2+i,true);n-setActivationFunction(identity,didentity);_outputLayer-addNeuron(n);}}elseif(!s.compare(CENTERS)){_nCenters=file.readInt();_centerLayer=newLayer(1);for(i=0;igetCenterCount();i++){CenterNeuron*n=newCenterNeuron(maxLayerSize*1+i,getInputCount());_centerLayer-addNeuron(n);}}elseif(!s.compare(CENTER_POINTS)){for(i=0;igetCenterCount();i++){CenterNeuron&n=(CenterNeuron&)_centerLayer-getNeuron(i);VECTORcenter;for(j=0;jgetInputCount();j++)center.push_back(file.readDouble());n.setCenter(center);}}elseif(!s.compare(MAX_LAYER_SIZE))maxLayerSize=file.readInt();elseif(!s.compare(Biases)){for(i=0;igetOutputCount();i++){if(file.eof())break;SimpleNeuron&o=(SimpleNeuron&)_outputLayer-getNeuron(i);if(file.readChar()=='t')o.setBias(file.readDouble());elseo.removeBias();}}elseif(!s.compare(BEGIN_META_DATA)){staticconstbasic_stringchar::size_typenpos=(basic_stringchar::size_type)-1;stringend(END_META_DATA);stringmetaData;s=file.readLine();while(s.find(end,0)==npos){metaData=metaData+s+\n;s=file.readLine();}if(metaData.length()0)metaData.erase(metaData.length()-1);setMetaData(metaData);}elseif(!s.compare(Connections)){//Connectinputstocentersfor(i=0;igetCenterCount();i++){CenterNeuron&c=(CenterNeuron&)_centerLayer-getNeuron(i);for(j=0;jgetInputCount();j++)c.connect(&_inputLayer-getNeuron(j));}//Connectcenterstooutputsfor(i=0;igetOutputCount();i++){SimpleNeuron&o=(SimpleNeuron&)_outputLayer-getNeuron(i);for(j=0;jgetCenterCount();j++)o.connect(&_centerLayer-getNeuron(j),file.readDouble());}}elsecerrgetClassName()::getClassName()()-Unr
本文标题:rbf核神经网络程序matlab程序
链接地址:https://www.777doc.com/doc-5090926 .html