bpx_simu.m

来自「Matlab实现BF算法」· M 代码 · 共 58 行

M
58
字号
%此为一仿真程序
%首先读入权域值参数

function retdouble = simulate(NetPara,SimulatePara,InputFun,OutputFun,DataDir)
NNTWARN OFF

retdouble = -1;
olddir=pwd;
% 数据所在目录
cd(DataDir);

% 输入层到中间层的传递函数
if (length(InputFun)==0)
    InputFun = 'tansig';
end
% 中间层到输出层的传递函数  
if (length(OutputFun)==0)
    OutputFun = 'purelin'
end    

frw1=fopen('w1.dat','r');
frb1=fopen('b1.dat','r');
frw2=fopen('w2.dat','r');
frb2=fopen('b2.dat','r');

InputDim=NetPara(1);      %输入层节点数
OutputDim=NetPara(2);     %输出层节点数
MidDim=NetPara(3);         %中间层节点数

[w1,count]=fscanf(frw1,'%f',[MidDim,InputDim]);
[b1,count]=fscanf(frb1,'%f',[MidDim,1]);
[w2,count]=fscanf(frw2,'%f',[OutputDim,MidDim]);
[b2,count]=fscanf(frb2,'%f',[OutputDim,1]);

fclose(frw1);
fclose(frb1);
fclose(frw2);
fclose(frb2);

for i=1:InputDim
    p1(i)=SimulatePara(i);
end

a=simuff(p1',w1,b1,InputFun,w2,b2,OutputFun);


%将仿真结果写入文件
fwresult=fopen('result.dat','w');
fprintf(fwresult,'%-15.6f\n',a);
fclose(fwresult);
retdouble = a;
logsig(1);
purelin(1);
tansig(1);
cd(olddir);


⌨️ 快捷键说明

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