I’m trying to use LsqFit.jl to fit data that is complex (in the form x + im*y). For purposes of showing the problem, I’m using the example provided on GitHub for LsqFit but I’m changing the model such that it has an imaginary term in the exponential, rather than a real one.
I’ve tried the same thing in Matlab () using lsqcurvefit() with complex data and it works fine and extracts the correct parameters. I’m aware that a fitting procedure that involves complex data is going to be inherently different to simply fitting real data, but I cannot figure this out.
Yes, it looks like its levenberg_marquardt function assumes that the model results have the same type as the parameters (see the array allocations here), which is wrong in this case. They need to be a bit more careful in propagating the data types.
@stevengj: I tried to fix the problem. Extended the original tests in curve_fit.jl and curve_fit_inplace.jl to check with Float32, Float64, ComplexF32, ComplexF64. Only open problem for now is I’m running into problems with complex AD in ForwardDiff here
for ad in (T<:Complex ? (:finite,) : (:finite, :forward, :forwarddiff))
fit = curve_fit(model, xdata, ydata, p0; autodiff = ad)
@show fit.param
@assert norm(fit.param - [1.0, 2.0]) < 0.05
@test fit.converged
# can also get error estimates on the fit parameters
errors = margin_error(fit, 0.1)
@assert norm(errors - [0.017, 0.075]) < 0.01
end
Thanks very much for your help, it’s super great to know that you guys are willing to help fix the problem! This has been my first question I’ve posted during my PhD after switching from Matlab to Julia, and it’s great to know there is help out there. I look forward to seeing the progress on the resolution of this issue!
Hi @PazzyBoardman449, you said you got it working in matlab? Could you explain how? I’m trying to do something similar but the output I get is always exactly the same as my starting point. Couldn’t find an answer on any matlab forum, so that’s why I asked it here…