-
Notifications
You must be signed in to change notification settings - Fork 0
/
bs2rv.m
61 lines (48 loc) · 1.37 KB
/
bs2rv.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
function Phen = bs2rv(Chrom,FieldD)
% Identify the population size (Nind)
% and the chromosome length (Lind)
[Nind,Lind] = size(Chrom);
% Identify the number of decision variables (Nvar)
[seven,Nvar] = size(FieldD);
if seven ~= 7
error('FieldD must have 7 rows.');
end
% Get substring properties
len = FieldD(1,:);
lb = FieldD(2,:);
ub = FieldD(3,:);
code = ~(~FieldD(4,:));
scale = ~(~FieldD(5,:));
lin = ~(~FieldD(6,:));
uin = ~(~FieldD(7,:));
% Check substring properties for consistency
if sum(len) ~= Lind,
error('Data in FieldD must agree with chromosome length');
end
if ~all(lb(scale).*ub(scale)>0)
error('Log-scaled variables must not include 0 in their range');
end
% Decode chromosomes
Phen = zeros(Nind,Nvar);
lf = cumsum(len);
li = cumsum([1 len]);
Prec = .5 .^ len;
logsgn = sign(lb(scale));
lb(scale) = log( abs(lb(scale)) );
ub(scale) = log( abs(ub(scale)) );
delta = ub - lb;
Prec = .5 .^ len;
num = (~lin) .* Prec;
den = (lin + uin - 1) .* Prec;
for i = 1:Nvar,
idx = li(i):lf(i);
if code(i) % Gray decoding
Chrom(:,idx)=rem(cumsum(Chrom(:,idx)')',2);
end
Phen(:,i) = Chrom(:,idx) * [ (.5).^(1:len(i))' ];
Phen(:,i) = lb(i) + delta(i) * (Phen(:,i) + num(i)) ./ (1 - den(i));
end
expand = ones(Nind,1);
if any(scale)
Phen(:,scale) = logsgn(expand,:) .* exp(Phen(:,scale));
end