-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgppopvars.m
58 lines (46 loc) · 1.29 KB
/
gppopvars.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
function hitvec=gppopvars(gp,top_frac)
%GPPOPVARS Displays the frequency of the input variables present in the
%best user specified fraction of the population.
%
% HITVEC=GPPOPVARS(GP) displays and returns an input frequency
% vector for the best 5% of the population.
%
% HITVEC=GPPOPVARS(GP,TOP_FRAC) displays and returns an input frequency
% vector for the best fraction TOP_FRAC of the population. TOP_FRAC must
% be > 0 and <= 1.
%
% Remarks:
% Assumes lower fitnesses are better.
%
% (c) Dominic Searson 2009
%
% v1.0
%
% See also: GPMODELVARS
if nargin<2
top_frac=0.05;
end
if top_frac<= 0 || top_frac>1
disp('Supplied fraction must be greater than zero and less than or equal to 1.');
return;
end
num2process = ceil(top_frac*gp.runcontrol.pop_size);
[fsort,sort_ind]=sort(gp.fitness.values);
sort_ind=sort_ind(1:num2process);
numx=gp.nodes.inputs.num_inp;
hitvec=zeros(1,numx);
%loop through population
for i=1:num2process
model=gp.pop{sort_ind(i)};
hitvec = hitvec+ scangenes(model,numx);
end
% plot results as barchart
h=figure;
set(h,'name','gppopvars','numbertitle','off');
a=gca;
bar(a,hitvec);
axis tight;
xlabel('Input number');
ylabel('Input frequency');
title(['Input frequency - best ' num2str(100*top_frac) '% of whole population']);
hitvec=hitvec';