-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.m
More file actions
72 lines (64 loc) · 2.06 KB
/
Copy pathmain.m
File metadata and controls
72 lines (64 loc) · 2.06 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [k2Progress,k2BestProgress,bestNet]= main(data,params,minmaxSystem,eliteSystem,reward,nIterations)
% number of ants
nAnts = 4;
% in params, the values indicate the weights of the least invalidated
% moves heuristic, the pheromones and the k2 score respectively.
% number of nodes in the net
nNodes=size(data,2);
% initialise the empty adjacency matrix
adjacencyMatrix = zeros(nNodes,nNodes);
% make the list of all possible edges. This list also keeps track of the
% pheromones on each edge.
possibleEdges = [];
for i=1:nNodes
for j=1:nNodes
possibleEdges=[possibleEdges;[i,j,1]];
end
end
% the lines above create all possible edges, we need an initial pruning
% round to remove edges from a node to itself
possibleEdges= removeInvalid(possibleEdges,adjacencyMatrix);
% initialise the desirability list
desirability = ones(size(possibleEdges,1),1);
%optional min-max and elitist ant system. set to 0 to use the normal ant
%system.
if minmaxSystem ==1
minmax=[1,100];
else
minmax=[];
end
if eliteSystem==1
elitist{1}=1;
elitist{2}=adjacencyMatrix;
else
elitist{1}=0;
elitist{2}=adjacencyMatrix;
end
% if prefSimple is true the K2 score is divided by the number of edges as a
% penalty to more complex networks.
prefSimple = true;
decay =0.95;
bestNet= adjacencyMatrix;
bestK2Score=-999999;
k2Progress=[];
k2BestProgress=[];
for j=1:nIterations
j
parfor i=1:nAnts
[networks{i},k2score(i)]=runAnt(data,params,desirability,adjacencyMatrix,possibleEdges,prefSimple);
end
if elitist{1}==1
elitist{2}=bestNet;
end
[k2score,k2bestIndex]=max(k2score);
Net= networks{k2bestIndex};
[Net,k2score]=localSearch(Net,k2score,data,prefSimple);
[possibleEdges] = pheromoneUpdate (possibleEdges,Net,decay,reward,minmax,elitist);
if k2score >= bestK2Score
bestK2Score=k2score;
bestNet=Net;
end
k2Progress=[k2Progress,k2score];
k2BestProgress=[k2BestProgress,bestK2Score];
end
plot(k2Progress)