P227
P227

Reputation: 47

lmfit - unable to form simple minimisation problem

I am struggling to get what ought to be a fairly basic minimisation problem setup correctly using the lmfit package. Here is my code, which serves as a dumbed-down version of what I am working on.

import lmfit

class test_class:

    def __init__(self,A=None):

        self.A = A

def my_obj_fn(B,C=1.0,the_class=None):

    D = abs(B + C + the_class.A)

    return D

if __name__ == '__main__':

    awesome_class_instance = test_class(A=2.0)
    C_val = 3.0

    my_params = lmfit.Parameters()
    my_params.add('B',7.0,min=-10.0,max=12.0)

    key_word_args = {'C': C_val,
                    'the_class': awesome_class_instance,
                    }

    result = lmfit.minimize(

            fcn = my_obj_fn,
            params = my_params,
            kws = key_word_args,
            method = 'differential_evolution'
    )

    print(result)

The error I am getting is as follows

    ValueError: '3.0' is not a Parameters object

    The above exception was the direct cause of the following exception:
    
    ....
    RuntimeError: The map-like callable must be of the form f(func, iterable), returning a sequence of numbers the same length as 'iterable'

Clearly I am not setting up the code correctly. The documentation has not been helpful in understanding why this is not correct. Any help is appreciated.

Cheers

Upvotes: 0

Views: 45

Answers (0)

Related Questions