i have problem with ffnn on matlab
3 次查看(过去 30 天)
显示 更早的评论
this is my code
clear
clc
input=[1 2 3];
target=[5 8 4];
n=2;
net=feedforwardnet(n);
net=configure(net,input,target);
net.layers{1}.transferFcn = 'purelin';
net.layers{2}.transferFcn = 'purelin';
ukuran1=size(input);
ukuran2=size(target);
m=ukuran1(1,1); %ini banyak input
o=ukuran2(1,1); %ini banyak output
kk=((m+1+o)*n)+1; %ini banyak bobot
net.iw{1}=[0;0];
net.lw{2}=[0 0];
net.b{1}=[0;0];
net.b{2}=[0];
y=net(input)
why the output (y) always different with my manual computation, can someone help me? maybe there is somethings i didnt know about FFNN matlab that
2 个评论
Greg Heath
2018-5-11
clear, clc
input=[1 2 3]; target=[5 8 4];
n=2; net=feedforwardnet(n);
net=configure(net,input,target);
% 1. EXPLICIT CONFIGURATION IS UNNECCESSARY IF YOU TRAIN THE NET
net.layers{1}.transferFcn = 'purelin';
% 2. NON OUTPUT LAYERS SHOULD HAVE NONLINEAR TRANSFER FUNCTIONS
net.layers{2}.transferFcn = 'purelin'; ukuran1=size(input); ukuran2=size(target); m=ukuran1(1,1); %ini banyak input o=ukuran2(1,1); %ini banyak output kk=((m+1+o)*n)+1; %ini banyak bobot net.iw{1}=[0;0]; net.lw{2}=[0 0]; net.b{1}=[0;0]; net.b{2}=[0];
% 3. INITIAL WEIGHTS SHOULD BE RANDOM. YOU CAN ASSIGN RANDOM VALUES, OR USE CONFIGURE OR JUST TRAIN THE NET WHICH WILL AUTOMATICALLY INITIALIZE WEIGHTS.
y=net(input)
% THE NET HAS NO WEIGHTS! YOU NEED TO TRAIN THE NET.
SEE MY ANSWER
GREG
回答(1 个)
Greg Heath
2018-5-11
close all, clear, clc
% N No. of input and output-target vectors
% I Input dimension
% O Output dimension
% H No. of hidden units
% I-H-O Typical network node topology
% Nw = (I+1)*H+(H+1)*O No. of weights
%
% Ntst = round(0.15*N) Default No. of test vectors
% Nval = Ntst Default No. of validation design vectors
% Ntrn = N-Nval-Ntst Default No. of training design vectors (~0.7*N)
%
% Training vectors: Design vectors used to determine network weight values
% Validation vectors: Design vectors used to stop training when val errors
% increase continually for 6 (default) continuous training epochs
% Test vectors: Nondesign vectors used to obtain UNBIASED performance
% estimates
input=[1 2 3]; target=[5 8 4];
[I N ] = size(input) % [1 3]
[O N ] = size(target)%[ 1 3 ]
plot(input,target)
rng(0) % Allows duplication of results
n=2; net=feedforwardnet(n);
[net tr output error ] = train(net,input,target);
% Normalized Mean Square Error 0<= NMSE <= 1
NMSE = mse(error)/var(target,1) % 4.3684e-26
2 个评论
Greg Heath
2018-5-11
1. See the documentation examples in
help feedforwardnet
and
doc feedforwardnet
2. For more examples, search ANSWERS using
greg feedforwardnet
Hope this helps.
Greg
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modeling and Prediction with NARX and Time-Delay Networks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!