matlab RBF神经网络实例

xiaoxiao2021-02-27  303

程序:

clc; clear; close all; %产生400个数据的输入与输出 ld=400; x=rand(2,ld); %0-1 x=(x-0.5)*1.5*2; %-1.5, 1.5 x1=x(1,:); x2=x(2,:); F=20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2); %创建RBF径向基网络 net=newrb(x,F); %产生测试数据 interval=0.1; %步长 [i, j]=meshgrid(-1.5:interval:1.5,-1.5:interval:1.5);%定义i、j的值域 row=size(i); %返回size的尺寸31行31列 %将i,j转换为行向量作为输入数据 tx1=i(:);%将i矩阵转换为列向量 tx1=tx1'; tx2=j(:);%将j矩阵转换为列向量 tx2=tx2'; tx=[tx1;tx2]; %testing ty=sim(net,tx); %开始测试 测试数据需要是行向量 得到测试结果ty v=reshape(ty,row); %将输出数据转换为31*31向量 以绘制三维图形 figure subplot(1,3,2) %一行3列图 的第二个位置 mesh(i,j,v); zlim([0,60]) %限制Z轴的范围 %plot the original function interval=0.1; [x1, x2]=meshgrid(-1.5:interval:1.5); F = 20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2); subplot(1,3,1) mesh(x1,x2,F); zlim([0,60]) %plot the error subplot(1,3,3) mesh(x1,x2,F-v); %误差图 zlim([0,60])

转载请注明原文地址: https://www.6miu.com/read-2854.html

最新回复(0)