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};

回答(1 个)

Rohit
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 zerosas 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!

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by