Search code examples
pythonminimizationchi-squared

Ways of ensuring parameters 'sum to one' during function minimisation


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!


Solution

  • 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?