fix: superposition converges instead of hanging when tlast < tau with auc.type "AUClast" - #588
Open
billdenney wants to merge 1 commit into
Open
fix: superposition converges instead of hanging when tlast < tau with auc.type "AUClast"#588billdenney wants to merge 1 commit into
billdenney wants to merge 1 commit into
Conversation
… auc.type AUClast With auc.type="AUClast" (or "AUCall"), concentrations after tlast extrapolate as exactly zero, so when tlast < tau the superposed profile keeps structural zeros (for example at time 0 and tau) at steady-state. The zero-concentration guard in the steady-state loop reset the convergence tolerance whenever any concentration was zero, on the assumption that all values eventually become nonzero, so superposition() with the default n.tau=Inf looped forever (issue 580). Two of the twelve Theoph subjects have tlast < 24, so a superposition(conc_obj, tau=24, auc.type="AUClast") call on that dataset hung. Now, once a completed dosing interval draws all of its concentrations from times after tlast, any remaining zero concentration can never become nonzero, so steady-state is assessed on the nonzero concentrations only, and a warning explains that zero concentrations remain in the steady-state profile. Zeros that can still accumulate from later dosing intervals keep the previous guard behavior, so all previously-converging cases are unchanged (verified byte-identical before and after the fix for AUCinf steady-state on all Theoph subjects, finite-n.tau AUClast, and the documented multi-dose cases). A generous 10000-interval backstop now raises an informative error instead of looping forever if steady-state cannot be reached. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #580.
The steady-state loop's zeros guard reset the convergence tolerance every iteration, so structural zeros from
auc.type = "AUClast"/"AUCall"tail handling (when a subject's tlast < tau) maden.tau = Infloop forever. The tolerance logic now distinguishes zeros that can still accumulate (previous behavior kept) from zeros originating after tlast, which can never become nonzero — those converge on the nonzero concentrations with a warning naming the persisting zeros, tlast, and auc.type. A generous 10,000-interval cap errors informatively as a backstop.Verification: nine reference results (AUCinf steady state, finite n.tau, dose-scaled, multi-subject) are byte-identical before/after, verified by stash-toggling the source; the formerly-hanging Theoph case now returns in ~0.05 s with the expected warning; the cap error path is exercised in tests. Full superposition + TSS test files pass.
🤖 Generated with Claude Code