How to setup LMFit constraints

20 Views Asked by At

I've tried to look at other SO answers, but they always have these complicated setups or equations that I can never wrap around my head around how LMFit handles constraints or how they should be setup.

https://lmfit.github.io/lmfit-py/constraints.html

Let's say you have 4 variables

pars = Parameters()
pars.add('A', value=5)
pars.add('B', value=5)
pars.add('C', value=5)
pars.add('D', value=5)

You want to put some constraint

A+B > C+D

The document example states to set some arbitrary variable with some min and max for the value you want. So in this case would it be something like this?

pars.add('delta', max=0)
pars.add('D', value=5,expr='delta+A+B-C')

The logic being per documentation

A+B > C+D
C+D-A-B < 0 
C+D-A-B = delta where delta < 0  
D < A+B-C

So the final setup

pars = Parameters()
pars.add('A', value=5)
pars.add('B', value=5)
pars.add('C', value=5)
pars.add('delta', max=0)
pars.add('D', value=5,expr='delta+A+B-C')

Just trying to see if I"m understanding this correctly. t

0

There are 0 best solutions below