symbolic model function passing

69 views
Skip to first unread message

Zohreh Karimzadeh

unread,
Jul 28, 2022, 7:12:20 AM7/28/22
to lmfit-py
Hi lmfit!
I stuck in my fitting due to my symbolic function,
Please kindly let me know how this issue could be solved here is my code, I need to pass tow indep_var which are xCl and XI and a is parameter:
********************************************
import numpy as np
import lmfit
import sympy as sp

anion = {'I': 1, 'Cl': 1}
xa = {'I': 0.2, 'Cl': 0.3}
xCl = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
xI = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.1, 0.8, 0.11, 0.12]
ydat = [0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]

def g(anion, xa, a):
     xzc = 0
     for k1, k2 in zip(anion, xa):
         xzc += sp.symbols(f"x{k1}") * sp.symbols(f"x{k2}") + a
      return xzc
obj = lmfit.Model(g, independent_vars=['xCl', 'xI'])
pars = obj.make_params(a=0.1)

result = mod.fit(ydat, pars, xCl, xI)
print(result.fit_report())

but I' ve found;
**************************************************
Traceback (most recent call last):
  File "F:\Zohreh\MainZohreh\postdoc-field\CSU\pythonProject\simple_Lmfit.py", line 36, in <module>
    obj = lmfit.Model(g, independent_vars=['xCl', 'xI'])
  File "C:\Users\Zohreh\AppData\Roaming\Python\Python310\site-packages\lmfit\model.py", line 277, in __init__
    self._parse_params()
  File "C:\Users\Zohreh\AppData\Roaming\Python\Python310\site-packages\lmfit\model.py", line 541, in _parse_params
    raise ValueError(self._invalid_ivar % (arg, fname))
ValueError: Invalid independent variable name ('xCl') for function g
*********************************************************

Zohreh Karimzadeh

unread,
Jul 29, 2022, 12:55:49 AM7/29/22
to lmfit-py
********************************************
import numpy as np
import lmfit
import sympy as sp

anion = {'I': 1, 'Cl': 1}
xa = {'xI': 0.2, xCl': 0.3}

xCl = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
xI = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.1, 0.8, 0.11, 0.12]
ydat = [0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]

def g( xa, anion a):

     xzc = 0
     for k1, k2 in zip(anion, xa):
         xzc += sp.symbols(f"x{k1}") * sp.symbols(f"x{k2}") + a
      return xzc
obj = lmfit.Model(g, independent_vars=['xCl', 'xI'])
pars = obj.make_params(a=0.1)

result = mod.fit(ydat, pars, xCl, xI)
print(result.fit_report())

but I' ve found;
**************************************************
In fact here just a is parameter and xa   includes independent variables.(xI and xCl)
1. Should I explicitly name the independent var here??
2. I don't know about data, numpy array or not?

Matt Newville

unread,
Jul 29, 2022, 9:20:07 AM7/29/22
to lmfit-py
Hi Zohreh,


The independent variables named in `lmfit.Model` need to match names of the arguments in the model function.  Your model function has
arguments `xa`, `anion`, and `a`, but not `xCl` or `xI`.  Neither `xCl` nor `xI` makes sense as independent variables.  

Data should be numpy arrays, preferably with dtype of float64.

I do not understand your use of sympy, and suspect that will prevent your model function from actually running. 

For sure,  always verify that you can run the model function with sensible inputs and get a sensible result before trying to use it in a fit.
 

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/ff67ca37-e1b1-436e-8a34-c56e3f09a31an%40googlegroups.com.


--Matt 

Zohreh Karimzadeh

unread,
Jul 29, 2022, 9:40:36 PM7/29/22
to lmfi...@googlegroups.com
Thank you for replying to my question.
I have a very big equation with almost 20 parameters that are provided automatically, so I should drive equation by sympy and then pass it to lmfit to fit it and find parameters. Automatically drived parameters is hard to passe explicitly in a function. Can I pass my func model by callable instance of a class??
Or as I found in lmfit documents, the lambdifed  sympy expression can be passed to model. Can I use this approach for very big equation??

Zohreh Karimzadeh

Contact me on
           +989102116325
                     and at
     z.kari...@gmail.com
                                 🌧️🌍🌱
   

Matt Newville

unread,
Jul 30, 2022, 2:02:26 PM7/30/22
to lmfit-py
On Fri, Jul 29, 2022 at 8:40 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Thank you for replying to my question.
I have a very big equation with almost 20 parameters that are provided automatically, so I should drive equation by sympy and then pass it to lmfit to fit it and find parameters.

Sorry, I don't really understand this.  I do not understand how "I have a complicated model" leads you to conclude that you should use sympy.  I do not mean that you should not use sympy, just that it is not at all obvious that you need to.  I've only used sympy a bit, only for symbolic algebraic work, and never when working with data.  Maybe I'm missing something...

Automatically drived parameters is hard to passe explicitly in a function. Can I pass my func model by callable instance of a class??

A model function can definitely be a class *method*.  But the model function or method needs to return the numerical values (preferably a numpy array of float64) for the model calculated with the input parameters. I think a model function cannot be a class instance by itself, because a callable class returns itself, not a numerical array of data to consider as the model.

I don't know if that answers your question.

Or as I found in lmfit documents, the lambdifed  sympy expression can be passed to model. Can I use this approach for very big equation??


I am not certain what "lambdified sympy expression" means to you.  It is always helpful to provide a minimal working code that shows what you are trying to do.

I think you will find it easier to write a Python function that models some behavior you want to model and then build from there.   If "big equation with many parameters" is a cause for concern, I definitely recommend starting simple and working your way towards complexity.   

Then again, I really do not understand what you are trying to do.  I also don't really know if your comments and questions in this message are actually related to your previous questions.
 
--Matt 

Zohreh Karimzadeh

unread,
Aug 2, 2022, 11:00:24 PM8/2/22
to lmfit-py
Than you Matt
Can I ask how nonindependent variables (x) can be passed in function using **kwargs?
As you stated:

from lmfit import Model, Parameters

def my_poly(x, **params):
val= 0.0
parnames = sorted(params.keys())
for i, pname in enumerate(parnames):
val += params[pname]*x**i
return val

my_model = Model(my_poly)

# Parameter names and starting values
params = Parameters()
params.add('C00', value=-10)
params.add('C01', value= 5)
params.add('C02', value= 1)
params.add('C03', value= 0)
params.add('C04', value= 0)

x = np.linspace(-20, 20, 101)
y = -30.4 + 7.8*x - 0.5*x*x + 0.03 * x**3 + 0.009*x**4
y = y + np.random.normal(size=len(y), scale=0.2)

out = my_model.fit(y, params, x=x)
In fact I need to pass  independent variables  x1, x2, ... in similar way to parameters. Will it be possible?
Regards,
Zohreh

Matt Newville

unread,
Aug 2, 2022, 11:46:06 PM8/2/22
to lmfit-py
Hi Zohreh, 

On Tue, Aug 2, 2022 at 10:00 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Than you Matt
Can I ask how nonindependent variables (x) can be passed in function using **kwargs?

Sure.

As you stated:

from lmfit import Model, Parameters

def my_poly(x, **params):
val= 0.0
parnames = sorted(params.keys())
for i, pname in enumerate(parnames):
val += params[pname]*x**i
return val

my_model = Model(my_poly)

# Parameter names and starting values
params = Parameters()
params.add('C00', value=-10)
params.add('C01', value= 5)
params.add('C02', value= 1)
params.add('C03', value= 0)
params.add('C04', value= 0)

x = np.linspace(-20, 20, 101)
y = -30.4 + 7.8*x - 0.5*x*x + 0.03 * x**3 + 0.009*x**4
y = y + np.random.normal(size=len(y), scale=0.2)

out = my_model.fit(y, params, x=x)

Ok.

In fact I need to pass  independent variables  x1, x2, ... in similar way to parameters. Will it be possible?

Well, if you explicitly add those to the function definition and set those as independent variables when you create the model, that should work.  Did you try that?

--Matt 

Zohreh Karimzadeh

unread,
Aug 3, 2022, 6:26:43 AM8/3/22
to lmfi...@googlegroups.com
I just have a dictionary of independent variables. 
How can pass them in function, both parameters and independent variables that are dictionaries.


Zohreh Karimzadeh

Contact me on
           +989102116325
                     and at
     z.kari...@gmail.com
                                 🌧️🌍🌱
   
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.

Matt Newville

unread,
Aug 3, 2022, 8:59:18 AM8/3/22
to lmfit-py
On Wed, Aug 3, 2022 at 5:26 AM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
I just have a dictionary of independent variables. 
How can pass them in function, both parameters and independent variables that are dictionaries.

The independent variables must be explicitly named arguments of the model function.  

--Matt 

Zohreh Karimzadeh

unread,
Aug 3, 2022, 1:10:43 PM8/3/22
to lmfi...@googlegroups.com
Dear Matt
Can I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.


Zohreh Karimzadeh

Contact me on
           +989102116325
                     and at
     z.kari...@gmail.com
                                 🌧️🌍🌱
   
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.

Matt Newville

unread,
Aug 3, 2022, 1:57:00 PM8/3/22
to lmfit-py
On Wed, Aug 3, 2022 at 12:10 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Can I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.

Yes. Using `minimize` you would have to manage any concept like "the data" or "independent parameters" on your own, inside the objective function.

Please read the docs and study the examples.  If you have follow-up questions, include actual code and ask questions about that.  

--Matt 

Zohreh Karimzadeh

unread,
Sep 6, 2022, 7:55:51 AM9/6/22
to lmfit-py
Dear Matt
Thanks for considering.
I've tried to examine all the known fitting  package in python like symfit, scipy, lmfit to consider my issue which is:
wrapping a code which gets,  expr, list_var, list_para, dict_data, do some fitting and gives fitted parameters.
Because all the named inputs are changing dynamically based on user input, so seemingly it is impossible to define or write fit_function explicitly:
 
def fit_function(expr, list_var, list_para, dict_data(key_var,list_data) ) ->list_para:

AS a function to be used for any expression, any number of variables/parameters.
Please let me know weather I'm not going in right way, so any suggestion eagerly will be welcomed.
Regards

Zohreh Karimzadeh

unread,
Sep 6, 2022, 8:34:36 AM9/6/22
to lmfi...@googlegroups.com
It seems this job would be possible because commonly in  Matlab and Maple a similar process is happening.
Zohreh Karimzadeh
Skype Name 49a52224a8b6b38b
Twitter Account @zohrehkarimzad1
+989102116325                                                        
((((((((((((((((Value Water)))))))))))))))


On Tue, Sep 6, 2022 at 4:25 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Thanks for considering.
I've tried to examine all the known fitting  package in python like symfit, scipy, lmfit to consider my issue which is:
wrapping a code which gets,  expr, list_var, list_para, dict_data, do some fitting and gives fitted parameters.
Because all the named inputs are changing dynamically based on user input, so seemingly it is impossible to define or write fit_function explicitly:
 
def fit_function(expr, list_var, list_para, dict_data(key_var,list_data) ) ->list_para:

AS a function to be used for any expression, any number of variables/parameters.
Please let me know weather I'm not going in right way, so any suggestion eagerly will be welcomed.
Regards

On Wednesday, August 3, 2022 at 10:27:00 PM UTC+4:30 Matt Newville wrote:
On Wed, Aug 3, 2022 at 12:10 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Can I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.

Yes. Using `minimize` you would have to manage any concept like "the data" or "independent parameters" on your own, inside the objective function.

Please read the docs and study the examples.  If you have follow-up questions, include actual code and ask questions about that.  

--Matt 

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.

Matt Newville

unread,
Sep 6, 2022, 1:43:27 PM9/6/22
to lmfit-py
Hi Zohreh, 

On Tue, Sep 6, 2022 at 6:55 AM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Thanks for considering.
I've tried to examine all the known fitting  package in python like symfit, scipy, lmfit to consider my issue which is:
wrapping a code which gets,  expr, list_var, list_para, dict_data, do some fitting and gives fitted parameters.
Because all the named inputs are changing dynamically based on user input, so seemingly it is impossible to define or write fit_function explicitly:
 
def fit_function(expr, list_var, list_para, dict_data(key_var,list_data) ) ->list_para:

AS a function to be used for any expression, any number of variables/parameters.
Please let me know weather I'm not going in right way, so any suggestion eagerly will be welcomed.
Regards


If I understand correctly (and I am not confident that I do!),  you're trying to develop a function or application that accepts single-line expressions and then wants to be able to fit data to that.  If so, you might find ExpressionModel() helpful. 

But it also seems like you're expecting user-supplied variations in what the names are for parameter and independent variables. 
To be honest, doing this in simple cases (where, say, the independent variable is "x", and is an array of the same length as the "y" data), should be pretty easy with ExpressionModel.  (Note that it does have an `independent_variables` argument and an `init_script` argument that can be used to set up functions, etc).

Doing this sort of thing in the most general case possible is actually pretty challenging.  Maybe obviously, the expression needs to be parsed as Python syntax (actually using `asteval`).  Symbols in the expression are identified lexically, and then someone has to decide whether each of those falls into the categories of "internally-identified symbols for function, built-in values", "independent variables", and "parameters".   Really, some person has to decide that.  If someone says the expression is

    "a + b*c(d*e+f)"

all we know is that "c" is a function. For sure, you could impose some conventions like expecting that "x" is an independent parameter of the same length as the data. To be clear, that is a huge simplification of "all possibilities", but it might be sufficient.

That's all just to say, that maybe it is actually pretty easy, or maybe it is actually pretty hard ;).







On Wednesday, August 3, 2022 at 10:27:00 PM UTC+4:30 Matt Newville wrote:
On Wed, Aug 3, 2022 at 12:10 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Can I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.

Yes. Using `minimize` you would have to manage any concept like "the data" or "independent parameters" on your own, inside the objective function.

Please read the docs and study the examples.  If you have follow-up questions, include actual code and ask questions about that.  

--Matt 

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
Message has been deleted

Zohreh Karimzadeh

unread,
Sep 6, 2022, 11:24:38 PM9/6/22
to lmfit-py
Dear Matt
I went through your example code in the documentation:

from lmfit.models import ExpressionModel
expr = 'off + amp * exp(-x/x0) * sin(x*phase)'
mod = ExpressionModel(expr)
from numpy import exp, linspace, sin
off=0.25, amp=1.0, x0=2.0, phase=0.04
x = linspace(0, 10, 501)
params = mod.make_params(??????)
x1=x1_vals, ...
y = mod.eval(params, ???)
out = mod.fit(y, params, x=x)
It worked pretty nice. As can be seen in code my first issue is done since the expr can be passed this way(green background color) while I'm wondering if there is any way to do the following stuff:
1. How params can be passed instead writing explicitly since it will be my user input.(Even after parsing expression or using evalast it should be passed not in the way is shown here.yellow background)
2. What if I have more than one independent variable that again needs to be passed not explicitly like params.(gray background)
Please kindly let me know about it.
Regards,

Zohreh Karimzadeh

unread,
Sep 9, 2022, 11:08:37 AM9/9/22
to lmfi...@googlegroups.com
Dear Matt
Based on the lmfit documentation on github it is unclear whether  more than one independent variable can be passed in mod.eval(params, ???) or not. I'm looking forward to hearing from you.
Regards,
Zohreh Karimzadeh
Skype Name 49a52224a8b6b38b
Twitter Account @zohrehkarimzad1
+989102116325                                                        
((((((((((((((((Value Water)))))))))))))))

Matt Newville

unread,
Sep 9, 2022, 1:26:40 PM9/9/22
to lmfit-py
On Fri, Sep 9, 2022 at 10:08 AM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Based on the lmfit documentation on github it is unclear whether  more than one independent variable can be passed in mod.eval(params, ???) or not.

Independent variable(s) are passed in as key/value pairs to `Model.eval` and `Model.fit`.  I don't know what `???` is supposed to represent.

It is common to do `Model.eval(params, x=x)`, because `x` is a common "independent variable".  If the model also has an independent variable of `pressure`, then you would do (actually, you would *have to do*). `Model.eval(params, x=x, pressure=pressure)`.  

I'm looking forward to hearing from you.

It is greatly preferred that you ask questions about actual code, giving real examples.


from lmfit.models import ExpressionModel
expr = 'off + amp * exp(-x/x0) * sin(x*phase)'
mod = ExpressionModel(expr)

I do not understand this color coding. Please post plain text.
from numpy import exp, linspace, sin
off=0.25, amp=1.0, x0=2.0, phase=0.04
x = linspace(0, 10, 501)
params = mod.make_params(??????)
x1=x1_vals, ...
y = mod.eval(params, ???)

I don't know what the ??? means. 

out = mod.fit(y, params, x=x)
It worked pretty nice. As can be seen in code my first issue is done since the expr can be passed this way(green background color)
while I'm wondering if there is any way to do the following stuff:
1. How params can be passed instead writing explicitly since it will be my user input.(Even after parsing expression or using evalast it should be passed not in the way is shown here.yellow background)

I am not certain I understand this (is this a question?).  I think you must be asking about how to pass in initial parameter values to make a set of Parameters for a model.   Are you asking to find out what the names of the Parameters are? (that would be `mod.param_names`).  It is necessary to give initial values for all parameters, of course.


2. What if I have more than one independent variable that again needs to be passed not explicitly like params.(gray background)

I think this must be the same question as above, but I have to admit I'm not certain of that.
--Matt 

Zohreh Karimzadeh

unread,
Sep 9, 2022, 1:36:44 PM9/9/22
to lmfi...@googlegroups.com
Dear Matt 
Thank for answering, 
1. Independent variables can be passed if it constantly is changing by user.
2. How dictionary of initial values of parameters can be passed if this dictionary is changing by user.
Regards


Zohreh Karimzadeh

Contact me on
           +989102116325
                     and at
     z.kari...@gmail.com
                                 🌧️🌍🌱
   
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.

Zohreh Karimzadeh

unread,
Sep 10, 2022, 9:07:38 AM9/10/22
to lmfi...@googlegroups.com
Dear Matt
Sorry to bother you again!
Here is my goal. AS a function to be used for any expression, any
number of variables/parameters.
--------------------------------------------------------------------
def fit_function(expr, list_var, list_para,
dict_data(key_var,list_data) ) ->list_para:
------------------------------------------------------------------------
I am trying to develop a function or application that accepts
single-line expressions, list_var, list_para,
dict_data(key_var,list_data and then be able to fit data to that. So,
you suggested the ExpressionModel() to me.
I find this code in documentation which worked pretty well:
------------------------------------------------------------
from lmfit.models import ExpressionModel
from numpy import exp, linspace, sin
expr = 'off + amp * exp(-x/x0) * sin(x*phase)'
mod = ExpressionModel(expr)
x = linspace(0, 10, 501)
params = mod.make_params(off=0.25, amp=1.0, x0=2.0, phase=0.04)
y = mod.eval(params, x=x)
out = mod.fit(y, params, x=x)
----------------------------------------------------------------------------
Here I can pass any expression as I want but what about
mod.make_params(), mod.eval() and mod.fit()
I am expecting to pass supplied variations in parameters and
independent variables something like this:
------------------------------------------------------------
from lmfit.models import ExpressionModel
from numpy import exp, linspace, sin
expr = 'off + amp * exp(-x/x0) * sin(x*phase)'
mod = ExpressionModel(expr)
x = linspace(0, 10, 501)
a =dict(off=0.25, amp=1.0, x0=2.0, phase=0.04)
b = dict( x=x)
params = mod.make_params()
y = mod.eval(params,b)
out = mod.fit(y, params, b)
----------------------------------------------------------------.
But I got an error:
y = mod.eval(params, b)
TypeError: Model.eval() takes from 1 to 2 positional arguments but 3 were given

It means params have not been added. Is there any way to do it?
so any suggestion eagerly will be welcomed.
Zohreh

Zohreh Karimzadeh
Skype Name 49a52224a8b6b38b
Twitter Account @zohrehkarimzad1
+989102116325
((((((((((((((((Value Water)))))))))))))))


On Fri, Sep 9, 2022 at 10:06 PM Zohreh Karimzadeh

Zohreh Karimzadeh

unread,
Sep 10, 2022, 11:03:56 AM9/10/22
to lmfi...@googlegroups.com
a should be passed this way:
params = mod.make_params(a)

On Sat, Sep 10, 2022 at 5:37 PM Zohreh Karimzadeh

Matt Newville

unread,
Sep 11, 2022, 9:55:19 AM9/11/22
to lmfit-py
Zohreh,

My uncertainty about what 

On Sat, Sep 10, 2022 at 8:07 AM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:
Dear Matt
Yes, that message is complaining that you passed a second (okay, third) positional argument to `Model.eval` and that it wants no more than one (okay, two) positional argument(s).   Admittedly, Python methods are a bit confusing, as the instance `self` is counted as the first positional argument in such error messages -- `Model.eval` takes either 1 or 2 positional arguments, with one being the not-optional `self` that is your Model instance `mod`, and the (optional) second being a Parameters object.  All other arguments must be keyword arguments.  

Did you mean to say  `y = mod.eval(params, **b)` ?   Calling a function `f` with a dictionary 

     options = {'a': 8, 'switch1': False}
     out1 = f(options)
     out2 = f(**options)

are very, very different. This is a basic feature of Python. 

We are here to answer questions about lmfit, minimization, curve fitting, and so on.  But we do expect that people using this library know Python, are familiar with Numpy and mathematics, and also know how to interpret error messages.

--Matt

Zohreh Karimzadeh

unread,
Sep 12, 2022, 12:52:50 AM9/12/22
to lmfi...@googlegroups.com
Dear Matt
Finally ,thanks to your patience to answer my tedious question, my issue with lmfit on running a fit in a totally dynamic way has gone.:)
God bless you and big thanks to the lmfit team.
I send this code for all with similar problems.
Regards.
Zohreh Karimzadeh.
-----------------------------------------------------------
from lmfit.models import ExpressionModel
import matplotlib.pyplot as plt

expr = 'off + amp * exp(-x / x0) * sin(x * phase)'
mod = ExpressionModel(expr)
from numpy import exp, linspace, sin
x = linspace(0, 10, 501)
a = dict(off=0.25, amp=1.0, x0=2.0, phase=0.04)
b = dict(x=x)
params = mod.make_params(**a)
y = mod.eval(params, **b)
out = mod.fit(y, params, **b)
print(out.fit_report())
plt.plot(x, y, 'o')
plt.plot(x, out.init_fit, '--', label='initial fit')
plt.plot(x, out.best_fit, '-', label='best fit')
plt.legend()
plt.show()
-------------------------------------------------                                               
((((((((((((((((Value Water)))))))))))))))

Zohreh Karimzadeh
Skype Name 49a52224a8b6b38b
Twitter Account @zohrehkarimzad1
+989102116325                                                        
((((((((((((((((Value Water)))))))))))))))


--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages