rbf核神经网络程序matlab程序_第1页
rbf核神经网络程序matlab程序_第2页
rbf核神经网络程序matlab程序_第3页
rbf核神经网络程序matlab程序_第4页
rbf核神经网络程序matlab程序_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

include RadialBasisNetwork h include Exception h include Matrix h include File h using namespace std namespace annie Creates a Radial basis function network All the outputs will have a bias param inputs Number of inputs taken in by the network param centers Number of centers the network has Each center will be an inputs dimensional point param outputs The number of outputs given by the neuron All of them will have a bias RadialBasisNetwork RadialBasisNetwork int inputs int centers int outputs real CenterArray 1024 Network inputs outputs int i j extern real CenterArray WORDNUM inputs centroid new real inputs Layer of input Each member is an InputNeuron InputLayer inputLayer inputLayer new InputLayer 0 inputs Number of centers in the network If you plan to extend this class then the onus of keeping this value consistent lies on you nCenters centers Layer of centers each member is a CenterNEuron centerLayer new Layer 1 for i 0 i nCenters i for j 0 j inputs j centroid j CenterArray i j CenterNeuron c new CenterNeuron Layer MAX LAYER SIZE 1 i inputs CenterNeuron c new CenterNeuron Layer MAX LAYER SIZE 1 i inputs centroid for j 0 jconnect centerLayer addNeuron c Layer of output each member if a SimpleNeuron outputLayer new Layer 2 for i 0 isetActivationFunction identity didentity for j 0 jconnect outputLayer addNeuron n Copy constructor NOT YET IMPLEMENTED RadialBasisNetwork RadialBasisNetwork RadialBasisNetwork int inputs src inputLayer getSize int centers src centerLayer getSize int outputs src outputLayer getSize inputLayer new InputLayer src inputLayer getLabel src inputLayer getSize nCenters src nCenters lbl src centerLayer getLabel centerLayer new Layer lbl for i 0 igetNeuron i c setCenter cSrc getCenter for j 0 jconnect centerLayer addNeuron c lbl src outputLayer getLabel outputLayer new Layer lbl for i 0 igetNeuron i n setBias nSrc getBias n setActivationFunction identity didentity for j 0 jaddNeuron n Loads a network from a text file see save param filename Name of the file from which to load network structure throws Exception On any error RadialBasisNetwork RadialBasisNetwork const char filename Network 0 0 File file int i j try file open filename catch Exception error error getClassName e what throw Exception error string s s file readWord if pare getClassName 0 string error getClassName error error getClassName File supplied is not about this type of network throw Exception error int maxLayerSize Layer MAX LAYER SIZE while file eof s file readWord if pare INPUTS nInputs file readInt inputLayer new InputLayer 0 nInputs else if pare OUTPUTS nOutputs file readInt outputLayer new Layer 2 for i 0 isetActivationFunction identity didentity outputLayer addNeuron n else if pare CENTERS nCenters file readInt centerLayer new Layer 1 for i 0 iaddNeuron n else if pare CENTER POINTS for i 0 igetNeuron i VECTOR center for j 0 j getInputCount j center push back file readDouble n setCenter center else if pare MAX LAYER SIZE maxLayerSize file readInt else if pare Biases for i 0 igetNeuron i if file readChar t o setBias file readDouble else o removeBias else if pare BEGIN META DATA static const basic string size type npos basic string size type 1 string end END META DATA string metaData 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 else if pare Connections Connect inputs to centers for i 0 igetNeuron i for j 0 jgetNeuron j Connect centers to outputs for i 0 igetNeuron i for j 0 jgetNeuron j file readDouble else cerr getClassName getClassName Unrecognized token s getNeuron i getCenter catch Exception error error getCenter e what throw Exception error return answer CenterNeuron catch Exception error error getCenterNeuron e what throw Exception error Returns the output of the network for the given input param input A vector of getDimension reals return The corresponding output of the network VECTOR RadialBasisNetwork getOutput VECTOR return outputLayer getOutput catch Exception e string error getClassName error error getOutput e what throw Exception error Sets the ith center point to the given point param i The center that is to be changed param center The getInputCount dimensional point void RadialBasisNetwork setCenter int i VECTOR c setCenter center catch Exception error error setCenter e what throw Exception e Sets the ith center point to the given point param i The center that is to be changed param center The getInputCount dimensional point void RadialBasisNetwork setCenter int i real center try CenterNeuron c setCenter center catch Exception error error setCenter e what throw Exception e Sets the weight between the given center and output param center Index of the center 0 center getCenterCount param output Index of the output 0 outputgetNeuron center SimpleNeuron o connect catch Exception error error setWeight e what throw Exception error Returns the weight of the link between the given center and output param center Index of the center 0 center getCenterCount param output Index of the output 0 outputgetNeuron output CenterNeuron return o getWeight catch Exception error error getWeight e what throw Exception error Sets the bias of the ith output param i The index of the output 0 igetNeuron i n setBias bias catch Exception error error setBias e what throw Exception e Returns the bias of the ith output param i The index of the output 0 igetNeuron i return n getBias catch Exception error error setBias e what throw Exception e Wrapper function to allow getOutput to work for an array of real as input as well Does exactly the same thing as Network getOutput real VECTOR RadialBasisNetwork getOutput real input return Network getOutput input const char RadialBasisNetwork getClassName return RadialBasisNetwork The number of centers in the network int RadialBasisNetwork getCenterCount return nCenters Sets the activation function of the center neurons The activation function is gaussian by default param f The activation function to be used param df The derivation of the activation function used in gradient descent training void RadialBasisNetwork setCenterActivationFunction ActivationFunction1 f RadialBasisNetwork setCenterActivationFunction ActivationFunction f ActivationFunction df int i for i 0 igetNeuron i c setActivationFunction f df c setActivationFunction f Prevents the ith output from having any bias param i The index of the output 0 igetNeuron i o removeBias catch Exception error error removeBias e what throw Exception error Trains the weights of the network centers are kept fixed param T The TrainingSet from which input desired output pairs will be obtained void RadialBasisNetwork trainWeights TrainingSet error error trainWeights Invalid TrainingSet provided throw Exception error int output int i j int p T getSize number of training patters int h getCenterCount number of centers VECTOR in y do for each output for output 0 outputgetNeuron output 为何要强制类型转换 if hasBias outNrn hasBias effectiveH setup matrices Matrix Y new Matrix p 1 存放 p 个模式下输出层各个节点的输出值 Matrix W NULL 存放权值 Matrix V new Matrix p effectiveH 存放 p 个模式各自隐节点输出值 Matrix VT NULL if p effectiveH VT new Matrix effectiveH p extern int Hidden num for i 0 i p i T getNextPair in y getOutput in for j 0 jelementAt i j centerLayer getNeuron j getOutput 为第 i j 个元 素赋值 if VT VT elementAt j i V elementAt i j if hasBias V elementAt i j 1 0 if VT VT elementAt j i 1 0 Y elementAt i 0 y output for i 0 p if VT Matrix VTVinv VTY try Matrix VTV VTV VT multiply V VTVinv VTV inverse delete VTV catch Exception error error trainWeights e what throw Exception error VTY VT multiply Y W VTVinv multiply VTY delete VTVinv delete VTY if VT else Matrix Vinv try Vinv V inverse catch Exception error error trainWeights e what throw Exception error W Vinv multiply Y delete Vinv set the weights for j 0 jelementAt j 0 if hasBias outNrn setBias W elementAt j 0 cleanup delete Y delete W delete V if VT delete VT for output 1 total outputs Save the network to a text file void RadialBasisNetwork save const char filename ofstream s int i j s open filename ios out if s string error getClassName error error save Could not open file for writing throw Exception error s ANNIE FILE ANNIE VERSION endl s Network information the next line identifies the type of network endl s Constructing a network from a file which doesn t have the following identifier endl s should result in an error endl s DO NOT MAKE FORMAT CHANGES TO THIS FILE endl s RadialBasisNetwork endl s MAX LAYER SIZE Layer MAX LAYER SIZE endl s INPUTS getInputCount endl s CENTERS getCenterCount endl s OUTPUTS getOutputCount endl s nBEGIN META DATA endl if getMetaData empty s getMetaData endl s END META DATA n endl s endl s Below follows description of the centers One center per line endl s Each center is a point in d dimensional space where d the number of inputs endl s endl s CENTER POINTS endl for i 0 igetNeuron i VECTOR center c getCenter VECTOR iterator it for it center begin it center end it s it s endl s endl s Now the biases for each of the outputs One line per output endl s Line starts with a t followed by the bias if the neuron has a bias endl s otherwise line has an f indicating no bias endl s endl s Biases endl for i 0 igetNeuron i if o hasBias s t o getBias else s f s endl s endl s Now follows the weights from

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论