Hi there,
I’m trying to minimize a residual function f
using LsqFit.jl since it is the only package that uses Levenberg-Marquardt (trying to do a course where the instructions and assignments assume Matlab usage, and we were explicitly asked to use LM).
function residual(t,k,p)
...
end
which is a function of two variables t
and k
, and I want to optimize the parameter set p
.
I’ve run through the single variable example, but still trying to wrap my head around the multivariate example.
I’ve tried doing something like this:
@. model(x,p) = residual(x[:,1], x[:,2], p)
xdata = rand(2,2)
ydata = rand(2)
p = rand(6)
fit = curve_fit(model, xdata, ydata, p)
But end up with a Dimension Mismatch error during broadcasting.
I’ve narrowed the dimension mismatch error to just calling the model
model(xdata, p)
but I have no idea why.
Simple functions like
@. model(x,p) = x[:,1] + x[:,2] + p[1]
evaluate correctly. I think I’m just not understanding the @.
broadcasting stuff? Would be great if I could get some clarification.
Thanks!