BP神经网络实验报告.doc_第1页
BP神经网络实验报告.doc_第2页
BP神经网络实验报告.doc_第3页
BP神经网络实验报告.doc_第4页
BP神经网络实验报告.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

深 圳 大 学 实 验 报 告实验课程名称: 人工神经网络技术 实验项目名称: BP神经网络对蝴蝶花分类 学院: 专业: 软件工程 报告人: 学号: 班级: 同组人: 无 指导教师: 实验时间: 实验报告提交时间: 教务处制一、 实验目的初步熟悉MATLAB 工作环境,熟悉命令窗口,学会使用帮助窗口查找帮助信息。二、 实验内容1、网络设计,包括输入层、隐含层、输出层节点个数的设计。 2、算法步骤 3、编程,注意原始数据的通用化,数据输入的随机性。 4、网络训练,注意训练数据与验证数据分开。 5、网络验证 6、结果分析,修改隐含层节点个数,修改学习率,分别对结果的影响。三、实验步骤直接在Matlab软件中的Editor中运行以下代码:(完善的代码用红色字体表示)% li.m% A BP NN with momentum to solve Fishers Iris Flower problem% by lixiujuan, Nov 13, 2011% the NN architecture% it is a three layers neural network 4-3-3.% parameter description% h=4 the node numer of input layer% i=3 the node numer of hidden layer% j=3 the node numer of output layer% Vh,i the weights between input and hidden layers% Wi,j the weights between hidden and output layers% Pii the thresholds of hidden layer nodes% Tauj the thresholds of output layer nodes% ah the input values% bi the hidden layer node activations% cj the output layer node activations% ckj the desired output of output layer nodes% dj the eror in output layer nodes% ei the eror in hidden layer nodes% DeltaWi,j the amount of change for the weights Wi,j% DeltaVh,i the amount of change for the weights Vh,i% DeltaPii the amount of change for the thresholds Pii% DeltaTauj the amount of change for the thresholds Tauj% Alpha=0.1 the leaning rate% Beta=0.1 the leaning rate% Gamma=0.8 the constant determines effect of past weight changes% Tor=0.001 the torrelance that determines when to stop training% Maxepoch=1000 the max iterate number% other parameters% Ntrain=115 the number of trainning sets% Ntest=35 the number of test sets% Otrain115 the output of training sets% Otest35 the output of test sets% Odesired150 the desired output of training and test sets% function description% f(x)=logsig(x)% f(x)=1/(1+exp(-x)% data file% input file: data.dat%close all; clc; clf; clear all;% parameters for the NN structureh=4;i=3;j=3;Alpha=0.1;Beta=0.1;Gamma=0.85;Tor=0.0005;Maxepoch=2000;Accuracy=0;Ntrain=115;Ntest=35;%assign random values in the range -1, +1V=2*(rand(h,i)-0.5);W=2*(rand(i,j)-0.5);Pi=2*(rand(1,i)-0.5);Tau=2*(rand(1,j)-0.5);DeltaWOld(i,j)=0; %set the delat of Wij to 0DeltaVOld(h,i)=0; %set the delat of Vij to 0DeltaPiOld(i)=0; %set the delat of Pi to 0DeltaTauOld(j)=0; %set the delat of Tau to 0% the learning processEpoch=1;Error=10;% load the training set data and test set dataload data.datOdesired=data(:,2); % get the desired of output of 150 data sets% normalize the input data to rang -1 +1datanew=data(:,3:6);maxv=max(max(datanew);minv=min(min(datanew);datanorm=2*(datanew-minv)/(maxv-minv)-0.5);while ErrorTorErr(Epoch)=0;for k=1:Ntrain % k = the index of tranning seta=datanorm(k,:); % get the input% set the desired output ckjif data(k,2)=0ck=1 0 0;elseif data(k,2)=1ck=0 1 0;elseck=0 0 1;end;% calculate the hidden nodes activationfor ki=1:ib(ki)=logsig(a*V(:,ki)+Pi(ki);end;% calculate the output nodes activationfor kj=1:jc(kj)=logsig(b*W(:,kj)+Tau(kj);end;% calculate error in output Layer FCd=c.*(1-c).*(ck-c);% calculate error in hidden layer FBe=b.*(1-b).*(d*W);% adjust weights Wij between FB and FCfor ki=1:ifor kj=1:jDeltaW(ki,kj)=Alpha*b(ki)*d(kj)+Gamma*DeltaWOld(ki,kj);endend;W=W+DeltaW;DeltaWOld=DeltaW;% adjust weights Vij between FA and FBfor kh=1:hfor ki=1:iDeltaV(kh,ki)=Beta*a(kh)*e(ki);endend;V=V+DeltaV;DeltaVold=DeltaV;% adjust thresholds Pi and TauDeltaPi=Beta*e+Gamma*DeltaPiOld;Pi=Pi+DeltaPi;DeltaPiold=DeltaPi;DeltaTau=Alpha*d+Gamma*DeltaTauOld;Tau=Tau+DeltaTau;DeltaTauold=DeltaTau;% the error is the max of d(1),d(2),d(3)Err(Epoch)=Err(Epoch)+0.5*(d(1)*d(1)+d(2)*d(2)+d(3)*d(3);end %for k=1:NtrainErr(Epoch)=Err(Epoch)/Ntrain;Error=Err(Epoch);% the training stops when iterate is too muchif Epoch Maxepochbreak;endEpoch = Epoch +1; % update the iterate numberend% test datafor k=1:Ntest % k = the index of test seta=datanorm(Ntrain+k,:); % get the input of test sets% calculate the hidden nodes activationfor ki=1:ib(ki)=logsig(a*V(:,ki)+Pi(ki);end;% calculate the output of test setsfor kj=1:jc(kj)=logsig(b*W(:,kj)+Tau(kj);end;% transfer the output to one field formatif (c(1) 0.9)Otest(k)=0;elseif (c(2) 0.9)Otest(k)=1;elseif (c(3) 0.9)Otest(k)=2;elseOtest(k)=3;end;% calculate the accuracy of test setsif Otest(k)=Odesired(Ntrain+k)Accuracy=Accuracy+1;end;end; % k=1:Ntest% plot the errorplot(Err);% plot the NN output and desired output during testN=1:Ntest;figure; plot(N,Otest,b-,N,Odesired(116:150),r-);% display the accuracyAccuracy = 100*Accuracy/Ntest;t=TESTING RESULT, the accuracy of test sets is: num2str(Accuracy) % ;disp(t);当中间隐藏层结点数为i=3时,得出下图:当Alpha=0.08;Beta=0.08时;如下图:当Alpha=0.05;Beta=0.05时;如下图:当Alpha=0.2;Beta=0.2时;如下图:当Alpha=0.3;Beta=0.3时;如下图:当Alpha=0.2;Beta=0.3时;如下图:当Alpha=0.3;Beta=0.2时;如下图:当中间隐藏层结点数为i=4时,得出下图:当中间隐藏层结点数为i=2时,得出下图:当Alpha=0.05;Beta=0.05时;如下图:当中间隐藏层结点数为i=1时,得出下图:四、总结分析 由于对MATLAB的不熟悉,一开始还是不知道怎么完成这个实验,但是在同学的帮助下,渐渐懂得怎么导入数据和代码实现,进而了解怎么样使用BP神经网络来进行蝴蝶花的分类。通过修改中间隐藏层的结点数,进行对比,发现i=3以及i=4的时候所得到的图是一样的,说明在i大于等于3的时候,实验结果误差较小以至于可以忽略不计,又进行了一次i=2的实验,结果发现结果也是几乎一样的,再进行进一步的实验,将i改为1,发现期望输出与实际输出存在明显区别,到后期才重合。所以,我觉得在这次的实验中,中间隐藏层结点数需要大于等于2比较合适。还有就是学习率的问题,刚开始实验,就只是改了隐藏节点,而忽略了学习率的问题。所以在原来的基础上,有改动了一下学习率,发现Figure1还是有很大地变动的,但是Figure2反而没什么不同。我觉得学习率的范围应该在0.1以内的。可是还是不知道学习率具体是起什么作用的。这次实验还是大概的完成了,但是对MATLAB还是有一些不懂的地方,仍需在接下来的实验中继续学习。指导教师批阅意见:实

温馨提示

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

评论

0/150

提交评论