0

I have an objective function that could consider a few parameters (a,b,c,d,...) depending on the number of datasets considered. Those parameters are bound in such a way that:

a+b+c+d +..+..<=1

Let suppose I have a,b,c and d; so a+b+c+d<=delta. I define:

a+b < delta-c-d (I call m=delta-c-d)

params = Parameters()
params.add('a', value=0.5, min=0., max=1.)
params.add('m', value=0.5)
params.add('b', expr='m -a')

with m=delta -c-d, so c= delta-m-d (I define n=m-d)

params.add('n', value=0.5)
params.add('delta', value=0.5)
params.add('c', expr='delta-n')

Finally n=m-d ==>d=m-n

params.add('d', expr='m-n')

Is this correct? How to set min and max for m,n and delta?

I followed the hints given on Python lmfit constraints: a < b < c

Cheers, Manuel

Manuel
  • 15
  • 3

1 Answers1

0

I guess that's OK. You can set min/max values on a constraint expression, as with

params.add('c', expr='delta-n', min=0, max=1)

But I should say that (if I understand your question correctly) I would probably do this as

params = Parameters()
params.add('a', value=0.25, min=0, max=1)
params.add('b', value=0.25, min=0, max=1)
params.add('c', value=0.25, min=0, max=1)
params.add('delta', value=0.05, min=0, max=1)
params.add('d', expr='1-(a+b+c+delta)', min=0, max=1)

that seems simpler to me... unless you do want to know the values of your m and n....

M Newville
  • 7,486
  • 2
  • 16
  • 29
  • 1
    I tried this way: `params.add('c', expr='1-(a+b+delta)', min=0, max=1)` --my problem considers three parameters-- but since a, b are free parameters in [0,1], it ends up with a+b+c >1. Also, I tried `params.add('b', expr='delta -a', min=0, max=1)` and `params.add('c', expr='delta -a- b', min=0, max=1)`; in this case a +b +c < 1, but most of the times it means b and c are equal to zero. Since I have three parameters a,b and c to fit, not sure if I must implement two constraints (`deltas`)? I am missing something. – Manuel Jul 07 '20 at 21:19