You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
incomplete_beta: second z-derivative is nan at z = 1 for b = 1 (and at z = 0 for a = 1) #73
The second z-derivative of incomplete_beta is nan at an endpoint where the base of the z-rule's power is 0 and its exponent is exactly 0: at z = 1 for b = 1, and at z = 0 for a = 1. The true values are finite. The value and the first derivative are fine.
The same happens with b traced. Reproduced on main (e982e80) and on #65, with jax 0.10.2.
Cause
The custom JVP gives d/dz B = z**(a-1) * (1-z)**(b-1). At b = 1 the second factor is (1-z)**0.0, and JAX differentiates a float-exponent pow as y * x**(y-1), which is 0 * inf = nan at x = 0:
Upstream treats this as intended and won't change it: a float-exponent ** is the real function x^y, which is not differentiable at (0, 0) (jax-ml/jax#14397, and jax-ml/jax#12033 for why the old y == 0 special case was dropped). So the fix belongs here. An integer exponent isn't an option, since b may be traced.
Possible fix
Guard each factor of the z-rule when its exponent is exactly 0, with a double where so the masked pow cannot put a nan into a cotangent:
The same applies to z**(a-1) at a == 1. With b traced, this has to fit around the existing log1p form, which serves the b-derivative (GH-68). Regression tests: the second and third z-derivatives at (a, 1, 1) and (1, b, 0), with b both concrete and traced. On #63, which adds a closed form for a static a == 1, a == 1 at z = 0 should be checked as well.
Activity
🐛 fix(beta): finite z-derivatives at an integer-exponent endpoint
🐛 fix(incomplete_beta): finite z-derivatives at z = 1 on the a == 1 path
🐛 fix(incomplete_beta): z-derivative where its two factors leave the …