コード例 #1
0
ファイル: test_gp_more.py プロジェクト: xypan1232/limix
    def setUp(self):
        np.random.seed(1)

        # define phenotype
        N = 10 
        P = 3
        Y = sp.randn(N,P)

        # pheno with missing data
        Ym = Y.copy()
        Im = sp.rand(N, P)<0.2
        Ym[Im] = sp.nan

        # define fixed effects
        F = []; A = []
        F.append(1.*(sp.rand(N,2)<0.5))
        A.append(sp.eye(P))
        mean = MeanKronSum(Y, F=F, A=A)
        mean_m = MeanKronSum(Ym, F=F, A=A)

        # define row caoriance
        f = 10
        X = 1.*(sp.rand(N, f)<0.2)
        R = covar_rescale(sp.dot(X,X.T))
        R+= 1e-4 * sp.eye(N)

        # define col covariances
        Cg = FreeFormCov(P)
        Cn = FreeFormCov(P)
        Cg.setRandomParams()
        Cn.setRandomParams()

        # define covariance matrices
        covar1 = KronCov(Cg, R)
        covar2 = KronCov(Cn, sp.eye(N))
        covar  = SumCov(covar1,covar2)

        # define covariance matrice with missing data
        Iok = (~Im).reshape(N * P, order='F')
        covar1_m = KronCov(copy.copy(Cg), R, Iok=Iok)
        covar2_m = KronCov(copy.copy(Cn), sp.eye(N), Iok=Iok)
        covar_m  = SumCov(covar1_m,covar2_m)

        # define gp
        self._gp = GP(covar=covar, mean=mean)
        self._gpm = GP(covar=covar_m, mean=mean_m)
        self._gp2ks = GP2KronSum(Y=Y, F=F, A=A, Cg=Cg, Cn=Cn, R=R) 
コード例 #2
0
from limix.core.gp import GP3KronSumLR
from limix.core.gp import GP
from limix.utils.preprocess import covar_rescale
import time
import copy
import pdb

if __name__ == '__main__':

    # define region and bg terms
    N = 500
    f = 10
    P = 3
    G = 1. * (sp.rand(N, f) < 0.2)
    X = 1. * (sp.rand(N, f) < 0.2)
    R = covar_rescale(sp.dot(X, X.T))
    R += 1e-4 * sp.eye(N)

    # define col covariances
    Cg = FreeFormCov(P)
    Cn = FreeFormCov(P)
    Cg.setRandomParams()
    Cn.setRandomParams()

    # define pheno
    Y = sp.randn(N, P)

    # define GP and optimize
    gp = GP3KronSumLR(Y=Y, Cg=Cg, Cn=Cn, R=R, G=G, rank=1)
    gp.optimize()
コード例 #3
0
    F.append(1.*(sp.rand(N,2)<0.5))
    #F.append(1.*(sp.rand(N,1)<0.5))
    A.append(sp.eye(P))
    #A.append(sp.ones((1,P)))

    # define row caoriance
    f = 10
    X = 1.*(sp.rand(N, f)<0.2)
    R = covar_rescale(sp.dot(X,X.T))
    R+= 1e-4 * sp.eye(N)
    S_R, U_R = la.eigh(R)

    # define col covariances
    Cg = FreeFormCov(P)
    Cn = FreeFormCov(P)
    Cg.setRandomParams()
    Cn.setRandomParams()

    # define gp
    gp = GP2KronSum(Y=Y, F=F, A=A, Cg=Cg, Cn=Cn, S_R=S_R, U_R=U_R)
    pdb.set_trace()
    print gp.covar.Sr()
    print gp.LML()
    print gp.covar.Sr()
    print Cg.setRandomParams()

    t0 = time.time()
    print 'GP2KronSum.LML():', gp.LML()
    print 'Time elapsed:', time.time() - t0

    # compare with normal gp
コード例 #4
0
    G = 1.*(sp.rand(N, f)<0.2)
    X = 1.*(sp.rand(N, f)<0.2)
    R = covar_rescale(sp.dot(X,X.T))
    R+= 1e-4 * sp.eye(N)
    S, U = la.eigh(R)
    Y = sp.randn(N, P)
    return Y, S, U, G 

if __name__=='__main__':

    P = 4

    # define col covariances
    Cg = FreeFormCov(P, jitter=0)
    Cn = FreeFormCov(P)
    Cg.setRandomParams()
    Cn.setRandomParams()

    out_file = './times.hdf5'

    if not os.path.exists(out_file) or 'recalc' in sys.argv:
        Ns = sp.array([100,150,200,300,500,800,1200,1600,2000,3000,4000,5000])
        n_rips = 5 
        t = sp.zeros((Ns.shape[0], n_rips))
        t0 = sp.zeros((Ns.shape[0], n_rips))
        r = sp.zeros((Ns.shape[0], n_rips))
        for ni, n in enumerate(Ns): 
            for ri in range(n_rips):
                print '.. %d individuals - rip %d' % (n, ri)
                print '   .. generating data'
                Y, S, U, G = gen_data(N=n, P=P)
コード例 #5
0
if __name__=='__main__':

    P = 4

    pdb.set_trace()

    # define col covariances
    C = FreeFormCov(P, jitter=0)
    C0 = covariance.freeform(P)

    t1 = 0
    t0 = 0

    for ti in range(1000):
        C.setRandomParams()
        C0.setParams(C.getParams())

        for i in range(int(0.5*P*(P+1))):
            _t0 = time.time()
            C0.Kgrad_param(i)
            _t1 = time.time()
            C.K_grad_i(i)
            _t2 = time.time()
            t0 += _t1-_t0
            t1 += _t2-_t1

    print 'old:', t0
    print 'new:', t1