In [3]:
import numpy as np
import numpy.random as npr
import pylab as pl
%matplotlib inline
In [2]:
a = 1 + 5j
In [3]:
a
Out[3]:
In [4]:
x = 1
In [25]:
a = np.complex(x,x+2)
In [26]:
a
Out[26]:
In [74]:
np.complex(*npr.rand(2))
Out[74]:
In [75]:
rand_complex = lambda n=1 : np.array([np.complex(*npr.randn(2)) for __ in xrange(n)])
In [87]:
n = 100 # samples
p = 5 # dimension
X = np.array([rand_complex(p) for __ in xrange(n)])
In [88]:
X.shape
Out[88]:
In [89]:
a.conjugate()*(a)
Out[89]:
In [90]:
a*a.conjugate()
Out[90]:
In [91]:
X[0]*(X[0].conjugate())/n
Out[91]:
In [92]:
X.T.shape
Out[92]:
In [93]:
x = X.T[0]
In [98]:
(x.dot((x.T).conjugate()))
Out[98]:
In [95]:
# Joel Tropp: Introduction to Matrix Concentration inequalities says on p.6 that
# this is an unbiased estimator for the covariance matrix of X, but I don't understand:
Y = sum([x*x.conjugate() for x in X.T]) / n
In [ ]:
Y = np.zeros((p,p))
for i in range(p):
Y[i] =
In [58]:
Y.shape
Out[58]:
In [59]:
Y
Out[59]:
In [56]:
np.cov(X.T).shape
Out[56]:
In [61]:
np.cov(X.T)
Out[61]:
In [2]:
from scipy import linalg
In [4]:
a = npr.rand(100,100)
b = npr.rand(1000,1000)
In [5]:
tiny = npr.rand(10,10)
In [118]:
%timeit linalg.inv(tiny)
In [119]:
%timeit np.linalg.inv(tiny)
In [115]:
%timeit ans = linalg.inv(a)
In [107]:
%timeit ans = linalg.inv(b)
In [27]:
c = npr.rand(5000,5000)
In [108]:
%timeit ans = linalg.inv(c)
In [113]:
%timeit np.linalg.inv(a)
In [110]:
%timeit ans = np.linalg.inv(b)
In [111]:
%timeit ans = np.linalg.inv(c)
In [6]:
ab = npr.rand(100)
bb = npr.rand(1000)
cb = npr.rand(5000)
In [124]:
%timeit linalg.solve(a,ab)
In [125]:
%timeit linalg.solve(b,bb)
In [126]:
%timeit linalg.solve(c,cb)
In [127]:
%timeit np.linalg.solve(a,ab)
In [128]:
%timeit np.linalg.solve(b,bb)
In [129]:
%timeit np.linalg.solve(c,cb)
In [131]:
tinyb = npr.rand(len(tiny))
In [133]:
%timeit linalg.solve(tiny,tinyb)
In [132]:
%timeit np.linalg.solve(tiny,tinyb)
In [134]:
%timeit linalg.det(c)
In [136]:
%timeit np.linalg.det(c)
In [7]:
%timeit linalg.lstsq(a,ab)
In [8]:
%timeit linalg.lstsq(b,bb)
In [10]:
%timeit linalg.eig(a)
In [11]:
%timeit linalg.eig(b)
In [12]:
%timeit np.linalg.eig(b)
In [33]:
%timeit linalg.eigvals(b)
In [19]:
%timeit linalg.svd(a)
In [20]:
%timeit linalg.svd(b)
In [14]:
from scipy.linalg import interpolative
In [17]:
%timeit interpolative.svd(a,0.1)
In [23]:
%timeit interpolative.svd(a,5)
In [25]:
%timeit interpolative.svd(b,50)
In [28]:
%timeit interpolative.svd(c,50)
In [30]:
%timeit interpolative.estimate_spectral_norm(a)
In [31]:
%timeit interpolative.estimate_spectral_norm(b)
In [32]:
%timeit interpolative.estimate_spectral_norm(c)