自创建神经网络
自创建神经网络, 使用传递函数(激活函数)为logsig(S型对数函数)。具体实现如下:
%自创建神经网络
P=[-3,2];
T=[0.4,0.8];
Wrange=-4:0.4:4;
Brange=-4:0.4:4; %W值的行向量、B值的行向量
ES=errsurf(P,T,Wrange,Brange,'logsig'); %求单神经元的误差平面(只用在单神经元中)
%Error surface of single input neuron
% errsurf(P,T,WV,BV,F) takes these arguments,
% P -- 1 x Q matrix of input vectors
% T -- 1 x Q matrix of target vectors
% WV -- Row vector of values of W
% BV -- Row vector of values of B
% F -- Transfer function (string)
% and returns a matrix of error values over WV and BV.
mesh(ES,[60,30]); %作三维网状面,视角【60,30】
title('Error Surface Graph') %标题
xlabel('W')
ylabel('B')
zlabel('Sum Squared Error')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%华丽分割线
max_epoch=1500; %赋最大训练次数
err=[];
xx=[];
yy=[]; %定义矩阵
lr=0.5;
W1=-4*rand(1); %赋权值和偏差的初值
b1=-4*rand(1);
x1=W1;
y1=b1;
for i=1:max_epoch
A1 = logsig(W1*P b1*ones(1,2)); %计算输出
% Log sigmoid transfer function
%
% logsig is a transfer function. Transfer functions calculate a layer's output from its net input.
% logsig(N) takes one input,
% N -- S x Q matrix of net input (column) vectors
% and returns each element of N squashed between 0 and 1.
% logsig(code) returns useful information for each code string:
% 'deriv' -- Name of derivative function
% 'name' -- Full name
% 'output' -- Output range
% 'active' -- Active input range
E = T-A1; %求误差
D1 = A1.*(1-A1).*E; %矩阵对应元素相乘
dW1 = D1*P'*lr; %求权值增量
db1 = D1*ones(2,1)*lr; %求偏差增量
newx = W1(1,1) dW1(1,1); %新的权值
W1(1,1) = newx;
xx =[xx newx];
newy = b1(1) db1(1); %新的偏差
b1(1) = newy;
yy =[yy newy];
SSE = sumsqr(E); %求误差平方和
err=[err SSE];
if (SSE<1e-8)
break;
end
end
figure(2)
[C,h] =contour(Wrange,Brange,ES); %作等高线图,ES为高
%返回等高线矩阵C,列向量h是线或对象的句柄,一条线一个句柄,这些被用作CLABEL的输入,
%每个对象包含每个等高线的高度
%A contour graph displays isolines of matrix Z. Label the contour lines using clabel
% contour(X,Y,Z,n), and contour(X,Y,Z,v) draw contour plots of Z.
% X and Y specify the x- and y-axis limits. When X and Y are matrices,
%they must be the same size as Z, in which case they specify a surface,
%as defined by the surf function.
% If X or Y is irregularly spaced,
% contour calculates contours using a regularly spaced contour grid,
% then transforms the data to X or Y.
clabel(C,h) %标上高度值
colormap cool %背景的颜色cool
axis('equal')
hold on
plot(x1,y1,'r ')
plot(xx,yy,'b*') %作矩阵变化曲线
hold off
figure(3)
plot(err) %作误差曲线
err
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhiaijki
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22 -
excel打印预览压线压字怎么办
PHP中文网 06-22