Ejemplo n.º 1
0
def fit_test():
    print "Testing GLS"
    model = LMMBasicAnimal(ylist = ['length'],plist=['size'])
    dataFile = "data/test.data"
    treeFile = "data/test.newick"
    # loadFromFile(self,dataFile,treeFile,taxa_column='taxa',sep='TAB'):
    model.loadFromFile(dataFile,treeFile,sep='SPACE')
    model.fitGLS()
    # model.fitLMMBasic()
    print "--------------------"
Ejemplo n.º 2
0
def simulate_one_tree():
    #treeFile = 'data/test.newick'
    treeFile = "data/bz.trees.newick"
    tree = PhyloTree(treeFile, schema='newick')
    tree.normalize()
    G = tree.getV()
    Gs = [G]
    #(y,X,beta,Z,b,G,cholL,sigma2_b,R,sigma2_e) = lmmsample(tree)
    beta = [15,2.5]
    (y,X,Z,Ls,u,e) =lmm_sample(beta,Gs=Gs,sigma2=[5,1])
    (n,xx) = np.shape(y)
    # saveModelData('data/bodybraindata.txt','Body',['Brain'],y,X,tree)
    model =  LMMBasicAnimal(ylist = ['Body'],plist=['Brain'])
    #return
    #model = LMMBasicAnimal(ylist = ['length'],plist=['size'])
    R = np.asmatrix(np.eye(n))
    model.loadFromMatrices(y,X,Z,G,R)
    model.fitLMMBasic()
    #model.fitGLSLambda()
    #return 0
    invG = np.linalg.inv(model.G)
    #cholG = np.asmatrix(scipy.linalg.cholesky(G,lower=True))
    print ("*** initializing LmmMcmc object")
    # gibbs = GibbsAnimal(y,X,Z,invG,cholG)
    gibbs = MC2Lmm(y,X,Z,Ginvs=[invG])
    gibbs.set_init_params(init_beta=[10,1.5],init_sigma2_u=0.5,init_sigma2_e=0.5)
    # Time this
    t1 = time.time()
    ret = gibbs.simulate(num_samples=100,burnin=2000,thin=20)
    t2 = time.time()
    print 'time='+str(t2-t1)
    print "**** Finished sampling ****"
    print "NUM SAMPLES = " + str(gibbs.num_samples)
    if (ret != 0):
        print "Horror!"
        if (gibbs.num_samples < 1):
            return -1
        gibbs.plot()
    else:
        print 'Finished successfully'
        gibbs.plot()
    #gibbs.save_to_file('samples2.log',filetype='xls')
    #print samples
    #print np.shape(samples)
    #(num_params,num_samples) = np.shape(samples)

    return 0
Ejemplo n.º 3
0
def fit_mammals():
    model = LMMBasicAnimal(ylist = ['Body'],plist=['Brain'])
    dataFile = "data/bzdata.txt"
    treeFile = "data/bz.trees.newick"
    # loadFromFile(self,dataFile,treeFile,taxa_column='taxa',sep='TAB'):
    model.loadFromFile(dataFile,treeFile,taxa_column='Name',sep='SPACE')
    model.fitGLS()
    # model.fitLMMBasic()
    print "--------------------"
    model.fitGLSLambda()
Ejemplo n.º 4
0
def fit_simulate2():
    treeFile = 'data/test.newick'
    dataFile = "data/test.data"
    #treeFile = "data/bz.trees.newick"
    tree = PhyloTree(treeFile, schema='newick')
    tree.normalize()
    #(y,X,beta,Z,b,G,cholL,sigma2_b,R,sigma2_e) = lmmsample(tree)
    #saveModelData2('data/bodybraindata.txt','Body',['Brain'],y,X,tree)
    #model =  LMMBasicAnimal(ylist = ['Body'],plist=['Brain'])
    #return
    model = LMMBasicAnimal(ylist = ['length'],plist=['size'])
    model.loadFromFile(dataFile,treeFile,sep='SPACE')

    invG = np.linalg.inv(model.G)
    cholG = np.asmatrix(scipy.linalg.cholesky(model.G,lower=True))
    print ("*** initializing LmmMcmc object")
    gibbs = GibbsAnimal(model.y,model.X,model.Z,invG,cholG)
    #gibbs = MC2Lmm(y,X,Z,Ginvs=[invG])
    #gibbs.set_init_params(init_beta=[10,1.5],init_sigma2_u=0.5,init_sigma2_e=0.5)
    # Time this
    t1 = time.time()
    ret = gibbs.simulate(num_samples=100,burnin=2000,thin=20)
    t2 = time.time()
    print 'time='+str(t2-t1)
    print "**** Finished sampling ****"
    print "NUM SAMPLES = " + str(gibbs.num_samples)
    if (ret != 0):
        print "Horror!"
        if (gibbs.num_samples < 1):
            return -1
        gibbs.plot()
    else:
        print 'Finished successfully'
        gibbs.plot()
    #gibbs.save_to_file('samples2.log',filetype='xls')
    #print samples
    #print np.shape(samples)
    #(num_params,num_samples) = np.shape(samples)

    return 0