Neural Network issue with Input weights
조회 수: 2 (최근 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!