Neural Network issue with Input weights
1 回表示 (過去 30 日間)
古いコメントを表示
Hi I used the following code to create a custom feedforward neural network. But Unfortunately the inputs from {1,1} are required to be 5 x 0 dimension. According to documentation, instead of zero there should be a 10 because there are 2 delays and 5 neurons. So net.IW{1,1} should be 5 x 10 in size. Does anyone know how to fix this problem? MATLAB is not considering the connections and delays?
net=feedforwardnet(S1,'trainlm');
net.layers{1}.size=5;
net.layers{2}.size=1;
net.numinputs = 4
net.inputConnect = logical([1 1 0 1;0 0 0 0]);
net.inputWeights{1}.delays =1:2;
net.inputWeights{3}.delays =1:2;
net.inputWeights{5}.delays =1:2;
net.inputWeights{7}.delays =1:2;
net.inputs{1}.processFcns = {};
net.IW{1} = net2.IW{1};
0 件のコメント
回答 (1 件)
Rohit
2023 年 11 月 16 日
Hi Christian,
I understand that you are creating a feedforward neural network. You want the inputs from {1,1} to be of 5*10 dimension but they are 5*0.
To fix the issue with the dimensions of net.IW{1,1}, you can modify the code as follows:
net=feedforwardnet(S1,'trainlm');
net=feedforwardnet(S1,'trainlm');
net.layers{1}.size=5;
net.layers{2}.size=1;
net.numinputs = 4;
% Set the input connections and delays
net.inputConnect = logical([1 1 0 1; 0 0 0 0]);
net.inputWeights{1}.delays = 1:2;
net.inputWeights{2}.delays = 1:2;
net.inputWeights{4}.delays = 1:2;
net.inputWeights{5}.delays = 1:2;
% Set the input processing functions
net.inputs{1}.processFcns = {};
% Set the input weight matrix
numDelays = max(cellfun(@max, net.inputWeights(1:2:end).delays));
numNeurons = net.layers{1}.size;
numInputs = net.numinputs;
net.IW{1,1} = rand(numNeurons, numInputs * numDelays); % Replace with your desired initialization
% Alternatively, you can set the input weight matrix to a specific size
% using zeros as placeholders
% numDelays = max(cellfun(@max, net.inputWeights(1:2:end).delays));
% numNeurons = net.layers{1}.size;
% numInputs = net.numinputs;
% net.IW{1,1} = zeros(numNeurons, numInputs * numDelays);
% Copy the weights from net2 to net
net.IW{1} = net2.IW{1};
In this code, we explicitly set the size of net.IW{1,1} based on the number of neurons, inputs, and delays. You can initialize it with random values using “rand” or use “zeros“ as placeholders if you prefer.
By setting the correct size for net.IW{1,1}, you ensure that the connections and delays are considered properly in your custom feedforward neural network.
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Modeling and Prediction with NARX and Time-Delay Networks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!