[Python] Solution to syntax problem in using "differential_evolution()" in scipy

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to minimise a complex problem (non-linear) with differential_evolution method in scipy. Key syntaxes are given below

    a) I am creating an object assigned to differential_evolution

    res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), streategy='belst1bin', maxiter=1000, popsize=15, disp =True, tol=1e-6 )


    b) bounds are provided as tuples in the following form, the len(bounds) == len(x)

    bounds = [ (0,1000), (0,1000),........ , (-1000,1000)]


    depending on the nature of corresponding elements in x.

    c) loss-function is part of a class, the definition of the self is accomplished through def __init__().

    def loss_function(self, x, input_series,ilt,bhpgrad, q_obs):


    Note that there are 4 constants which shall not be optimized by differential_evolutions, but needs to execute them. These constants are being passed through args = (.......) method.

    I get the following error:

    res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), \
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: differential_evolution() got multiple values for argument 'args'


    I don't understand why this is happening or how to fix it.

    Continue reading...

Compartilhe esta Página