There is a statement in the manual of curve_fit
that
The model function, f(x, ...). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.
However, I would like to use as a model function a method of the class which is defined as:
def model_fun(self,x,par):
So, the first argument is not an independent variable, as you can see. Is there any way how I can use the method of a class as a model function for curve_fit
shx2
Sure, create an instance and pass its bound method:
class MyClass(object):
...
def model_fun(self,x,par): ...
obj = MyClass(...)
curve_fit(obj.model_fun, ...)
You can find a good explanation about bound/unbound/etc. in this question.
来源:https://stackoverflow.com/questions/16543610/class-method-as-a-model-function-for-scipy-optimize-curve-fit