Repository navigation
Draw NaN rather than hang when poisson() or negative_binomial() is sampled with an invalid parameter (#617) - #864
Merged
Merged
Conversation
…mpled with an invalid parameter (#617) - R/probability_distributions.R: tf_sample_where_valid() swaps invalid parameters for a placeholder before sampling and gives NaN for those draws; poisson() and negative_binomial() sample through it - tests/testthat/helpers.R: in_fresh_greta() takes a timeout, so a test of a hang fails rather than hangs - tests/testthat/test_calculate.R: calculate() draws NaN for an invalid poisson() and negative_binomial(), in a session killed after 120 seconds - NEWS.md: bullet for #617 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aN rather than hanging and an infinite size still draws Inf (#617) - R/probability_distributions.R: negative_binomial() checks TFP's probs = 1 - prob is in [0, 1) and masks an infinite size only with probs of 0, using TFP's constructor directly - tests/testthat/test_calculate.R: the #617 test adds negative_binomial(0, 0), an infinite size, and valid elements a placeholder draw can't match, with a 600 s timeout that allows for a slow start Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…here_valid() - tests/testthat/test_calculate.R: the comment says why the draws run in a killable session and why the timeout is long, without repeating the sampler's explanation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
njtierney
commented
Oct 23, 2026
njtierney
commented
Oct 23, 2026
njtierney
commented
Oct 23, 2026
njtierney
commented
Oct 23, 2026
…l()'s mask - R/probability_distributions.R: what tf_sample_where_valid() does and why in three lines; the negative binomial's invalid cases in two Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n lists on its own line - R/probability_distributions.R: list(log_prob, sample) split over lines in both tf_distrib() methods Co-Authored-By: Claude Opus 5.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.
Closes #617.
poisson()samples through it, and so doesnegative_binomial(), as a Poisson with a gamma-distributed rate. Socalculate()andsimulate()hung on a NaN or negativelambda(greta passeslog(lambda)), and on a negative binomial whose rate is NaN.What changes
tf_sample_where_valid()swaps each invalid parameter element for a safe placeholder before sampling, and givesNaNfor those draws. When every element is valid, the draws are the same as on main, seed for seed.poisson()masks a NaN log rate, which covers a NaN or negativelambda.negative_binomial()masks a NaN or negativesize, a TFPprobs = 1 - proboutside [0, 1), and an infinitesizewithprob = 1. Soprob = 0, or aprobso small that1 - probrounds to 1, drawsNaN. An infinitesizewithprobbelow 1 still drawsInf, as on main.list(log_prob, sample), like greta's other custom distributions.log_probis TFP's, unchanged.Not covered
binomial()with a NaNsizegives 0; that's a separate issue, also drafted.Tests
tests/testthat/test_calculate.R:calculate()drawsNaNfor invalidpoisson()andnegative_binomial()elements, includingnegative_binomial(0, 0)and an infinite size withprob = 1, and ordinary draws for the valid elements beside them. On main the test hangs, and its session is killed at 600 s.tests/testthat/helpers.R:in_fresh_greta()takes atimeout, so a test of a hang fails rather than hangs. The timeout also covers starting R and loading greta, hence 600 s.test_future.Rerrors: future workers load the installed greta, which predates%*%multiplies a data matrix once, not once per chain (#858) #859'sunbatched_tf_name().🤖 Generated with Claude Code