Filter löschen
Filter löschen

using Neural Network without toolbox

25 Ansichten (letzte 30 Tage)
Mohammad
Mohammad am 2 Dez. 2022
Kommentiert: Mohammad am 5 Dez. 2022
I have to write a code to model Neural Network. I write it with sigmoid function, back propogation, and gradient descent method.
My problem is that I can not insert input higher than 1.
This is my code:
X = (0:0.01:1.5);
X = X';
LX = length(X);
B_size = 1;
NO_B = (LX / B_size);
Y_d = X.^2;
Width = 20;
H = zeros (Width,1);
H_f = zeros (Width,1);
Y = zeros(LX,1);
Y_f = zeros(LX,1);
W1 = rand (Width,B_size);
W2 = rand (B_size,Width);
b1 = 1 ;
b2 = 1 ;
E_total = 1;
Eta = 0.1;
itt = 0;
epoch = 1500;
for e = 1 : epoch
for i = 1 : NO_B
itt = itt + 1;
XX = X( (B_size * (i-1)) +1 : (i*B_size) );
YY_d = Y_d( (B_size * (i-1)) +1 : (i*B_size) );
H = W1*XX + b1;
H_f = SIG(H);
Y = W2*H_f + b2;
Y_f = SIG(Y);
E_total = sum ( 0.5 * (( YY_d - Y_f ).^2)) ;
E(itt) = E_total;
ITT(itt) = itt;
delta = YY_d - Y_f ;
dY = Y_f.*(1-Y_f) ;
dH = H_f.*(1-H_f) ;
pd2 = (delta.*dY) * H_f' ;
pd1 = (XX *((delta.*dY)' * W2).* dH')' ;
W2 = W2 + Eta*pd2;
W1 = W1 + Eta*pd1;
YY_f ( (B_size * (i-1)) +1 : (i*B_size) )= Y_f;
end
end
plot(X,YY_f,'r*',X,Y_d,'b:','LineWidth',2);
function [alpha_f] = SIG(alpha)
%SIGMOID FUNCTION
alpha_f = 1 ./ (1 + ((exp(1)) .^ (-alpha)));
end
  2 Kommentare
Walter Roberson
Walter Roberson am 2 Dez. 2022
It is not clear to me which is the input that you cannot make larger than 1. Also you did not indicate what happens when you try to do that.
Mohammad
Mohammad am 5 Dez. 2022
The input is X.
However, I found the problem. the problem is because of Sigmoid function.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by