In [84]:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed(42)
In [104]:
D = 16 # number of dimensions
condition = 1.e20 # approximate condition number we are going to make
scales = np.sqrt(condition) ** (np.arange(D) / D)
scales
Out[104]:
In [108]:
vectors = scales[:, None] * np.random.normal(size=(D, D+2))
matrix = np.dot(vectors, vectors.T)
matrix.shape
Out[108]:
In [109]:
# this matrix has to be positive definite, but at high dynamic range, sometimes crazy shit happens!
eigvals, eigvecs = np.linalg.eigh(matrix)
"{:e}".format(np.max(eigvals) / np.min(np.abs(eigvals)))
Out[109]:
In [110]:
# hogg matrix inversion trick
foo = np.eye(D)
for iter in range(64): # no stopping criterion
foo = np.dot(np.linalg.inv(np.dot(foo, matrix)), foo.T)
foo = 0.5 * (foo + foo.T)
inverse = foo
np.allclose(np.dot(inverse, matrix), np.eye(D))
Out[110]:
In [ ]:
In [ ]: