The culprit here is there is a check if a value is x == 0.0, which leads to unstable divide by zero behavior. Using np.isclose(x,0) should lead to more stable behavior.
To fix this, I implemented a sanitizing step before passing a matrix into the pfaffian functions wherein you replace any value smaller than some tol (I used 10e-10) with a value precisely 0. This seemed to fix the issue leading to the return of a NaN.
The culprit here is there is a check if a value is
x == 0.0
, which leads to unstable divide by zero behavior. Usingnp.isclose(x,0)
should lead to more stable behavior.To fix this, I implemented a sanitizing step before passing a matrix into the pfaffian functions wherein you replace any value smaller than some tol (I used 10e-10) with a value precisely 0. This seemed to fix the issue leading to the return of a
NaN
.