Thanks for you reply!
In fact, what I am trying to do is as following:
# -- define the model --
function expmodel(x, u)
y0, a, τ, t₀ = u
return y0 + a * exp(-(x-t₀)/τ)
end
# and unified residual function
function residualfn!(du, u, data)
(xs, ys) = data
du .= expmodel.(xs, Ref(u)) .- ys
return nothing
end
# -- so that I can fix arbitary parameter at ease --
# -- generate data --
Random.seed!(3465)
y0, a, τ, t₀ = 0.0, 1.0, 2.0, 0
xs = 0:0.1:3;
ys0 = expmodel.(xs, Ref([y0, a, τ, t₀])) # ideal data
ys = ys0 .+ randn(size(ys0)) .* 0.02 # add noise
# -- fit --
prob1 = NonlinearLeastSquaresProblem(
NonlinearFunction((du, u, data) -> residualfn!([du; 0.0], [u; t₀], data), resid_prototype = similar(ys)), [y0, a, τ], (xs, ys))
prob2 = NonlinearLeastSquaresProblem(
NonlinearFunction((du, u, data) -> residualfn!([du[1:2]; 0.0; du[3]], [u[1:2]; t₀; u[3]], data), resid_prototype = similar(ys)), [y0, a, t₀], (xs, ys))
prob3 = NonlinearLeastSquaresProblem(
NonlinearFunction((du, u, data) -> residualfn!([du; 0.0; 0.0], [u[1:2]; τ; t₀], data), resid_prototype = similar(ys)), [y0, a], (xs, ys))
But as you see, all three trials won’t work. And I couldn’t figure it out. Would you please have a look on that?