⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simufunc.m

📁 我ANN的大作业
💻 M
字号:
function FunApprox()%获取训练样本target_T = zeros(10,1);unit = 9;for i = 0:unit    for j= 0:unit        index = i*unit+j+1;        input_P(index,1) = 0.1*i;        input_P(index,2) = 0.1*j;        target_T(index) = f(input_P(index,:));    endendinput_Ptarget_Ttest_T = zeros(10,1);unit = 99;for i = 0:unit    for j= 0:unit        index = i*unit+j+1;        test_P(index,1) = 0+0.01*i;        test_P(index,2) = 0+0.01*j;        test_T(index) = f(test_P(index,:));    endend%训练三层神经网络,隐藏层有6个单元eps = 0.05;alpha = 0.1;initU1 = [0.43 0.54           0.23 0.54           0.54 0.54           0.53 0.22           0.15 0.98          0.67 0.23 ];initV1 = [0.43 0.56           0.24 0.5           0.54 0.26           0.76 0.87           0.26 0.38          0.38 0.48 ];initb1 = [0.42;0.23;0.31;0.43;0.42;0.34];initU2 = [0.5 0.55 0.32 0.21 0.23 0.6];initV2 = [0.4 0.32 0.52 0.36 0.14 0.9];initb2 = [0.1];[u1,u2, v1, v2, b1, b2, times] = MLP(eps, initU1, initV1, initb1, initU2, initV2, initb2 , alpha, input_P, target_T)%验证神经网络的正确性len = length(test_T);correct = 0;for i=1:len    x0 = test_P(i,:)';    x1 = sigmoid(u1*(x0.^2) + v1*x0 + b1);    x2 = sigmoid(u2*(x1.^2) + v2*x1 + b2);    if(abs(x2-test_T(i))<=eps)        correct = correct+1;    end    test_T(i) = x2;endcorrectRate = correct/len;len = length(test_P);actualZ = zeros(10,1);for i=1:len    actualZ(i) = f(test_P(i,:));endfigureplot3(test_P(:,1), test_P(:,2), actualZ);legend('f(x,y)');figureplot3(test_P(:,1), test_P(:,2), test_T);legend('Network Result');figureplot3(test_P(:,1), test_P(:,2), actualZ, test_P(:,1), test_P(:,2), test_T);legend('f(x,y)','Network Result');function y=f(x)y = (1+sin(6*(x(1)^2+x(2)^2)))/2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -