-
Notifications
You must be signed in to change notification settings - Fork 2
/
optimizeall.m
53 lines (35 loc) · 1.33 KB
/
optimizeall.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [cmTraining, cmTesting,auctrain,auctest,convergence] = optimizeall(algorithm,dataset)
%load dataset
load(dataset);
inputs=xtrain';
targets=ytrain';
xtest=xtest';
ytest=ytest';
% Find number of features in the dataset
[k,l] = size(xtrain);
NumberOfNeurons=l*2+1; % number of hidden neurons equals to 2*(number of features) +1
dim=l*NumberOfNeurons+2*NumberOfNeurons+1; % Total number of weights and biases to optimize (dimensions of the problem)
%%%%%%%%%%%%%%
net = newpr(inputs,targets,NumberOfNeurons); % Create Net structure
%%%%%%%%%%%%%%%%%%%%%
if (algorithm==1)
[x_ga_opt, convergence] =MVO(dim,net,inputs,targets);
elseif (algorithm==2)
[x_ga_opt, convergence] =GA(dim,net,inputs,targets);
elseif (algorithm==3)
[x_ga_opt, convergence] =PSO(dim,net,inputs,targets);
elseif (algorithm==4)
[x_ga_opt, convergence] =BBO(dim,net,inputs,targets);
end
net = setx(net, x_ga_opt');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% training results
predictionTraining = sim(net,inputs);
[ct,cmt,indt,pert] = confusion(targets,predictionTraining);
cmTraining=cmt
auctrain = colAUC(predictionTraining', targets','ROC');
% testing results
prediction = sim(net,xtest);
[c,cm,ind,per] = confusion(ytest,prediction);
cmTesting=cm
auctest = colAUC(prediction', ytest','ROC');