Does LsqFit have constraint interval?

Hello everyone

I would like to know if I could specify a range for parameters when I perform a non-linear fit ?

For example, how to run something similar to

curve_fit(model, x, y, p, ?)

in such way that parameter p[1] must be between [1,2] and p[2] between [0,0.5]

or is there any package that compute non-linear fit and also does this for me ?

Thank you

What you can always do is use Optim.jl (or BlackBoxOptim.jl if your problem is hard) and add bounds in your error function, I usually define my penalties like this:

lower_bound(p,lb,α) = p < lb ? exp(α*(lb-p))-1 : 0.0

It’s not the most elegant or efficient solution, but usually it works well enough.

You can use the lower and upper keywords. In your example:

lower_p = [1.0; 0.0]
upper_p = [2.0; 0.5]
curve_fit(model, x, y, p; lower = lower_p, upper = upper_p)

I’m on julia v0.6.2 and LsqFit 0.3.0.

1 Like