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

FIX: Update truncate_arrays and optimal_parameters to allow some zeros #122

Merged
merged 2 commits into from Mar 29, 2020

Conversation

bocklund
Copy link
Member

Users who had any zeros in their initial parameters would see an error when calling optimal_parameters ending in:

  File "/Users/brandon/Projects/espei/espei/utils.py", line 110, in optimal_parameters
    for i in range(nz[-1][-1]):

IndexError: index -1 is out of bounds for axis 0 with size 0

The trace and lnprob arrays are initialized to zeros, so an intermediate trace or lnprob will be back-padded with zeros. This issue (and a corresponding issue in truncate_arrays) was caused by the code for finding the last iteration checking that all parameters were non-zero, when a more appropriate heuristic for finding the last iteration is to check that any parameters are non-zero. Note that truncate_arrays would fail silently, removing all the iterations from the trace (and probability, if passed). This is fixed so if some parameters are zero, optimal_parameters and truncate_arrays still work. Doctests were written for each to prevent regressions.

This issue could occur if an initial parameter passed by a user was zero, since the chains in the ensemble for that parameter are all initialized to zero and any StretchMove made by emcee for that parameter will also produce a zero. This is still allowed, however a warning is now logged so users have feedback on this nuance. The logged warning suggests to provide an initial parameter value that's either a good guess or close to zero.

A future solution would be to give users more flexible options for initializing parameters, such as the system for prior specification. Until a better solution exists, a user who desire parameter values centered at zero could work around this by providing a restart_trace (see the input YAML docs) that was made by hand, where the last iteration (just one iteration is sufficient) with all the chains they desire. Each parameter could be initialized to any distribution, for example a normal distribution centered at zero with a standard deviation of 10,000 J.

@bocklund bocklund merged commit 22ec264 into master Mar 29, 2020
@bocklund bocklund deleted the zero-parameters-fix branch April 20, 2021 03:44
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.

None yet

1 participant