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

Update fit_c3_aci.R #57

Merged
merged 2 commits into from
Nov 1, 2022
Merged

Update fit_c3_aci.R #57

merged 2 commits into from
Nov 1, 2022

Conversation

eloch216
Copy link
Owner

@eloch216 eloch216 commented Nov 1, 2022

Previously, fit_c3_aci performed a check to ensure that the initial guess returned by initial_guess_fun lies within the lower and upper bounds supplied by the user (lower and upper, respectively):

initial_guess <- pmax(initial_guess, lower)
initial_guess <- pmin(initial_guess, upper)

However, the default_optimizer uses the dfoptim::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 of NA 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 for Rd, which then gets reset by fit_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 of Rd = NA is passed to calculate_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, the initial_guess is checked (and possibly modified) to ensure that it lies within (but not on) the user-supplied bounds:

lower_temp <- lower + 0.01 * (upper - lower)
upper_temp <- upper - 0.01 * (upper - lower)

initial_guess <- pmax(initial_guess, lower_temp)
initial_guess <- pmin(initial_guess, upper_temp)

This is an important bug fix, so it justifies a new version of the package.

@eloch216 eloch216 merged commit ea29fb4 into main Nov 1, 2022
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