# MATLAB Neural Network - Forward Propagation

조회 수: 7(최근 30일)
Erica Dos Santos Saraiva 2021년 7월 24일
댓글: Erica Dos Santos Saraiva 2021년 7월 28일
I am trying to implement a forward propogation with a foor loop as advices on neural smithing. I keep recieveing an error when iterating through my for loop. How do I get rid of this error.
I have checked the sizes for both NOUTPUTS(i+1) and NPATS(i) which both are = 1 however keep receiving this error.
Patterns = x'; Desired = y; NHIDDENS = 1; prnout=Desired;
% Patterns become x so number of inputs becomes size of patterns
[NINPUTS,NPATS] = size(Patterns); [NOUTPUTS,NP] = size(Desired);
%apply the backprop here...
LearnRate = 0.15; Momentum = 0; DerivIncr = 0; deltaW1 = 0; deltaW2 = 0;
% Keeps the tan ordering of the examples of x
Inputs1= [Patterns;ones(1,NPATS)]; %Inputs1 = [ones(1,NPATS); Patterns];
% Weight initialisation
Weights1 = 0.5*(rand(NHIDDENS,1+NINPUTS)-0.5);
Weights2 = 0.5*(rand(1,1+NHIDDENS)-0.5);
TSS_Limit = 0.02;
for epoch = 1:10
% FORWARD LOOP
size(NOUTPUTS)
size(NPATS)
for ii = 0: ii < length(NINPUTS)
NOUTPUTS(ii+1) = NPATS(ii);
% Sets bias to 1
NOUTPUTS(1) = 1;
end
for ii = NHIDDENS: ii < NINPUTS
sum = 0;
for ij = 0: ij < ii
sum = sum + deltaW1(ii,ij) * NOUTPUTS(ij);
NOUTPUTS(ii) = tanh(sum);
end
end
Unable to perform assignment because the
left and right sides have a different
number of elements.
Error in mlpts (line 66)
NOUTPUTS(i+1) = NPATS(i);

댓글을 달려면 로그인하십시오.

### 답변(1개)

Swetha Polemoni 2021년 7월 27일
Hi,
You might want to check on the format of for loops you have used(for ii = 0: ii < length(NINPUTS)). This can be replaced with following code snippet.
ii = intial value;
while condition
end
##### 댓글 수: 1표시숨기기 없음
Erica Dos Santos Saraiva 2021년 7월 28일
Do you know how to implement a for loop for forward propogation?

댓글을 달려면 로그인하십시오.

### 범주

Find more on Deep Learning Toolbox in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by