-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compute_F.m
54 lines (50 loc) · 1.91 KB
/
Compute_F.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 fun = Compute_F(x, h, w, c, bench)
%COMPUTE_F - Computes the objective function for the moving peak benchmark.
%
% Syntax: fun = Compute_F(x, h, w, c, bench)
%
% Inputs:
% x - Points at which the function is to be evaluated. Matrix (n,d), where n is the number of trial points and d is the dimension.
% h - Peak heights. Vector (m,1) for Benchmark 1 and matrix (m,d) for Benchmark 2.
% w - Peak widths. Vector (m,1) for Benchmark 1 and matrix (m,d) for Benchmark 2.
% c - Peak centers. Matrix (m,d) for Benchmark 1 and matrix (m,d) for Benchmark 2.
% bench - Either 'bench1' for Benchmark 1 or 'bench2' for benchmark2.
%
% Outputs:
% fun - The objective value. Vector (n,1).
%
% Example:
% fun = Compute_F(rand(10,3), rand(5,1), rand(10,1), rand(5,3), 'bench1')
% fun = Compute_F(rand(10,3), rand(5,3), rand(10,3), rand(5,3), 'bench2')
%
% Author: Lukas Adam
% Paper: L. Adam, X. Yao: A Simple Yet Effective Approach to Robust Optimization Over Time
% Email: [email protected]
% July 2019; Last revision: 17-Jul-2019
m = size(c,1);
n = size(x,1);
% Evaluate the objective. The inner if only minimizes the lenght of the for loop (makes the code faster).
fun = -Inf(n,1);
if strcmp(bench, 'bench1')
if m<n
for i=1:m
fun = max(fun, h(i) - w(i)*vecnorm(x-c(i,:), 2, 2));
end
else
for j=1:n
fun(j) = max(h - w.*vecnorm(x(j,:)-c, 2, 2));
end
end
elseif strcmp(bench, 'bench2')
if m<n
for i_m=1:m
fun = max(fun, h(i_m,:) - w(i_m,:).*abs(x-c(i_m,:)));
end
fun = mean(fun,2);
else
for i_n=1:n
fun(i_n) = mean(max(h - w.*abs(x(i_n,:)-c)));
end
end
end
end