Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously,
fit_c3_aci
performed a check to ensure that the initial guess returned byinitial_guess_fun
lies within the lower and upper bounds supplied by the user (lower
andupper
, respectively):However, the
default_optimizer
uses thedfoptim::nmkb
function, which requires that the initial guess lies within (but not on) the bounds. If the initial guess lies on the bounds, no error is produced, but the optimizer's behavior becomes undefined and it may begin making guesses ofNA
for some parameter values.This can lead to some weird behavior. E.g. if there is a strange looking A-Ci curve,
initial_guess_c3_aci
may produce a negative estimate forRd
, which then gets reset byfit_c3_aci
to the default lower bound of 0, which then causes an issue with the optimizer. Ultimately, an error will occur when a value ofRd = NA
is passed tocalculate_c3_assimilation
. This whole process is very difficult to debug because the (uninformative) error message does not indicate that the real issue is related to the initial guess being on the bounds.This PR addresses this problem by modifying
fit_c3_aci
. Now, theinitial_guess
is checked (and possibly modified) to ensure that it lies within (but not on) the user-supplied bounds:This is an important bug fix, so it justifies a new version of the package.