Closed lesshaste closed 4 years ago
lambdas = parameters(', '.join(['lambdas{}'.format(idx) for idx in range(4)]))
ps = parameters(', '.join(['ps{}'.format(idx) for idx in range(4)]))
model = 0
for idx in range(4):
ps[idx].min = 0.01
lambdas[idx].min = 0.01 # Better to use bounds than constraints where able.
model += ps[idx] * lambdas[idx]*exp(-lambdas[idx]*x)
Something like this, you should be able to figure out the rest from here. There's probably an even shorter and better sympy way of writing this, but meh. As a last note, don't do Ge(ps2, 0.01)
to bound the value of your parameters. Use bounds instead, those are much easier to solve for numerically.
Thanks so much. I really didn't realise string joins would be the answer!
Thanks also for the advice about constraints versus bounds. If that isn't documented in symfit it might be worth adding it as it's not at all obvious why it should make a difference.
Good idea, we'll definitely look into it :)
I am trying to maximize a likelihood function which has several parameters. For example:
This works OK but is increasingly awkward to write as the number of ps and lambdas variables increases. How can this code be generalized to work with an arbitrary number of parameters? The number of ps and lambdas variables is always equal.