from lmfit.models import LinearModel as lm
linmodel = lm()
from lmfit.models import ConstantModel as cm
constmodel = cm()
import numpy as np
xdata = np.linspace(0,10,11)
linpoints = linmodel.eval(x=xdata, intercept=1., slope=2.)
constpoints = constmodel.eval(x=xdata, c=2.)
print("linear: " + str(type(linpoints)))
print("constant: " + str(type(constpoints)))Yeah, that is a problem. I think that `Model.eval()` would have to be changed to`return np.asarray(func(**self.make_funcargs(params, kwargs))`This would complicate (somewhat) the case where `Model.eval()` is given a float as `x` (as in "evaluate this model at a particular value for the independent variable"). Currently, that returns a float, and with this change it would return an ndarray of length 1.But that is what the documentation says, so at least that is defensible!Anyone have a strong opinion on this? I don't if anyone is relying on the type returned from evaluating of a model at a single value for the independent variable(s).--Matt
Hi Matt,On Tuesday, February 12, 2019 at 3:11:01 PM UTC+1, Matt Newville wrote:Yeah, that is a problem. I think that `Model.eval()` would have to be changed to`return np.asarray(func(**self.make_funcargs(params, kwargs))`This would complicate (somewhat) the case where `Model.eval()` is given a float as `x` (as in "evaluate this model at a particular value for the independent variable"). Currently, that returns a float, and with this change it would return an ndarray of length 1.But that is what the documentation says, so at least that is defensible!Anyone have a strong opinion on this? I don't if anyone is relying on the type returned from evaluating of a model at a single value for the independent variable(s).--MattI'm not stating that the documentation is wrong per se. But I think it is a bit misleading at least. If the data parameter ("x=...") is provided, I would expect that the return value has the same type, as well as the same mathematical dimension (size()) as that given data.
Implicitly I would expect that there is some function -- or model -- and one would like to evaluate it at the provided values. Regardless of what the function/model is. This is the part that somewhat astounded me, as can be seen from the test snippet.
To me it seems very annoying, if not plainly wrong, to effectively overload the return type of a method depending on the subtype of the object.
--Cheers, Christoph
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 post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/d4491830-c53c-450b-8377-b375cc0dc532%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.