3

I need to calculate the determinant of a large 1554,1554 matrix of values with single precision in python. In doing so I encounter a runtime warning:

import numpy as np

from numpy import linalg as LA

a = np.random.random((1554, 1554))

b = np.random.random((1554, 1554))

c = np.dot(a,b)

det = LA.det(c)

RuntimeWarning: overflow encountered in det r = _umath_linalg.det(a, signature=signature)

Any ideas on how I can work around this problem? Many thanks!

Edit: this question is unique in that it specifically refers to computing the determinant of large matrix in double precision, though a possible answer is included here: Can I get the matrix determinant using Numpy?

Community
  • 1
  • 1
user 123342
  • 463
  • 1
  • 9
  • 21

1 Answers1

2

You can use this relation: https://wikimedia.org/api/rest_v1/media/math/render/svg/f6404a766d86e9d78a5c4f82e05de37469a5f8e9

from https://en.wikipedia.org/wiki/Determinant#Properties_of_the_determinant

So divide your matrix by the mean and then compute the determinant to avoid overflow. Later you can multiply with the mean to the power of n (length of one axis)

edit: I'm not sure if the mean is the ideal choice though. This is more a math question

dnalow
  • 974
  • 4
  • 14
  • OP used np.random.random() to generate his matrices, meaning the mean will be about 0.5. Won't this make the computation *more* complicated? – Max May 24 '19 at 02:50