Skip to content

Instantly share code, notes, and snippets.

@RohitRathore1
Created August 14, 2020 12:11
Show Gist options
  • Save RohitRathore1/e08e62afcf090b3c9e367e30078d5e94 to your computer and use it in GitHub Desktop.
Save RohitRathore1/e08e62afcf090b3c9e367e30078d5e94 to your computer and use it in GitHub Desktop.
Gists of surrogates package on which I am working
using Plots # hide
default(c=:matter, legend=false, xlabel="x", ylabel="y") # hide
using Surrogates # hide
function leon(x)
x1 = x[1]
x2 = x[2]
term1 = 100*(x2 - x1^3)^2
term2 = (1 - x1)^2
y = term1 + term2
end
n_samples = 80
lower_bound = [0, 0]
upper_bound = [10, 10]
xys = sample(n_samples, lower_bound, upper_bound, SobolSample())
y1 = leon.(xys);
x, y = 0:10, 0:10 # hide
p1 = surface(x, y, (x1,x2) -> leon((x1,x2))) # hide
xs = [xy[1] for xy in xys] # hide
ys = [xy[2] for xy in xys] # hide
scatter!(xs, ys, y1) # hide
p2 = contour(x, y, (x1,x2) -> leon((x1,x2))) # hide
scatter!(xs, ys) # hide
plot(p1, p2, title="True function") # hide
grad_x1 = x -> 2*(300*(x1)^5 - 300*(x1)^2*x2 + x1 -1)
grad_x2 = x -> 200*(x2 - (x1)^3)
d = 2
function create_grads(n, d, grad_x1, grad_x2, y)
c = 0
y2 = zeros(eltype(y[1], n*d))
for i in 1:n
y2[i + c] = grad_x1([x[i]])
y2[i + c + 1] = grad_x2(x[i])
c = c + 1
end
return y2
end
y2 = create_grads(n, d, grad_x1, grad_x2, y)
@ludoro
Copy link

ludoro commented Aug 16, 2020

Well go look at the line of the error and see where's the problem, I cannot help you by just looking at the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment