-
Notifications
You must be signed in to change notification settings - Fork 0
/
ga_output.m
65 lines (52 loc) · 1.7 KB
/
ga_output.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
54
55
56
57
58
59
60
61
62
63
64
65
function [state, options, optchanged] = ga_output(options, state, ~, num_pps)
%% ga_output.m : This is function that can be passed as an option to
% Matlab's genetic algorthim routine, inputs and outputs are defined at
% http://www.mathworks.com/help/gads/genetic-algorithm-options.html#f17837
first_flag = 0;
optchanged = false;
if state.Generation == 0
if exist('results/ga_interim.mat','file') > 0
delete('results/ga_interim.mat');
end
end
%% Find plausible patients, i.e. those with a score < 0
pp_idx = find(state.Score < 0);
if ~isempty(pp_idx)
pps_new = state.Population(pp_idx,:);
pps_scores_new = state.Score(pp_idx);
else
%disp(state.Score);
return;
end
%% Append to existing list of plausible patients if possible
if exist('txtout/ga_interim.mat','file') == 2
% Generation 2+, load and append:
try
load('txtout/ga_interim.mat');
catch
disp(first_flag);
disp(state.Generation);
error('no load');
end
p_pp = [p_pp; 10.^pps_new];
score_pp = [score_pp; pps_scores_new];
% Filter out close-ish duplicates:
z = p_pp./mean(p_pp,1);
[~,ia,~] = uniquetol(z,1e-2,'ByRows',true);
p_pp = p_pp(ia,:);
score_pp = score_pp(ia,:);
else %create new list of plausible patients
%fprintf('Interim file not found!\n');
p_pp = 10.^pps_new;
score_pp = pps_scores_new;
end
n_pp = size(p_pp,1);
%% Save results back to temporary file
save('txtout/ga_interim.mat', 'p_pp','score_pp','n_pp');
%disp(['Number of plausible patients found: ', num2str(n_pp)]);
%% Flag exit if we have enough PPs
if (n_pp >= num_pps)
% disp([n_pp num_pps]);
state.StopFlag = 'y';
end
end % function ga_output