Surrogates.jl icon indicating copy to clipboard operation
Surrogates.jl copied to clipboard

Optimization function mutates surrogate struct

Open vikram-s-narayan opened this issue 2 years ago • 2 comments

The optimization functions in surrogates mutate the surrogate struct.

To reproduce:

using Surrogates

#sphere function
function s(x)
    return sum(x .^ 2)
end

n = 30
d = 3
lb = [-10.0 for i in 1:d]
ub = [10.0 for i in 1:d]
x = sample(n, lb, ub, SobolSample())
y = s.(x)

r = RadialBasis(x, s.(x), lb, ub, rad = linearRadial())

size(r.x) #(30,)
size(r.y) #(30,)

surrogate_optimize(s, SRBF(), lb, ub, r, UniformSample())

size(r.x) #(165,)
size(r.y) #(165,)

Should we be indicating that the function mutates with the ! convention (i.e. surrogate_optimize!(s, SRBF(), lb, ub, r, UniformSample()))?

vikram-s-narayan avatar Jul 16 '22 10:07 vikram-s-narayan

Yes it should have a !

ChrisRackauckas avatar Jul 16 '22 12:07 ChrisRackauckas

This also confused me for a bit.

ablaom avatar Oct 02 '23 21:10 ablaom