Simple neural network computation NOT working

조회 수: 2 (최근 30일)
Jacob Jeong
Jacob Jeong 2022년 6월 13일
댓글: Jacob Jeong 2022년 6월 13일
I've used the "Neural Net Fitting" App as well as my own code to compute weights for a very simple 1 hidden layer (w/ 1 neuron).
== my own code ==
h1 = X_input * w1 + b1;
o1 = tanh(h1);
h2 = o1 * w2 + b2;
o2 = tanh(h2);
=====
However, it does not output a correct output compared to the "Neural Net Fitting" App.
Is there anything wrong with the above algorithm?
Thanks.

답변 (1개)

Steven Lord
Steven Lord 2022년 6월 13일
  댓글 수: 1
Jacob Jeong
Jacob Jeong 2022년 6월 13일
%% Linear function for testing NN %%
function [x_input, y_true] ...
= test_lin(N_samples)
a = 3;
b = -5;
% preallocated for speed
x_input = zeros(1, N_samples);
y_true = zeros(1, N_samples);
% generate x (within [-10, 10])
for i = 1:N_samples
x_input(i) = unifrnd(-1, 1);
y_true(i) = a * x_input(i) + b;
end
%%
%% Testbench %%
clear; clc;
N_neuron = 1; % number of neurons
K_max = 1000;
Y_max = 100;
eta = 0.01;
[x_input, y_true] = test_lin(K_max);
X_input = x_input;
Y_true = y_true/Y_max;
Y_pred = zeros(1,K_max);
%%
%% Trained Neural Net Fitting using X_input and Y_true
got the following from Neural Net Fitting
% Layer 1
b1 = -0.0034309766062626356579;
IW1_1 = 0.22567942543499841523;
% Layer 2
b2 = 0.015126064794135411773;
LW2_1 = 4.4754110209172548451;
%% Neural Net Fitting app uses tanh for hidden layer and linear function for output layer
h1 = X_input * w1 + b1;
o1 = tanh(h1);
h2 = o1 * w2 + b2;
o2 = h2
o2 should be same as when I input X_input to Neural Net Fitting function, but is NOT the same....

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

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by