Set initial weights of neural networks

조회 수: 5 (최근 30일)
Hamza Ali
Hamza Ali 2017년 5월 5일
댓글: Santhana Raj 2017년 5월 5일
Hello everyone !
I would like to set the initial weights of artificial neural network in order to define relevant number of hidden nodes. So, I wrote the code below but it does not work. Could you correct it for me? Thank you.
% Solve an Input-Output Fitting problem with a Neural Network
function [performance] = NN(x,t,i)
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. NFTOOL falls back to this in low memory situations.
[xn,xs] = mapminmax(x);% Normalization of inputs
[tn,ts] = mapminmax(t); % Normalization of outputs
%dx = randperm(size(xn,2)); % Inputs permutation
%xn = xn(:,dx); % Inputs permutation
%dx = randperm(size(tn,2)); % Output normalization
%tn = tn(:,dx); % Output normalization
trainFcn = 'trainlm'; % Levenberg-Marquardt
% Create a Fitting Network
H = i ;
net = fitnet(H, trainFcn);
I = size(x,1);
N = size(x,2);
O = size(t,1);
net = configure(net, xn, tn);
% Define initial conditions (transferFn, weights, biases...)
% Define transfer Function for each layer
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'logsig';
rng(0);
IW = 0.001 * randn(H,I);
LW = 0.001 * randn(O,H);
b1 = 0.001 * randn(H,1);
b2 = 0.001 * randn(O,1);
% Show weights and biases before training
net.IW{1,1}
net.LW{2,1}
net.b{1}
net.b{2}
% Setup Division of Data for Training, Validation, Testing
%net.divideParam.trainRatio = 70/100;
%net.divideParam.valRatio = 15/100;
%net.divideParam.testRatio = 15/100;
net.divideFcn = 'dividerand';
% Train the Network
[net] = train(net,xn,tn);
% Show weights and biases after training
net.IW{1,1} = IW;
net.LW{2,1} = LW;
net.b{1} = b1;
net.b{2} = b2;
% Test the Network
y = net(xn);
e = gsubtract(tn,y);
performance = perform(net,tn,y)
  댓글 수: 1
Santhana Raj
Santhana Raj 2017년 5월 5일
What do you mean by not working???
If you are getting error, then post the error.
If it is not able to train a specific data, then post the data also.
If you are expecting some results and the results are different, then post the data along with the expected results.

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

답변 (0개)

카테고리

Help CenterFile 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!

Translated by