Regression Learner and 1 layer Neural Network Model parameters
Show older comments
I used Regression Learner to generate a 1 fully-connected layer, narrow neural network with no activation function. The exported compact model works great when I run data through it. However, if I use the Layer Weights and Biases from the model to try and calculate the neural network myself, I am doing something wrong.
Here is what i've tried.
predictor1=rand(100,1);
predictor2=rand(100,1);
response=(2*predictor1 - 3*predictor2);% [predictor1 predictor2]*[2 -3]'
dataset=[predictor1 predictor2 response];
% Use Regression Learner App with dataset to train Narrow Neural Network
% activation function = none, 1 layer (size =1).
% No surprise it has an RMSE approaching zero and R^2 =1.
% Export & use compact model.
yfit = trainedModel.predictFcn([predictor1 predictor2]);
disp(max (yfit - response)) % output 1.2234e-05 (small, as expected, model works)
%extract the parameters from the model
k1=trainedModel.RegressionNeuralNetwork.LayerWeights{1,1};
b1=trainedModel.RegressionNeuralNetwork.LayerBiases{1};
k2=trainedModel.RegressionNeuralNetwork.LayerWeights{1,2};
b2=trainedModel.RegressionNeuralNetwork.LayerBiases{2};
%calculate yfit outside of matlab's model
myfit=([predictor1 predictor2]*k1'+b1)*k2+b2; % WHAT AM I DOING WRONG???
disp(max (myfit - response)) % output 1.3108 (large, something is wrong with myfit)
What am I missing here?
Accepted Answer
More Answers (0)
Categories
Find more on Gaussian Process Regression 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!