Skip to content
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

Always retain numerical keyword argument defaults #925

Closed
wants to merge 1 commit into from

Conversation

schtandard
Copy link
Contributor

Description

This change has numerical default values of model functions be used as inital values for fitting corresponding fitting parameters when the fitting parameters are explicitly chosen using Model's param_names argument, just like they are when the parameters are inferred from the function signature. This was proposed in #919 (though some of the discussion bled over to #920).

This is completely backward compatible, no existing code needs to be changed.

A note on the code structure

In principle, it would have been more natural to first only generate self._param_root_names (if it was None) and then fill the initial values (i.e. self.def_vals) for all parameters where this is possible irrespective of how self._param_root_names came to be (from the param_names argument or from automatic generation). However, in practice this made the code harder to read (and slightly less efficient) as essentially the same loop and tests would be performed twice in the case of automatic generation. I thus went with leaving the existing loop untouched and just handling the case where param_names was used separately.

Type of Changes
  • Bug fix
  • New feature
  • Refactoring / maintenance
  • Documentation / examples
Tested on
Python: 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)]

lmfit: 0.0.post2796+g4e2470a.d20231118, scipy: 1.11.3, numpy: 1.26.0, asteval: 0.9.31, uncertainties: 3.1.7
Verification

Have you

  • included docstrings that follow PEP 257?
    (As the present behavior is not described in the docstring, no docstrings were changed.)
  • referenced existing Issue and/or provided relevant link to mailing list?
  • verified that existing tests pass locally?
    (I get several warnings and three skipped tests, though.)
  • squashed/minimized your commits and written descriptive commit messages?
  • added or updated existing tests to cover the changes?
    (No tests were affected by the change. I can add some if you ask me to.)
  • updated the documentation and/or added an entry to the release notes (doc/whatsnew.rst)?
    (I did not add anything to doc/whatsnew.rst yet. I had a look at the file history and other PRs and it seems to be done in batch, separate from the PRs. I will add an entry if you ask me to.)
  • added an example?
    (Same as for test, I don't think any example was affected and I did not add a new one. Can do so if you ask me to.)

Really, the statement in the documentation was incorrect before. The
changed wording is now correct unless one chooses keyword arguments with
non-numerical default values as parameters (using param_names). Adding
this caveat does not seem worth the reduction in clarity though, as the
behavior is quite natural.
@newville
Copy link
Member

@schtandard I think this is resolved with #941

@newville newville closed this Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants