Simple Example of an Improper Posterior Without Warnings from Stan

If the constrained-space density is continuous and finite at 1 then rounding makes little difference; the sampler behaves approximately correctly. If the density goes to zero or infinity at the boundary any rounded sample is rejected anyway.

Don’t worry, it’s just me.

I’d like someone to explain it to me! I’m pretty sure the infinite looping I saw is literally impossible. I didn’t find any loops in the code at the point where I think it’s happening.

3 Likes

Honestly I think we should return the nominal output (without that 1e-15 correction). If 1 is the closest floating point approximation to the logistic output then that’s the best number to report so long as constraints are inclusive. It’s up to the density to handle that boundary value gracefully.

It’s in https://github.com/stan-dev/math/blob/develop/stan/math/prim/scal/fun/lb_constrain.hpp which gets called by the code autogenerated by the parser.

The behavior here is even trickier as it a component of the gradient at the boundary that is causing the problem. Gradient behavior isn’t checked in most of the densities. Then again it’s tricky because bad behavior in the density can sometimes be ameliorated by opposing behavior in the constraint Jacobian, but there’s no way to access both pieces of info at the same time.

The 1e-15 thing definitely has to go.

If we round to 1, then the output better be 1 or we’ll fail. The question is whether we should fail earlier.

Right—we don’t constrain the domain to values where derivatives are well behaved.