ighdez / choicedesign

Experimental designs for discrete choice models
5 stars 3 forks source link

Update criteria.py: handle singular matrix with determinant of a very small number close to 0 #3

Closed stellamulia closed 6 months ago

stellamulia commented 7 months ago

Hi Jose,

I encountered error LinAlgError("Singular matrix") that occurred from criteria.py (line 18: vce = np.linalg.solve(im,np.eye(im.shape[0])).

It seems that in this operation, the matrix is singular, but the determinant is not 0 due to floating-point number issue, as mentioned here. As a result, despite the check if np.linalg.det(im) != 0: on line 17, the next line of code is still executed.

Therefore, I suggest using np.isclose(<determinant>,0).

Note: if relevant, this error occurred in Linux, but not in Windows.