nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
160 stars 24 forks source link

incorrect restoration of marginalizedNodes values for nonconjugate sampling in sampler_CRP when number of clusters exceeds truncated number #1513

Closed paciorek closed 2 weeks ago

paciorek commented 2 weeks ago

In sampler_CRP, if a user sets the max number of clusters to be less than the number of "observations", then we warn the user that that max number is exceeded and simply avoid setting the cluster membership value to be more than the max number.

However, when this happens it turns out that our logic for restoring values of marginalizedNodes when they are sampled by the non-conjugate sampler is faulty but no cluster is opened with those cluster parameter values. When we are at the max, no sampling of the marginalizedNodes is done, so the call to sample(i,0) resets values of an arbitrary index to arbitrary values (the last stored index and values). This will presumably cause incorrect sampling. Fortunately, this is in a case where we have already warned the user they should increase the max number of clusters, so the MCMC output is already invalid (albeit as an incorrectly constrained model rather than incorrect samples per se).

I will fix this shortly.