using Neural Network without toolbox
조회 수: 25 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2022년 12월 2일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!