User Tools

Site Tools

Use lmfit with constraint parameters

In many applications, it is desirable to impose constraints like p0>=0 or 10<p1<10.

In lmfit, there is no explicit for mechanism for this, and it is unlikely that I will ever add one: In my experience, it is sufficient to mimick constraints by variable transform or by adding a penalty to the sum of squares. Variable transform seems to be the better solution.

In the above examples: To enforce p0'>0, use e.g. p0'=exp(p0) or p0'=p0^2. To enforce -10<p1'<10, use p1'=10*tanh(p1).