![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
模糊神经网络matlab 10
刚刚接触MATLAB程序,下面是武世虔老师的的动态模糊神经网络的MATLAB程序,看不太明白,也不知道输入数据怎么确定,请大神指导一下啊由于程序内容较多请加我QQ:158...
刚刚接触MATLAB程序,下面是武世虔老师的的动态模糊神经网络的MATLAB程序,看不太明白,也不知道输入数据怎么确定,请大神指导一下啊 由于程序内容较多 请加我QQ:158830710 万分感谢。
function [w1,w2,width,rule,e,RMSE]=DFNN(p,t,parameters)
% This is D-FNN training program.
% Input:
% p is the input data,which is r by q matrix.
% r is the No. of input.
% t is the output data,which is s2 by q matrix.
% q is the No. of sample data.
% parameters is a vector which defines the predefined parameters
% parameters(1)=kdmax (max of accommodation criterion)
% parameters(2)=kdmin (min of accommodation criterion)
% parameters(3)=gama (decay constant)
% parameters(4)=emax (max of output error)
% parameters(5)=emin (min of output error)
% parameters(6)=beta (convergence constant)
% parameters(7)=width0 (the width of the first rule)
% parameters(8)=k (overlap factor of RBF units)
% parameters(9)=kw (width updating factor)
% parameters(10)=kerr (significance of a rule)
%Output:
% w1 is the centers of the RBF units,which is a u by r matrix
% w2 is the weights,which is s2 by u(1+r) matrix
% width is the widths of RBF units,which is a 1 by u matrix 展开
function [w1,w2,width,rule,e,RMSE]=DFNN(p,t,parameters)
% This is D-FNN training program.
% Input:
% p is the input data,which is r by q matrix.
% r is the No. of input.
% t is the output data,which is s2 by q matrix.
% q is the No. of sample data.
% parameters is a vector which defines the predefined parameters
% parameters(1)=kdmax (max of accommodation criterion)
% parameters(2)=kdmin (min of accommodation criterion)
% parameters(3)=gama (decay constant)
% parameters(4)=emax (max of output error)
% parameters(5)=emin (min of output error)
% parameters(6)=beta (convergence constant)
% parameters(7)=width0 (the width of the first rule)
% parameters(8)=k (overlap factor of RBF units)
% parameters(9)=kw (width updating factor)
% parameters(10)=kerr (significance of a rule)
%Output:
% w1 is the centers of the RBF units,which is a u by r matrix
% w2 is the weights,which is s2 by u(1+r) matrix
% width is the widths of RBF units,which is a 1 by u matrix 展开
2个回答
展开全部
您好,是这样的:
经过训练后的参数比较差,用原数据输入训练好的网络,得出结果和要的结果误差很大,不明白是怎么回事?
还有要是多输入多输出这段程序该怎么改?模糊神经网络可以用matlab工具箱实现吗?
还有输入数据差别比较大(就是大小差异大)是不是要进行归一化再学习训练呢?
求解,求解答!
对于你的帮助不胜感激!
clear all
clc
close all
tic,
%[x,y]=data;
x=[1 2 3 4 5 6 7 8;
-1 -2 -3 -4 -5 -6 -7 -8];
y=[2 3 4 5 6 7 8 9]; %%%%%--数据显示,输入为-两输入,输出为-单输出。--------样本为p2组
[p1,p2]=size(x);
% 隶属度函数个数
k=7;
% 初始化四个隶属度函数的参数A,B及输出层初始权值W
for i=1:p1;
for j=1:k;
m(i,j)=1+0.6*rand(1);
b(i,j)=1+0.6*rand(1);
end
end
for j=1:k*k;
w(j)=1+rand(1);
end
%%%---推理计算输出值
for q=1:p2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-----用同一隶属度参数对 输入样本 X 累计计算
% 选用高斯函数作为隶属度,求隶属度,共 size(x,2)+k 个。x(1) K个,x(2) K个
for i=1:p1;
for j=1:k;
u(i,j)=gaussmf(x(i,q),[m(i,j),b(i,j)]);
end
end
% 模糊推理计算:a21,a22.几个隶属度函数,得出几个值,此处已知输入为2
%%%%----由以前的取小做法改为相乘—prod(x,1) or prod(x,2)———
v=[];
for i=1:k
for j=1:k
v=[v,u(1,i)*u(2,j)];
end
end
% 归一化计算模糊推理的值;相当于已经除去了经典去模糊输出的分母值
for i=1:length(v);
v1(i)=v(i)/sum(v);
end
% 系统输出
% out1(q)=w*v';
% e(q)=(y(q)-out1(q));
% end
% out=out1
out1(q)=w*v1';
e(q)=y(q)-out1(q);
end
out=out1;
%- 三。参数修正过程。 增加方式,非批处理方式迭代
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%-----------------------------误差反向传播过程--------------------------------------------
% 取误差函数:E=(1/2)*sumsqr(t-y)
E=(1/2)*sumsqr(y-out);
EE=E;
% e=sum(y-out)
lr=0.3; % c2=zeros(2,2);
%%%%----------------------------------------误差反传后的参数修正过程-------------------
r=1; %
p=1;
s=1000; %
% e(r)=y(r)-out(r);
while p<=s & EE>0.05
%%%%%%%%%%%%%_____隶属度参数 M. B 输出层权值参数 W 的修正过程_____%%%%%%%%%%%%
%%1.--W
wc=zeros(1,k*k);
for i=1:k*k;
wc(i)=-lr*e(r)*v1(i);
end
%%2.--M
mc=zeros(p1,k);
for i=1:p1;
for j=1:k;
mc(i,j)=2*lr*e(r) * w(j) * (v(j)/u(i,j)) * exp(-((x(i,r)-m(i,j)).^2)/(b(i,j).^2))* (x(i,r)-m(i,j))/(b(i,j).^2);
end
end
%%3.--B
bc=zeros(p1,k);
for i=1:p1;
for j=1:k;
bc(i,j)=2*lr*e(r)* w(j) * (v(j)/u(i,j)) * exp(-((x(i,r)-m(i,j)).^2)/(b(i,j).^2)) * ((x(i,r)-m(i,j)).^2)/(b(i,j).^3);
end
end
% 4.参数修正 m b w
m=m-mc;
b=b-bc;
w=w-wc;
%%%%%%%%%%%_______利用修正后的参数重新计算_____________%%%%%%%%%%%%%%%%%%%%%
% 5.利用修正过的参数重新计算输出
for q=1:p2;
for i=1:p1;
for j=1:k;
u(i,j)=gaussmf(x(i,q),[m(i,j),b(i,j)]);
end
end
v=[];
for i=1:7
for j=1:7
v=[v,u(1,i)*u(2,j)];
end
end
% 归一化计算模糊推理的值;相当于已经除去了经典去模糊输出的分母值
for i=1:length(v)
v1(i)=v(i)/sum(v);
end
out1(q)=w*v1';
end
out=out1;
p=p+1;
EE=(1/2)*sumsqr(y-out);
E(p)=EE;
r=r+1;
if r>p2
r=1;
end
e(r)=(y(r)-out(r));
end
%%%%%%%%%%%%%%%%%%%________________当误差或迭代步数满足要求后得到结果_________________%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m,b,w,E_out=EE,e
epoch=1:size(E,2);
figure
plot(epoch,E,'-r');
% plot(epoch,out(1),'b');
% axis([0 1.5*s min(E) max(E)]);
% set(gca,'fontsize',8);
% set(gca,'xtick',0:s/10:1.5*s);
%set(gca,'ytick',1e-30:1e5:1e5);
%set(gcf,'color','b')
title('误差变化曲线');xlabel('步数');ylabel('误差');
toc
%% %% 泛化过程
经过训练后的参数比较差,用原数据输入训练好的网络,得出结果和要的结果误差很大,不明白是怎么回事?
还有要是多输入多输出这段程序该怎么改?模糊神经网络可以用matlab工具箱实现吗?
还有输入数据差别比较大(就是大小差异大)是不是要进行归一化再学习训练呢?
求解,求解答!
对于你的帮助不胜感激!
clear all
clc
close all
tic,
%[x,y]=data;
x=[1 2 3 4 5 6 7 8;
-1 -2 -3 -4 -5 -6 -7 -8];
y=[2 3 4 5 6 7 8 9]; %%%%%--数据显示,输入为-两输入,输出为-单输出。--------样本为p2组
[p1,p2]=size(x);
% 隶属度函数个数
k=7;
% 初始化四个隶属度函数的参数A,B及输出层初始权值W
for i=1:p1;
for j=1:k;
m(i,j)=1+0.6*rand(1);
b(i,j)=1+0.6*rand(1);
end
end
for j=1:k*k;
w(j)=1+rand(1);
end
%%%---推理计算输出值
for q=1:p2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-----用同一隶属度参数对 输入样本 X 累计计算
% 选用高斯函数作为隶属度,求隶属度,共 size(x,2)+k 个。x(1) K个,x(2) K个
for i=1:p1;
for j=1:k;
u(i,j)=gaussmf(x(i,q),[m(i,j),b(i,j)]);
end
end
% 模糊推理计算:a21,a22.几个隶属度函数,得出几个值,此处已知输入为2
%%%%----由以前的取小做法改为相乘—prod(x,1) or prod(x,2)———
v=[];
for i=1:k
for j=1:k
v=[v,u(1,i)*u(2,j)];
end
end
% 归一化计算模糊推理的值;相当于已经除去了经典去模糊输出的分母值
for i=1:length(v);
v1(i)=v(i)/sum(v);
end
% 系统输出
% out1(q)=w*v';
% e(q)=(y(q)-out1(q));
% end
% out=out1
out1(q)=w*v1';
e(q)=y(q)-out1(q);
end
out=out1;
%- 三。参数修正过程。 增加方式,非批处理方式迭代
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%-----------------------------误差反向传播过程--------------------------------------------
% 取误差函数:E=(1/2)*sumsqr(t-y)
E=(1/2)*sumsqr(y-out);
EE=E;
% e=sum(y-out)
lr=0.3; % c2=zeros(2,2);
%%%%----------------------------------------误差反传后的参数修正过程-------------------
r=1; %
p=1;
s=1000; %
% e(r)=y(r)-out(r);
while p<=s & EE>0.05
%%%%%%%%%%%%%_____隶属度参数 M. B 输出层权值参数 W 的修正过程_____%%%%%%%%%%%%
%%1.--W
wc=zeros(1,k*k);
for i=1:k*k;
wc(i)=-lr*e(r)*v1(i);
end
%%2.--M
mc=zeros(p1,k);
for i=1:p1;
for j=1:k;
mc(i,j)=2*lr*e(r) * w(j) * (v(j)/u(i,j)) * exp(-((x(i,r)-m(i,j)).^2)/(b(i,j).^2))* (x(i,r)-m(i,j))/(b(i,j).^2);
end
end
%%3.--B
bc=zeros(p1,k);
for i=1:p1;
for j=1:k;
bc(i,j)=2*lr*e(r)* w(j) * (v(j)/u(i,j)) * exp(-((x(i,r)-m(i,j)).^2)/(b(i,j).^2)) * ((x(i,r)-m(i,j)).^2)/(b(i,j).^3);
end
end
% 4.参数修正 m b w
m=m-mc;
b=b-bc;
w=w-wc;
%%%%%%%%%%%_______利用修正后的参数重新计算_____________%%%%%%%%%%%%%%%%%%%%%
% 5.利用修正过的参数重新计算输出
for q=1:p2;
for i=1:p1;
for j=1:k;
u(i,j)=gaussmf(x(i,q),[m(i,j),b(i,j)]);
end
end
v=[];
for i=1:7
for j=1:7
v=[v,u(1,i)*u(2,j)];
end
end
% 归一化计算模糊推理的值;相当于已经除去了经典去模糊输出的分母值
for i=1:length(v)
v1(i)=v(i)/sum(v);
end
out1(q)=w*v1';
end
out=out1;
p=p+1;
EE=(1/2)*sumsqr(y-out);
E(p)=EE;
r=r+1;
if r>p2
r=1;
end
e(r)=(y(r)-out(r));
end
%%%%%%%%%%%%%%%%%%%________________当误差或迭代步数满足要求后得到结果_________________%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m,b,w,E_out=EE,e
epoch=1:size(E,2);
figure
plot(epoch,E,'-r');
% plot(epoch,out(1),'b');
% axis([0 1.5*s min(E) max(E)]);
% set(gca,'fontsize',8);
% set(gca,'xtick',0:s/10:1.5*s);
%set(gca,'ytick',1e-30:1e5:1e5);
%set(gcf,'color','b')
title('误差变化曲线');xlabel('步数');ylabel('误差');
toc
%% %% 泛化过程
![](https://ecmc.bdimg.com/public03/b4cb859ca634443212c22993b0c87088.png)
2024-06-26 广告
通过视频孪生技术能够:构建实时、动态孪生场景的实时实景整体态势孪生一张图,所见即所得,实现业务时空一体化管理,从而解决传统视频监控数据面临的:信息割裂、数据孤岛、缺少统一表达和空间协同计算的问题。依托视频孪生底座已经完成的的部分行业项目案例...
点击进入详情页
本回答由智汇云舟提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询