自创建神经网络

自创建神经网络, 使用传递函数(激活函数)为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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值