【发布时间】:2014-08-23 00:01:57
【问题描述】:
大家好,我是 matlab 新手,我对 ga 函数有一些问题。
我必须使用遗传算法找到应用于时间序列问题的网络的最佳输入和输出延迟整数值。
我编写了一个拟合函数,使用 2 个变量作为输入和输出延迟创建网络并返回性能值。
我想要 1 到 10 之间的 2 次延迟,所以我使用这样的 ga 函数
[x,fval,exitflag,output,population,scores] = ga(@rendimentoRete, 2, [], [], [], [], [1 1], [10 10], [], [1 2])
我有这个错误“在调用“D:\Documents\MATLAB\rendimentoRete.m>rendimentoRete”期间未分配输出参数“out”(可能还有其他参数)。”
这是我的拟合函数 (如果有人喜欢这与语法突出显示 http://pastebin.com/5iwzwhi0 的 pastebin 上的功能相同)
function out = rendimentoRete(iDelay, oDelay)
if nargin < 2
return;
end
%%carico le variabili dal workspace in modo che la funzione di fitness
%%conservi come varibili di ingresso solo i delay
load baseSet.mat;
inputSeries = tonndata(first_period,false,false);
targetSeries = tonndata(first_usd_ise,false,false);
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:iDelay;
feedbackDelays = 1:oDelay;
hiddenLayerSize = 8;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer states.
% Using PREPARETS allows you to keep your original time series data unchanged, while
% easily customizing it for networks with differing numbers of delays, with
% open loop or closed loop feedback modes.
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
for j=1:10
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
end
% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs); %%alt -> MSE
%prova1
out = performance;
%{
%prova2
%converto l'output a un vettore e approssimo i risultati ai valori 1 e -1
%convert outputs cell to array
outputs_array = cell2mat(outputs);
%convertiamo outputs_array
for k=1:(268-outputDelay)
if outputs_array(k)>0
outputs_array(k)=1;
else
outputs_array(k)=-1;
end
end
out = performance + calcoloMape(outputDelay, first_usd_ise, outputs_array) + calcoloPgcp(outputDelay, first_usd_ise, outputs_array);
%}
end
随着 baseSet.mat 的加载,我正在加载 first_period 和 first_usd_ise,因为它们总是相同的。
我不知道该怎么做,因为当我单独使用该功能时会给我带来很好的结果。 有人可以解释我哪里出错了。
【问题讨论】:
-
对于
nargin<2没有分配输出,设置断点并检查您的函数是否获得所需数量的参数。 -
没有
nargin<2我得到这个错误Error using rendimentoRete (line 15) Not enough input arguments.其中第15 行是feedbackDelays = 1:oDelay;所以该函数不包含第二个变量。
标签: matlab neural-network