Simple neural network computation NOT working

1 visualización (últimos 30 días)
Jacob Jeong
Jacob Jeong el 13 de Jun. de 2022
Comentada: Jacob Jeong el 13 de Jun. de 2022
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.

Respuestas (1)

Steven Lord
Steven Lord el 13 de Jun. de 2022
  1 comentario
Jacob Jeong
Jacob Jeong el 13 de Jun. de 2022
%% 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....

Iniciar sesión para comentar.

Categorías

Más información sobre Deep Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by