-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two different syntaxes for getting Parameter values? #45
Comments
I always find these questions very hard... But here's my two cents. I'm in favor of the first syntax, since IMHO it's more Pythonic (attributes over getter functions). Optionally you could change it to EDIT: read up on Python documentation. |
Thanks for your reply. Upon reading it I realized I should have thought about my original post longer because I didn't specify all the problems I have with the current To get standard deviation in each paradigm you do assert fit_result.params.a_stdev == fit_result.stdev(a) (Btw, the first works by overloading However, this way of accesing the value and stdev has no consistent way of getting covariances between fit parameters. Therefore it would be nice to have one syntax which feels self-consistent. This is why I implemented the following functions (#43): fit_result.value(a)
fit_result.stdev(a)
fit_result.covariance(a, b)
fit_result.variance(a) They all have a similar feel to them, which is why I like them better. Now, the y = model(x=xdata, **fit_result.params) And then given the additional tasks of returning the value and stdev by attribute. (This is why it's So this is why currently my way of thinking is to get the values, covariance etc. with the new syntax but to still have fit_result.params as a simple One could even consider making The fact that all this originates from the need for having the ** shorthand hopefully also explains why |
Ok, that changes things. Now, a covariance between fit_result.stdev(a)
fit_result.covariance(a, b)
fit_result.variance(a) Then, for the sake of consistency you should also use
Or should you return a list of |
Coming back to this my view hasn't changed much. a = Parameter(3.14)
... # set up model and Fit object
fit_result = fit.execute()
Note that InteractiveGuess (PR #33) does |
To continue the disussion in #57, for me it would make sense to implement more Dict-like behaviour. I really like the ability to ** unpack, which suggests a dict, which makes me want to do this:
Which doesnt work because the key is a Parameter instance and not a string. This does work:
Would it make sense to change the def __getitem__(self, param):
"""
....
"""
if isinstance(param, Parameter):
param_name = str(param)
elif isinstance(param, str):
param_name = param
else:
#maybe some error raised
return getattr(self, param_name) |
Could work, but actually I think it would make more sense to change This would solve all these problems right? |
Hang on, I'm totally lost now. We have 3 (?) things related to parameters: Parameter objects, Model objects (which have a params attribute) and FitResults objects (which also have a params attribute). Requirements stated above:
Still unclear:
I think an OrderedDict fits all these requirements, but did I miss anything? |
Let me go through those points.
I think that also answers the unclear point. So yes, I think an OrderedDict should work right? And maybe another name to avoid confusion? |
Thanks. |
…dentity crisis. It has been replaced with an OrderedDict. However, Pitje06's point in #45 is now even more evident; confusion between the content of FitResults.params and Model.params is bound to arrise.
Is this still an issue? |
No, the switch to OrederedDicts has been made. Thanks |
Currently there are two different ways to get the value and stdev of a parameter:
This kinda conflicts with the principle that there should be only one obvious way to do something. Which is better?
If we decide to remove the first one, that means the ParameterDict object can be removed entirely and replaced with an OrderedDict. This is something I would like, as the current ParameterDict is kind of a "don't touch it, it works"-thing.
Furthermore, the second syntax is better when dealing with dynamically generated
Parameter
objects whose name you don't know or care about.The only thing going for the first one is that I think it's rather elegant.
@Jhsmit, @Pitje06, @Eljee What do you think?
The text was updated successfully, but these errors were encountered: