% bowl -- 3D display of error surface in weight space for LMS learning.
load LmsPat.dat;
load LmsAns.dat;
Patterns = LmsPat';
Desired = LmsAns';
NINPUTS = size(Patterns,1);
NPATS = size(Patterns,2);
NUNITS = size(Desired,1);
Inputs = [ones(1,NPATS); Patterns];
InitWeights = rand(NUNITS,1+NINPUTS)*2 - 1.5; % bias weights for larger error
Weights = InitWeights;
LearnRate = 0.142; % any larger than this, and the weights diverge
colordef none, clf reset
axpat=subplot(1,2,2); hold on
PlotLmsPats(Patterns,Desired);
% Calculate and plot the error surface
fprintf('Calculating the error surface...');
w0range = -0.5:0.025:1.0;
w1range = -0.5:0.05:2.5;
w0range = -1:0.025:1.0;
w1range = -1:0.05:3;
[xm,ym] = meshgrid(w0range,w1range);
zm = 0*xm;
W = Weights;
for i = 1:size(xm,1)
for j = 1:size(ym,2)
W(1,1:2) = [xm(i,j) ym(i,j)];
zm(i,j) = tss(W,Inputs,Desired);
end
end
disp('');
axbowl = subplot(1,2,1);
contour3(xm,ym,zm,50,'b');
hold on; axis([w0range(1) w0range(end) w1range(1) w1range(end) 0 max(zm(:))])
view (60,14); %view(220,50);
grid off, box on
xlabel('w0'); ylabel('w1'); zlabel('TSS'); title('Error Surface')
set(gca,'CameraViewAngleMode','manual')
rotate3d off, rotate3d on
prevW = Weights;
prevTSS = tss(prevW,Inputs,Desired);
plot3(prevW(1,1),prevW(1,2),prevTSS,'or');
drawnow
TSS = prevTSS;
oldTSS = Inf;
% Main loop of the LMS algorithm
for i = 1:500,
if rem(i-1,9) == 0
subplot(axpat)
PlotLmsFn(Weights);
subplot(axbowl);
plot3([prevW(1,1) Weights(1,1)],[prevW(1,2) Weights(1,2)],[prevTSS TSS],'-r');
plot3(Weights(1,1),Weights(1,2),TSS,'or');
pause(0.5)
prevW = Weights; prevTSS = TSS;
end
NetIn = Weights * Inputs;
Result = NetIn;
Error = Result - Desired;
TSS = sum(sum(Error.^2));
fprintf('Epoch %.0f: ',i);
fprintf('TSS = %6.5f\n',TSS);
if abs(TSS-oldTSS) < 0.0001
subplot(axpat);
PlotLmsPats(Patterns,Desired,1);
PlotLmsFn(Weights,[1 1 1]);
break;
end;
oldTSS = TSS;
dW = - Error * Inputs';
Weights = Weights + LearnRate * dW;
end
感知器算法Matlab源码
5星 · 超过95%的资源 需积分: 49 78 浏览量
2012-03-15
09:30:34
上传
评论 6
收藏 17KB RAR 举报
aiyatnnd
- 粉丝: 2
- 资源: 16
最新资源
- 【代码】RT1021-100P MicroPython固件使用例程.7z
- springboot176基于Spring Boot的装饰工程管理系统.rar
- springboot171社区医院管理系统.rar
- 1251+1255.pdf
- springboot169基于vue的工厂车间管理系统的设计.rar
- springboot168基于springboot + vue的疫情隔离管理系统.rar
- 高校人事管理系统.zip
- ACM比赛算法:ACM 树同构-比赛常用的算法
- Python课程大作业二手车价格预测案例数据挖掘源码+数据集+实验报告+详细注释.zip
- springboot167基于springboot的医院后台管理系统的设计与实现.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页