I have a parametric estimation problem which can be solved by Non-Linear Least Squares optimization. I have an analytical model with two unknown parameters x[0]
and x[1]
. I have a vector of my measured data samples, using which I write the cost function
.
function cost_function(x)
measured = data_read() # This is where I read my measured samples
model = analytical_model(x) # I calculate the values from my
analytical model method
residual = abs.(measured - model)
return residual
end
In LsqFit
package
in Julia, which has the Levenberg-Marquardt (LM)
implementation, there is only the method curve_fit
which takes in model
(analytical_model()
here), xdata
, p
, ydata
and it passes this function to the LM
optimizer. (i.e) model(xdata,p) - ydata
becomes the residual. But for me, my measured
and model
are both complex numbers and that is the reason I have to return the abs.()
.
I have tried
import LsqFit
result = LsqFit.levenberg_marquardt(cost_function, rand(2))
but it requires the jacobian of my cost_function(x)
as another argument. I do not know the Jacobian and I want my optimizer to calculate the Jacobian for me using Forward Difference approximation. Is there a way to do this in Julia?
sum(residual)
from your function. Note that Julia uses 1-based indexing, so probably you havex[1]
andx[2]
. – Bogumił KamińskiLevenberg-Marquardt
function implemented in this. The closest quadratic non-linear optimizer I found wasNewtonTrustRegion()
which does not work efficiently for me. Regarding the indexing, I am a python user and I am slowly shifting to Julia. But I did usex[1]
andx[2]
in my code though.. :) – Vijay Karthikcurve_fit
function in which you do not have to pass Jacobian and can choose forward difference approximation viaautodiff
kwarg. – Bogumił Kamińskicurve_fit
code which does what I mention in the summary. In LsqFit package in Julia, which has the Levenberg-Marquardt (LM) implementation, there is only the method curve_fit which takes inmodel (analytical_model() here)
,xdata
,p
,ydata
and it passes this function to the LM optimizer. (i.e)model(xdata,p) - ydata
becomes the residual. But I wantabs.(model(xdata,p) - ydata)
to be input to the residual. – Vijay KarthikFloat64
values; if they are e.g.BigFloat
then change the third argument accordingly). – Bogumił Kamiński