Search code examples
pythonoptimizationconstraintslmfit

Python lmfit impose subtle constraints


I'm dealing with the following question:

d1=-1/b1*log((p1*t-a1)/c1)
d2=-1/b2*log((p2*t-a2)/c2)
d3=-1/b3*log((p3*t-a3)/c3)

where a1,a2,a3,b1,b2,b3,c1,c2,c3,p1,p2,p3 are known, and theoretically d1=d2=d3>0, so I try to find the proper t to minimize (d1-d2)^2+(d2-d3)^2+(d3-d1)^2. I try to use lmfit to do it, but don't know to impose the restrictions like d>0 and the thing in log is greater than 0, namely (p*t-a)/c>0. There are simple examples in lmfit's document, in my case I don't know how to do. Can anybody helps? Thank you very much.


Solution

  • Assuming you know the values of b1, b2, b3, c1, c2, c3, you can place bounds on the value of t so that d1>0. If b1 is positive, d1>0 means that log((p1*t-a1)/c1) > 0, so that the argument to the log function is greater than 1 (not only "greater than 0"). That means p1*t-a1 > c1 or t > (c1 + a1)/p1, and so on. So, you can create a Parameter for t and set its minimum value to be the largest of [(c1+a1)/p1, (c2+a2)/p2, (c3+a3)/p3] to satisfy d1,d2,d3>0.