Thanks for this, should have thought of this myself. I made some progress
by defining the functions as follows:
for y = 1:Y
function f2(x, y_now = y)
y_l = y_now-1
y_h = y_now+1
f(y) = f3(x, y)*pdf(LogNormal(mu_y, sig_y), y)
quadgk(f, y_l, y_h)
end
end
With this, I get back one single-valued function f2 for each value of y in
the loop, that I can evaluate at x:
> f2(5)
1-element Array{Float64,1}:
134.112
However, the optimization fails, since the function I construct seems to be
incorrectly specified for the Optim package to work:
> using Optim
> fminbox(f2, 1, 0, 2) # minimize over interval [0, 2], start at 1
`fminbox` has no method matching fminbox(::Function)
> optimize(f2, 0, 2) # minimize over interval [0, 2] using Brent's method
`eps` has no method matching eps(::Type{Int64})
I believe the second way of doing it would be the correct one, however I can't
interpret the error being thrown here. The only place eps appears in the source
code of Optim is when the tolerance levels for convergence of Brent's method
are set (both in optimize.jl
<https://github.com/JuliaOpt/Optim.jl/blob/master/src/optimize.jl> and
brent.jl), <https://github.com/JuliaOpt/Optim.jl/blob/master/src/brent.jl> but
I can't figure out what this error means or how I could fix it.
<https://github.com/JuliaOpt/Optim.jl/blob/master/src/brent.jl>