单层神经网络补充程序
%init 神经网络的初始化
net=init(net);
net=newp([0,1;-2,2],1); % 创建感知器
net.iw{1,1}; % 创建时的权值{i,j} 从第j个输入到到第i层的权重的权重矩阵
% ans =
%
% 0 0
net.b{1} % 创建时的偏置
% ans =
%
% 0
P=[0,1,0,1;0,0,1,1] % 训练输入向量
% P =
%
% 0 1 0 1
% 0 0 1 1
T=[0,0,0,1] % 训练输入向量的期望输出
% T =
%
% 0 0 0 1
net=train(net,P,T); % 训练
net.iw{1,1} % 训练后的权值
% ans =
%
% 1 2
net.b{1} % 训练后的偏置
% ans =
%
% -3
net=init(net); % 初始化
net.iw{1,1} % 初始化后的权值
% ans =
%
% 0 0
net.b{1} % 初始化后的偏置
% ans =
%
% 0
net.initFcn % net.initFcn值
% ans =
%
% initlay
net.initParam % 当net.initFcn= initlay时,net.initParam自动为空所以系统报错
% SWITCH expression must be a scalar or string constant.
%
% Error in network/subsref (line 140)
% switch (subs)
平均绝对误差函数mae(mse sse)
%% 清理
clear,clc
close all
%% adapt感知器
% 创建感知器
net=newp([-1,2;-2,2],1);%向量维数2*1 单个神经元
% 定义训练向量
P={[0;0] [0;1] [1;0] [1;1]}; %按照纵向输入
T={0,0,1,1}; %期望值
% 进行调整
[net,y,ee,pf] = adapt(net,P,T); %net 网络 y 输出值 ee 网格误差pf 延迟
ma=mae(ee)
ite=0;
while ma>=0.15 %误差大于0.15 进行重新训练网络
[net,y,ee,pf] = adapt(net,P,T,pf);
ma=mae(ee)
newT=sim(net,P)
ite=ite+1;
if ite>=10 %训练10次停止
break;
end
end
误差表达式