Skip to content

Commit 5d70700

Browse files
Merge pull request #508 from sathvikbhagavan/sb/fix_rtea
test: revive RTEA optimization tests
2 parents c85d513 + 783708f commit 5d70700

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

lib/SurrogatesSVM/src/SurrogatesSVM.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function SVMSurrogate(x, y, lb, ub)
3333
end
3434
else
3535
for j in eachindex(x)
36-
X[j, :] = x[j]
36+
X[j, :] .= x[j]
3737
end
3838
end
3939
model = LIBSVM.fit!(SVC(), X, y)
@@ -46,7 +46,7 @@ end
4646

4747
function (svmsurr::SVMSurrogate)(val)
4848
n = length(val)
49-
return LIBSVM.predict(svmsurr.model, reshape(val, 1, n))[1]
49+
return LIBSVM.predict(svmsurr.model, reshape(collect(val), 1, n))[1]
5050
end
5151

5252
"""
@@ -65,7 +65,8 @@ function SurrogatesBase.update!(svmsurr::SVMSurrogate, x_new, y_new)
6565
svmsurr.model = LIBSVM.fit!(
6666
SVC(), reshape(svmsurr.x, length(svmsurr.x), 1), svmsurr.y)
6767
else
68-
svmsurr.model = LIBSVM.fit!(SVC(), transpose(reduce(hcat, svmsurr.x)), svmsurr.y)
68+
svmsurr.model = LIBSVM.fit!(
69+
SVC(), transpose(reduce(hcat, collect.(svmsurr.x))), svmsurr.y)
6970
end
7071
end
7172

lib/SurrogatesSVM/test/runtests.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ using SafeTestsets
2525
obj_N = x -> x[1]^2 * x[2]
2626
lb = [0.0, 0.0]
2727
ub = [10.0, 10.0]
28-
x = collect.(sample(100, lb, ub, RandomSample()))
28+
x = sample(100, lb, ub, RandomSample())
2929
y = obj_N.(x)
30-
svm = LIBSVM.fit!(SVC(), transpose(reduce(hcat, x)), y)
30+
svm = LIBSVM.fit!(SVC(), transpose(reduce(hcat, collect.(x))), y)
3131
my_svm_ND = SVMSurrogate(x, y, lb, ub)
3232
x_test = [5.0, 1.2]
3333
val = my_svm_ND(x_test)
3434
@test LIBSVM.predict(svm, reshape(x_test, 1, 2))[1] == val
35-
update!(my_svm_ND, [[1.0, 1.0]], [1.0])
36-
update!(my_svm_ND, [[1.2, 1.2], [1.5, 1.5]], [1.728, 3.375])
37-
svm = LIBSVM.fit!(SVC(), transpose(reduce(hcat, my_svm_ND.x)), my_svm_ND.y)
35+
update!(my_svm_ND, [(1.0, 1.0)], [1.0])
36+
update!(my_svm_ND, [(1.2, 1.2), (1.5, 1.5)], [1.728, 3.375])
37+
svm = LIBSVM.fit!(
38+
SVC(), transpose(reduce(hcat, collect.(my_svm_ND.x))), my_svm_ND.y)
3839
x_test = [1.0, 1.0]
3940
val = my_svm_ND(x_test)
4041
@test LIBSVM.predict(svm, reshape(x_test, 1, 2))[1] == val

src/VariableFidelity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function (varfid::VariableFidelitySurrogate)(val)
145145
end
146146

147147
"""
148-
add_point!(varfid::VariableFidelitySurrogate,x_new,y_new)
148+
update!(varfid::VariableFidelitySurrogate,x_new,y_new)
149149
150150
I expect to add low fidelity data to the surrogate.
151151
"""

test/optimization.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Surrogates
22
using LinearAlgebra
33
using QuasiMonteCarlo
4+
using SurrogatesSVM
45
#######SRBF############
56
##### 1D #####
67

@@ -86,16 +87,15 @@ my_linear_ND = LinearSurrogate(x, y, lb, ub)
8687
surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_linear_ND, SobolSample(),
8788
maxiters = 15)
8889

89-
#=
9090
#SVM
91-
lb = [1.0,1.0]
92-
ub = [6.0,6.0]
93-
x = sample(5,lb,ub,SobolSample())
94-
objective_function_ND = z -> 3*norm(z)+1
91+
lb = [1.0, 1.0]
92+
ub = [6.0, 6.0]
93+
x = sample(5, lb, ub, SobolSample())
94+
objective_function_ND = z -> 3 * norm(z) + 1
9595
y = objective_function_ND.(x)
96-
my_SVM_ND = SVMSurrogate(x,y,lb,ub)
97-
surrogate_optimize(objective_function_ND,SRBF(),lb,ub,my_SVM_ND,SobolSample(),maxiters=15)
98-
=#
96+
my_SVM_ND = SVMSurrogate(x, y, lb, ub)
97+
surrogate_optimize(
98+
objective_function_ND, SRBF(), lb, ub, my_SVM_ND, SobolSample(), maxiters = 15)
9999

100100
#Inverse distance surrogate
101101
lb = [1.0, 1.0]
@@ -276,26 +276,24 @@ num_centers = 2
276276
surrogate_optimize(objective_function_ND, SOP(num_centers), lb, ub, my_k_SOPND,
277277
SobolSample(), maxiters = 20)
278278

279-
#multi optimization
280-
#=
281-
f = x -> [x^2, x]
279+
f = x -> [x^2, x]
282280
lb = 1.0
283281
ub = 10.0
284-
x = sample(100, lb, ub, SobolSample())
285-
y = f.(x)
282+
x = sample(100, lb, ub, SobolSample())
283+
y = f.(x)
286284
my_radial_basis_smb = RadialBasis(x, y, lb, ub, rad = linearRadial())
287-
surrogate_optimize(f,SMB(),lb,ub,my_radial_basis_ego,SobolSample())
285+
surrogate_optimize(f, SMB(), lb, ub, my_radial_basis_smb, SobolSample())
288286

289-
f = x -> [x^2, x]
287+
f = x -> [x, sin(x)]
290288
lb = 1.0
291289
ub = 10.0
292-
x = sample(100, lb, ub, SobolSample())
293-
y = f.(x)
290+
x = sample(500, lb, ub, RandomSample())
291+
y = f.(x)
294292
my_radial_basis_rtea = RadialBasis(x, y, lb, ub, rad = linearRadial())
295293
Z = 0.8 #percentage
296294
K = 2 #number of revaluations
297295
p_cross = 0.5 #crossing vs copy
298296
n_c = 1.0 # hyperparameter for children creation
299297
sigma = 1.5 # mutation
300-
surrogate_optimize(f,RTEA(Z,K,p_cross,n_c,sigma),lb,ub,my_radial_basis_rtea,SobolSample())
301-
=#
298+
surrogate_optimize(f, RTEA(K, Z, p_cross, n_c, sigma), lb, ub,
299+
my_radial_basis_rtea, SobolSample(); maxiters = 10)

0 commit comments

Comments
 (0)