In [1]:
# set some ipython notebook properties
%matplotlib inline
# set degree of verbosity (adapt to INFO for more verbose output)
import logging
logging.basicConfig(level=logging.WARNING)
# set figure sizes
import pylab
pylab.rcParams['figure.figsize'] = (10.0, 8.0)
# set display width for pandas data frames
import pandas as pd
pd.set_option('display.width', 1000)
In [27]:
import numpy as np
K = np.array([[1., 2, 3],[2,1,5],[3,5,1]])
S,U = np.linalg.eigh(K)
print S
print U
In [14]:
np.eye(3) * S
Out[14]:
In [17]:
U
Out[17]:
In [16]:
np.dot(np.dot(U,np.eye(3) * S),U.T)
Out[16]:
In [21]:
print np.linalg.inv(K)
print np.dot(np.dot(U,np.eye(3) / S),U.T)
In [26]:
V = .2 * K + .8 * np.eye(3)
print V
print np.linalg.inv(V)
print .2 * np.dot(np.dot(U,np.eye(3) / S),U.T) + .8 * np.eye(3)
In [33]:
print np.linalg.inv(13 * K)
print 1./13 * np.linalg.inv(K)
factor = np.diag(K).sum() print factor
In [38]:
Kn = K/factor
print Kn
In [39]:
np.std(Kn)
Out[39]:
In [7]:
s,u = np.linalg.eigh(np.eye(3))
print s
print u
In [8]:
np.dot(np.dot(u,np.eye(3) * s),u.T)
Out[8]:
In [15]:
u2 = 1
print np.dot(u2,np.eye(3)*s)
In [27]:
#Why can we assume that h2 and e2 add to one?
#Because y is unit standardized then its s.d. is 1
# and K's diagional is N
covar = np.array([[float(num)] for num in xrange(490)])
np.random.seed(0)
pheno = covar * 2.0 + 100 + np.random.normal(size=len(covar))*10
print np.mean(pheno), np.std(pheno)
In [32]:
import pylab
pylab.plot(covar, pheno,".")
pylab.show()
In [ ]: