Laboratorio Matlab: differenze tra le versioni
Da Bioingegneria Elettronica e Informatica.
(→Reti Neurali Feed-Forward) |
(→Cluster Analysis: Self-Organizing Maps) |
||
Riga 115: | Riga 115: | ||
y = net(x); | y = net(x); | ||
cluster_indices = vec2ind(y); | cluster_indices = vec2ind(y); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Dendrogramma: | ||
+ | <syntaxhighlight lang="matlab" line> | ||
+ | range = 1:100; | ||
+ | cgo = clustergram(yeastvalues(range,:),'RowLabels',genes(range),'ColumnLabels',times,'Standardize','Row'); | ||
+ | get(cgo) | ||
</syntaxhighlight> | </syntaxhighlight> |
Versione delle 15:21, 21 mag 2019
Reti Neurali Feed-Forward
Esempio di applicazione di reti neurali artificiali.
Creazione dataset:
load cancer_dataset.mat
x = cancerInputs;
t = cancerTargets(1,:);
temp = [x;t];
rng(0)
p = randperm(size(temp,2));
train_size = floor(size(temp,2)*.8);
p_train = p(1:train_size);
p_test = p(train_size+1:end);
x_train = temp(1:9,p_train);
t_train = temp(10,p_train);
x_test = temp(1:9,p_test);
t_test = temp(10,p_test);
save('dataset2.mat','x_train','t_train','x_test','t_test')
Implementazione rete neurale:
load dataset2.mat
disp(['# Features: ',num2str(size(x_train,1))])
disp(['# Samples: ',num2str(size(x_train,2))])
%% Creazione rete
% Layers nascosti
% hiddenLayerSize = [20];
% hiddenLayerSize = [50];
hiddenLayerSize = [20,10];
% Training Function - help nntrain
trainFcn = 'traingdx'; % traingda, traingdm, traingd
% Creazione rete
net = patternnet(hiddenLayerSize, trainFcn);
% Suddivisione dataset
net.divideFcn = 'dividerand';
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 30/100;
net.divideParam.testRatio = 0/100;
% Criteri di stop
net.trainParam.epochs = 5000;;
%net.trainParam.max_fail = 20;
%net.trainParam.min_grad = 0;%10e-5;
% Funzione errore
net.performFcn = 'mse';
% Funzioni di attivazione
net.layers{end}.transferFcn = 'logsig';
% Visualizza rete
view(net)
%% Inizializzazione Rete
rng(0)
net = configure(net,x_train,t_train);
net = init(net);
init_LW = net.LW;
init_IW = net.IW;
%% Addestramento Rete
[net,tr] = train(net,x_train,t_train);
y_train = net(x_train);
% Plots vari
figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
figure, plotconfusion(t_train,y_train),title('Training Confusion Matrix')
%figure, plotroc(t,y)
%% Test Rete
y_test = net(x_test);
figure, plotconfusion(t_test,y_test),title('Test Confusion Matrix')
Cluster Analysis: Self-Organizing Maps
Implementazione rete SOM:
load filteredyeastdata.mat
rng(0);
[x,std_settings] = mapstd(yeastvalues'); % Normalize data
[x,pca_settings] = processpca(x,0.15); % PCA
clusters_number = 10;
dimensions = [clusters_number];
net = selforgmap(dimensions);
view(net)
net.trainParam.epochs = 2000;
net.trainParam.showCommandLine = 1;
net = train(net,x);
figure,plotsompos(net,x);
figure,plotsomhits(net,x);
figure,plotsomnd(net,x);
y = net(x);
cluster_indices = vec2ind(y);
Dendrogramma:
range = 1:100;
cgo = clustergram(yeastvalues(range,:),'RowLabels',genes(range),'ColumnLabels',times,'Standardize','Row');
get(cgo)