Reputation: 2005
I am trying to build a neural surrogate using Flux.jl, the goal is to develop a function which is comparable to kriging
function in estimating interpolated values.
The code is shown below:
using Plots
using Surrogates
using Flux
f(x) = sin(x)
x = range(0, 10.0, length = 9)
x= Float32.(x)
y = f.(x);
scatter(x,y)
model1 = Chain(
Dense(1, 5, σ),
Dense(5,2,σ),
Dense(2, 1)
)
neural = NeuralSurrogate(x, y, model = model1, n_echos = 5);
#surrogate_optimize(schaffer, SRBF(), lower_bound, upper_bound, neura, SobolSample(), maxiters=20, num_new_samples=10)
x_test = range(0, 10.0, length = 101)
x_test= Float32.(x_test)
res = [neural(i) for i in x_test]
plot!(x_test, result)
However, I am getting a method error, as following:
MethodError: no method matching NeuralSurrogate(::Array{Float32,1}, ::Array{Float32,1}; model=Chain(Dense(1, 5, σ), Dense(5, 2, σ), Dense(2, 1)), n_echos=5)
May I know what is the cause of this error? And how may i resolve this issue?
Upvotes: 2
Views: 103
Reputation: 2162
The NeuralSurrogate
constructor requires a lower and upper bound. The examples in the Surrogates.jl docs show this but if you're unsure you can always use the methods
function.
julia> methods(NeuralSurrogate)
2 methods for type constructor:
(::Type{NeuralSurrogate})(x, y, lb, ub; model, loss, opt, n_echos) in Surrogates at /srv/julia/pkg/packages/Surrogates/3CmhS/src/NeuralSurrogate.jl:24
(::Type{NeuralSurrogate})(x::X, y::Y, model::M, loss::L, opt::O, ps::P, n_echos::N, lb::A, ub::U) where {X, Y, M, L, O, P, N, A, U} in Surrogates at /srv/julia/pkg/packages/Surrogates/3CmhS/src/NeuralSurrogate.jl:4
A working example:
using Plots
using Surrogates
using Flux
lb = 0.0
ub = 10.0
f(x) = sin(x)
x = range(lb, ub, length = 9)
x= Float32.(x)
y = f.(x);
scatter(x,y)
model1 = Chain(
Dense(1, 5, σ),
Dense(5,2,σ),
Dense(2, 1)
)
neural = NeuralSurrogate(x, y, lb, ub, model = model1, n_echos = 5);
x_test = range(lb, ub, length = 101)
x_test= Float32.(x_test)
res = [neural(i) for i in x_test]
plot!(x_test, res)
Upvotes: 3