想寫一個
3 input units, 1 output unit 的一層(內有4個 computational units)
的BPN類神經網路
但是寫在m file中, 讓他run的時候總是會出現錯誤~ 一個解完又一個
都快哭哭了我
可以麻煩大家提供意見嗎? 謝謝!!
原始code如下:
clear;
fprintf('This is an example ........')
In_data=xlsread('tdata30.xls');
In_1=In_data(1:30, 2); %讀excel內的第二行資料 當作input1
In_1=In_1'
In_2=In_data(1:30, 3); %讀excel內的第三行資料 當作input2
In_2=In_2'
In_3=In_data(1:30, 4); %讀excel內的第四行資料 當作input3
In_3=In_3'
Target=In_data(1:30, 5); %讀excel內的第五行資料 當作目標值
Target=Target'
net=network;
net.numInputs = 3; %有三個inputs
net.numLayers = 1; %只有1層
net.biasConnect = [1];
net.inputConnect = [ 1 1 1];
net.layerConnect(1,1) = 1;
net.outputConnect = [1];
targetConnect = [1];
net.inputs{1}.range = [ 7 10];
net.inputs{2}.range = [ 20 40];
net.inputs{3}.range = [ 50 120];
net.layers{1}.size = 4;
net.layers{1}.transferFcn = 'logsig';
net.layers{1}.initFcn = 'initnw';
net.layerWeights{1,1}.delays = [1]; <---這裡可能有誤 不設delay會出現error
%net.layerWeights{1,2}.delays = [1]; <---這裡可能有誤 不太知道要不要設delay
%net.layerWeights{1,3}.delays = [1]; <---這裡可能有誤 不太知道要不要設delay
net.initFcn = 'initlay';
net.performFcn = 'mse';
net.trainFcn = 'traingd';
%net.trainFcn = 'trainlm';
net.trainParam.mem_reduc=5
p = [In_1;In_2;In_3]
%這裡可能有問題...因為書中舉的例子都直接key值 不知道能不能將三個input放一起
net=init(net); %初始化
Before_train=sim(net,p);
<----這裡我有疑問~模擬(sim)的時候 是要分別將input1 input2 input3丟進去嗎?
還是可以一起~?
Target;
net.trainParam.lr=0.05;
net.trainParam.epochs=1000;
net.trainParam.goal=1e-5;
fprintf('The network has been set up ....');
fprintf(' ==> pause for waiting to train');
pause
p = [In_1;In_2;In_3] <--書中案例也是先將值key進去 所以不太清楚能不能這樣寫
net = train(net,p,Target);
%訓練網路train 此行會出現error
%不知道train(net,input1 input2 input3,target)可不可行(有試過...還是出現error)
After_train=sim(net,p)
Target
disp('Done!!');
----------------------------------------------------
目前這樣的程式
跑出的error如下敘述
??? Error using ==> network.train at 146
Targets are incorrectly sized for network.
Matrix must have 4 rows.
Error in ==> training30 at 62
net = train(net,p,Target); %訓練網路
但是我已經不知道要修改哪裡了...>"<
有沒有好心人能幫幫忙給我一點建議呢?
謝謝大家!
若需要m-file方便閱讀 麻煩mail我 我會寄給您 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.55.196