-
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
Add convenience functions for multiple Parameter/Variable creation #27
Comments
After thinking about it some more, x, y = variables()
a, b = parameters() looks weird to me. As a user I would not understand how this could possibly work. How does it know I want two? At the very least I would expect to have to give an int as argument for the number I want. So I guess in this case the sympy way is better. Just as an aside, does the following look good? (x, y), (a, b) = variables('x y'), parameters('a b') I think it looks rather nice, and greatly reduces the number of lines needed! I'm thinking of adopting this as the official way of defining vars and params in the docs. |
Some other cool ideas for the parameter factory, given that you also should have some method of specifying default values and ranges: # value will be used as initial guess
a, b = parameters(a=1.0, b=2.0)
# Parameter will be initiated from the dict
c, d = parameters(c={'value': 1.0, 'min': 0.0}, d={'value': 2.0, 'fixed': True})
# The range of the param. Must be increasing in size. Does not support fixed kw nicely
a, e = parameters(a=(0.0, 1.0), e=(0.0, 1.1, 5.0))
# Or, taking even more inspiration from django:
c, d = parameters(c=1.0, c__min=0.0, d=2.0, d__fixed=True) In all of these the name of the keyword argument is used as the name of the parameter. I like a combination of the first two most: if only a number is supplied use it as an initial guess, if # Next level with djangoesque syntax to keep similarity with variables():
c, d = parameters('c d', c__min=0.0, d__value=2.0, d__fixed=True) |
Though some of these might reduce the numbers of lines of code, the main choice in what would be possible is not convenience rather than readability, since the main idea (as it strikes me) is to produce readable fitting, With that in mind I would say that the
Note the added comma, which in PEP8 is the best way to represent multiple variables. It might be however, that some fuzziness should be allowed (PEP8 is a style guide) and I'm not sure on the implementation of that. As for the Django-esque syntax, though it might be beautiful, I would at the very least not introduce it as standard. If it were possible for Django users and not be the norm, I would |
@Eljee, I agree with you that using a space as a separator is not nice. It's my other big annoyance about the way symbols are defined in sympy. (Apart from the violation of DRY) After talking to a mutual friend of ours I decided that parameter creation shouldn't be done with optional extra's. Instead, if other default guesses or ranges are required, you can always set them separately: a, b = parameters('a, b')
a.value = 2.0
a.min, a.max = 0.0, 10.0 I got a bit carried away earlier ;). I still don't like the violation of DRY though... But it is the least surprising to users, which is important. |
sympy support the following to make multiple symbols:
Although I'm not a big fan of determining the names from the string
x y z t
, symfit should have something similar:Or if you use the
inspect
for DRY philosophy used in single Argument definitions,The function itself would be a oneliner in the first case:
The text was updated successfully, but these errors were encountered: