0

I'm trying to perform a minimisation where some parameters must sum to one using PyMinuit. I'm wondering if there is a standard method of implementing this kind of thing?

Is it usual to set the function to some large value if the constraint is not met? e.g.

def f(params):
    if params.sum() != 1:
        return 1e6
    else:
        ... compute actual value ...

Is it a very bad idea to normalise the parameters each round? e.g.

if params.sum() != 1:
    for param in params:
        param = param / params.sum()

Thanks!

user1353285
  • 191
  • 1
  • 10

1 Answers1

1

I think you probably want to alter things so that the constraint is baked in to your minimization. Without some more details about what you're doing, exactly, I'd try introducing a Lagrange multiplier. It's a pretty common thing to do in a freshman calculus course, so you should be able to find lots of examples online.

PS: Are you using PyMinuit because you're doing particle physics?

BenDundee
  • 4,389
  • 3
  • 28
  • 34
  • Thanks for the advice, I'll see if I can get Lagrange multipliers into the minimisation. The biggest problem I can see with doing it this way in my code is that the function `f` will be generated behind the scenes and passed to the minimisation routine. I think `SymPy` may be quite useful for getting the derivative at run-time though. P.S. I am doing particle physics, but the problem is based in nuclear. ;) – user1353285 Feb 19 '13 at 10:28
  • Yeah I was trying to think how you'd manage to minimize something with constraints NOT using Lagrange multipliers. – BenDundee Feb 19 '13 at 13:44