[NumPy-Tickets] [NumPy] #1402: Provide a function to compute the log-determinant

NumPy Trac numpy-tickets@scipy....
Fri Feb 19 01:27:16 CST 2010

#1402: Provide a function to compute the log-determinant
 Reporter:  njs          |       Owner:  somebody
     Type:  enhancement  |      Status:  new     
 Priority:  normal       |   Milestone:          
Component:  Other        |     Version:          
 Keywords:               |  
 For large matrices, computing the determinant directly may cause overflow
 or underflow. But in many cases (e.g., doing maximum-likelihood
 calculations with multivariate normals), all one really wants to calculate
 is the log-determinant, which is not subject to these numerical issues.

 Attached patch adds a function 'sign_log_det' to np.linalg. The idea is
 that it returns the sign of the determinant (as a number with absolute
 value 1) and the log of the absolute value. This avoids introducing
 complex numbers when calculating the determinant of a real matrix (and
 anyway the absolute value is often what's of interest anyway).

 It also changes the ordinary 'det' function to be a simple wrapper around
 'sign_log_det'; as a side-effect, it becomes somewhat more robust against
 ill-conditioned matrices. For instance, without this patch,
 np.linalg.det([[1e300, 0], [0, 1e-300]]) returns 0; with this patch, it
 (correctly) returns 1.

 Tests and docs included; patch is against r8128.

 I'd like to get this API settled, because I'm adding similar functions for
 sparse matrices to my scikits.sparse library, and I'd like to be
 consistent with whatever numpy does.

Ticket URL: <http://projects.scipy.org/numpy/ticket/1402>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list