예제 #1
0
파일: test_gp_D.py 프로젝트: jeffhsu3/limix
    F = 1.*(SP.rand(N,2)<0.2); A = SP.eye(P)

    # add second fixed effect
    F2 = 1.*(SP.rand(N,3)<0.2); A2 = SP.ones((1,P))
    
    mu.addFixedEffect(F=F,A=A)
    mu.addFixedEffect(F=F2,A=A2)

    if mtSet_present:
        mu1 = MEAN.mean(Y)
        mu1.addFixedEffect(F=F,A=A)
        mu1.addFixedEffect(F=F2,A=A2)
    

    # define covariance matrices
    Cg = freeform(P)
    Cn = freeform(P)
    Cg1 = freeform(P)
    Cn1 = freeform(P)
    
    ipdb.set_trace()

    if 1:
        # compare with mtSet implementation
        params = {}
        params['Cg']   = SP.randn(int(0.5*P*(P+1)))
        params['Cn']   = SP.randn(int(0.5*P*(P+1)))


        print "check gradient with gp2kronSum"
        gp = gp2kronSum(mu,Cg,Cn,XX)
    # import data
    fname = 'data/arab107_preprocessed.hdf5'
    f = h5py.File(fname,'r')
    X = f['genotype'][:]
    X-= X.mean(0); X/=X.std(0)
    G = X[:,0:200]

    Y = genPheno(G=G,X=X,var_g=0.10,var_x=0.40,P=P)
    XX = SP.dot(X,X.T)
    XX/= XX.diagonal().mean()
    XX+= 1e-4*SP.eye(XX.shape[0])
    GG = SP.dot(G,G.T)
    GG/= GG.diagonal().mean()
    GG+= 1e-4*SP.eye(GG.shape[0])

    C1 = freeform(P)
    C2 = freeform(P)
    Cn = freeform(P)
    gp = gp3kronSumApprox(Y=Y,C1=C1,C2=C2,Cn=Cn,R1=GG,R2=XX,tol=1e-16) 

    if 0:
        Kinit = SP.cov(Y.T)/3 
        C1.setCovariance(Kinit)
        C2.setCovariance(Kinit)
        Cn.setCovariance(Kinit)
    else:
        C1.setRandomParams()
        C2.setRandomParams()
        Cn.setRandomParams()
    params = gp.getParams()
    gp.setParams(params)
예제 #3
0
    # define mean term
    mu = mean(Y)

    # add any fixed effect including bias term
    F = 1. * (SP.rand(N, 3) < 0.2)
    A = SP.eye(P)
    F[:, 0] = 1.0
    mu.addFixedEffect(F=F, A=A)

    # add common fixed effect
    F2 = 1. * (SP.rand(N, 4) < 0.2)
    A2 = SP.ones((1, P))
    mu.addFixedEffect(F=F2, A=A2)

    # define covariance matrices
    Cg = freeform(P)
    Cn = freeform(P)
    Cg1 = freeform(P)
    Cn1 = freeform(P)

    # compare with mtSet implementation
    params = {}
    params['Cg'] = SP.randn(int(0.5 * P * (P + 1)))
    params['Cn'] = SP.randn(int(0.5 * P * (P + 1)))

    print "creating gp2kronSum object"
    XX = SP.dot(X, X.T)
    XX /= XX.diagonal().mean()
    gp = gp2kronSum(mu, Cg, Cn, XX)
    gp.setParams(params)
예제 #4
0
    fname = 'data/arab107_preprocessed.hdf5'
    f = h5py.File(fname, 'r')
    X = f['genotype'][:]
    X -= X.mean(0)
    X /= X.std(0)
    G = X[:, 0:200]

    Y = genPheno(G=G, X=X, var_g=0.10, var_x=0.40, P=P)
    XX = SP.dot(X, X.T)
    XX /= XX.diagonal().mean()
    XX += 1e-4 * SP.eye(XX.shape[0])
    GG = SP.dot(G, G.T)
    GG /= GG.diagonal().mean()
    GG += 1e-4 * SP.eye(GG.shape[0])

    Cr = freeform(P)
    Cg = freeform(P)
    Cn = freeform(P)
    gp = gp3kronSumApprox(Y=Y, Cr=Cr, Cg=Cg, Cn=Cn, XX=XX, GG=GG)
    n_rips = 10
    for rip in range(n_rips):

        Cr.setRandomParams()
        Cg.setRandomParams()
        Cn.setRandomParams()
        params = gp.getParams()
        gp.setParams(params)

        conv, info = OPT.opt_hyper(gp, params, factr=1e3)
        print conv
예제 #5
0
    # import data
    fname = 'data/arab107_preprocessed.hdf5'
    f = h5py.File(fname,'r')
    X = f['genotype'][:]
    X-= X.mean(0); X/=X.std(0)
    G = X[:,0:200]

    Y = genPheno(G=G,X=X,var_g=0.10,var_x=0.40,P=P)
    XX = SP.dot(X,X.T)
    XX/= XX.diagonal().mean()
    XX+= 1e-4*SP.eye(XX.shape[0])
    GG = SP.dot(G,G.T)
    GG/= GG.diagonal().mean()
    GG+= 1e-4*SP.eye(GG.shape[0])

    Cr = freeform(P)
    Cg = freeform(P)
    Cn = freeform(P)
    gp = gp3kronSumApprox(Y=Y,Cr=Cr,Cg=Cg,Cn=Cn,XX=XX,GG=GG) 
    n_rips = 10
    for rip in range(n_rips):

        Cr.setRandomParams()
        Cg.setRandomParams()
        Cn.setRandomParams()
        params = gp.getParams()
        gp.setParams(params)

        conv,info = OPT.opt_hyper(gp,params,factr=1e3)
        print conv
예제 #6
0
    # import data
    fname = 'data/arab107_preprocessed.hdf5'
    f = h5py.File(fname,'r')
    X = f['genotype'][:]
    X-= X.mean(0); X/=X.std(0)
    G = X[:,0:200]

    Y = genPheno(G=G,X=X,var_g=0.10,var_x=0.40,P=P)
    XX = SP.dot(X,X.T)
    XX/= XX.diagonal().mean()
    XX+= 1e-4*SP.eye(XX.shape[0])
    GG = SP.dot(G,G.T)
    GG/= GG.diagonal().mean()
    GG+= 1e-4*SP.eye(GG.shape[0])

    C1 = freeform(P)
    C2 = freeform(P)
    Cn = freeform(P)
    gp = gp3kronSumApprox(Y=Y,C1=C1,C2=C2,Cn=Cn,R1=GG,R2=XX,tol=1e-16) 

    if 0:
        Kinit = SP.cov(Y.T)/3 
        C1.setCovariance(Kinit)
        C2.setCovariance(Kinit)
        Cn.setCovariance(Kinit)
    else:
        C1.setRandomParams()
        C2.setRandomParams()
        Cn.setRandomParams()
    params = gp.getParams()
    gp.setParams(params)