Neural Network issue with Input weights
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/935449/image.png)
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 Commenti
Risposte (1)
Rohit
il 16 Nov 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Modeling and Prediction with NARX and Time-Delay Networks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!