z4 test funkcji train asv



%Testowanie funkcji toolboxa neural networks
clear
osie=[-20 20 -10 10];
u1=[-4 0];
u2=[5 2];
u3=[2 -5];
u1=[1 u1];
u2=[1 u2];
u3=[1 u3];
U=[u1;u2;u3];
z=[1;1;-1];
disp('Rozwiązanie analityczne')
%det(U'*U)
w=inv(U'*U)*U'*z
wp=w;
r=U*w-z;
disp('Błąd aproksymacji')
r=r'*r

figure(1);clf;
subplot(1,3,1);
newplot;
hold on;

N=length(z);
for licz=1:N
if z(licz)==1
plot(U(licz,2),U(licz,3),'bs');
elseif z(licz)==-1
plot(U(licz,2),U(licz,3),'ro');
else
plot(U(licz,2),U(licz,3),'gx');
end;
end;

kolor=['b-'];
wrys=[w(1)-1;w(2:3)];
rprosta(wrys,osie,kolor);
kolor=['r-'];
wrys=[w(1)+1;w(2:3)];
rprosta(wrys,osie,kolor);
kolor=['m-'];
wrys=w;
rprosta(wrys,osie,kolor);
title('Rozwiazanie analityczne');
hold off;




%%%Funkcje TOOLBOXa

zakresy=[-20 20; -10 10]


% TRAINLM is a network training function
% that updates weight and bias values according to Levenberg-Marquardt optimization.
% You can create a standard network that uses TRAINLM with NEWFF.
% net=newff(zakresy,[1],{'purelin'});
% To prepare a custom network to be trained with TRAINLM:
% 1) Set NET.trainFcn to 'trainlm'.
% This will set NET.trainParam to TRAINLM's default parameters.
% 2) Set NET.trainParam properties to desired values.


net=newff(zakresy,[1],{'purelin'});
disp('Atrybuty sieci utworzonej przez newff')
disp('Metoda treningu')
net.trainFcn
disp('Metoda uczenia wag')
net.inputWeights{1,1}.learnFcn
disp('Metoda uczenia biasów')
net.biases{1}.learnFcn

% %Zmiana wartości
% net.inputWeights{1,1}.learnFcn = 'learnwh';
% net.biases{1}.learnFcn= 'learnwh';
% net = newlin(zakresy,1);
% disp('Metoda uczenia')
% net.inputWeights{1,1}.learnFcn
% net.biases{1}.learnFcn


% %Ustawianie wag początkowych
% %Pokaż wagi początkowe
% disp('Wagi początkowe')
% net.iw{1,1}
% net.b{1}
% %input weight
% net.iw{1,1}=[-1 1];
% %bias
% net.b{1}=0;
%Pokaż wagi początkowe

disp('Wagi początkowe')
net.iw{1,1}
net.b{1}



%Sprawdzenie trainFcn (stylu uczenia)


% % TRAIN trains a network NET according to NET.trainFcn and NET.trainParam.

disp('Funkcja treningu')
net.trainFcn

% net.trainFcn='trainb';
% net.trainFcn='trains';


% Funckcja TRAINB: Batch training with weight & bias learning rules.
% In batch training the weights and biases are only updated after all of the inputs are presented.
%
% % Funkcja TRAINS: Sequential order incremental training w/learning functions.
% % In incremental training the weights and biases of the network
% % are updated each time an input is presented to the network.
%
%
% % Typically one epoch of training is defined as a single presentation
% % of all input vectors to the network. The network is then updated
% % according to the results of all those presentations.
%
% net.trainParam.epochs = 200;
% net.trainParam.show = 10;
%

% Niżej ustawiane sa parametry domyślne dla adapt (wyniki uczenia train i adapt będa jednakowe)
% net.inputWeights{1,1}.learnParam.lr = 0.1;
% net.biases{1}.learnParam.lr = 0.1;
% net.trainParam.epochs = 10;%Zmiana na domyślne dla adapt


disp('Dane uczące')
P=U(:,2:3)'
T=z'
% Trening
nettr = train(net,P,T);
nettr.iw{1,1}'
nettr.b{1}
wt=zeros(3,1);
wt(2:3,1)=nettr.iw{1,1}';
wt(1,1)=nettr.b{1};

% Weryfikacja uczenia: obliczenie wyjścia dla danych uczących
wynik = sim(nettr,P)

figure(1);
subplot(1,3,2);
newplot;
hold on;
kolor=['m-'];
rprosta(wt,osie,kolor);
title('Testowanie train');

[lw,lk]=size(P);
kolor1='bs';kolor1a='bo';
kolor2='ro';kolor2a='rs';
for licz=1:lk;
if wynik(licz)<=0
if z(licz)<=0
plot(P(1,licz),P(2,licz),kolor2);
else
plot(P(1,licz),P(2,licz),kolor2a);
end;
else
if z(licz)>0
plot(P(1,licz),P(2,licz),kolor1);
else
plot(P(1,licz),P(2,licz),kolor1a);
end;
end;
end;



disp('Test dla danych spoza zbioru uczącego')


testuj=[-8 -5 0 5 10; -8 -4 0 4 8];

wynik=sim(nettr,testuj)

[lw,lk]=size(testuj);
kolor1='bd';
kolor2='rd';
for licz=1:lk;
if wynik(licz)<=0
plot(testuj(1,licz),testuj(2,licz),kolor2);
else
plot(testuj(1,licz),testuj(2,licz),kolor1);
end;

end;



hold off;


% testowanie adapt
% ADAPT Allow a neural network to adapt.

% When we call adapt, it will invoke trains
% (which is the default adaptation function for the linear network)
% and learnwh
% (which is the default learning function for the weights and biases).
% Therefore, Widrow-Hoff learning is used.


% Given an input sequence with TS steps the network is
% updated as follows. Each step in the sequence of inputs is
% presented to the network one at a time. The network's weight and
% bias values are updated after each step, before the next step in
% the sequence is presented. Thus the network is updated TS times.


net.adaptParam.passes = 100;


netad = adapt(net,P,T);
netad.iw{1,1}'
netad.b{1}
wa=zeros(3,1);
wa(2:3,1)=netad.iw{1,1}';
wa(1,1)=netad.b{1};

disp('Porównanie rozwiązań: analitycznego i uczenia funkcja train i adapt');
[wp wt wa]


disp('Symulacja sieci dla danych uczących');
wynik = sim(netad,P)

figure(1);
subplot(1,3,3);
newplot;
hold on;
kolor=['m-'];
rprosta(wa,osie,kolor);
title('Testowanie adapt');

[lw,lk]=size(P);
kolor1='bs';kolor1a='bo';
kolor2='ro';kolor2a='rs';
for licz=1:lk;
if wynik(licz)<=0
if z(licz)<=0
plot(P(1,licz),P(2,licz),kolor2);
else
plot(P(1,licz),P(2,licz),kolor2a);
end;
else
if z(licz)>0
plot(P(1,licz),P(2,licz),kolor1);
else
plot(P(1,licz),P(2,licz),kolor1a);
end;
end;
end;




%
%
%



disp('Test dla danych spoza zbioru uczącego')


testuj=[-8 -5 0 5 10; -8 -4 0 4 8];

wynik=sim(netad,testuj)

[lw,lk]=size(testuj);
kolor1='bd';
kolor2='rd';
for licz=1:lk;
if wynik(licz)<=0
plot(testuj(1,licz),testuj(2,licz),kolor2);
else
plot(testuj(1,licz),testuj(2,licz),kolor1);
end;

end;



hold off;


Wyszukiwarka

Podobne podstrony:
MwN Test 7 Funkcja kl3
funkcja kwadratowa test
WdAM 2007 wstep test wlasnosci funkcji
FUNKCJA LINIOWA TEST
Test wielokrotnego wyboru z matematyki Funkcje cyklometryczne odpowiedzi
Geneza i funkcjonowanie mitu arkadyjskiego
klucz test zawodowy Y6ZUUDOV
Fundacje i Stowarzyszenia zasady funkcjonowania i opodatkowania ebook
Test dla kierowcy[1]
candi self test
integracja funkcji
FUNKCJA CHŁODZENIE SILNIKA (FRIC) (ZESPOLONE Z KALKULATOREM

więcej podobnych podstron