basnijholt / pfapack

Efficient numerical computation of the Pfaffian for dense and banded skew-symmetric matrices
https://arxiv.org/abs/1102.3440
Other
14 stars 6 forks source link

Python implementation unstable with small valued matrices #6

Open awstasiuk opened 2 years ago

awstasiuk commented 2 years ago

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.