Exemplo n.º 1
0
 def fit(self, XTrain=None, yTrain=None, KTrain=None, delta=None, folds=0):
     self.nTrain = yTrain.shape[0]
     self.yTrain = yTrain
     if KTrain is not None:
         self.kernel = KTrain
     self.S, self.U = LA.eigh(self.kernel+SP.eye(self.nTrain)*1e-8)
     self.Uy = SP.dot(self.U.T, yTrain)
     self.Uone = SP.dot(self.U.T, SP.ones_like(yTrain))
     if delta is None:
         # Initialize cross-learning of delta
         if folds > 0:
             self.ldelta = self.crossvalidate_delta(folds)
         else:
             self.ldelta = lmm_fast.optdelta(self.Uy[:, 0], self.Uone, self.S,
                                             numintervals=1000)
         self.delta = SP.exp(self.ldelta)
     else:
         self.delta = delta
         self.ldelta = SP.log(delta)
     self.cov = LA.inv((self.kernel + SP.eye(self.nTrain)*self.delta))
Exemplo n.º 2
0
UY=SP.dot(U.T,Y);
UX=SP.dot(U.T,X);


ldelta = +8

import time

#need to create copies to ensure it is all properly lined up in memory
#TODO: I am sure this issues is common to cython stuff and other people have similar problems
_UX = SP.array(UX[:,0:2])
_UY = SP.array(UY[:,0])

if 1:
    print "testing delta opt"
    delta0 = lmm_fast.optdelta(_UY,_UX,S)
    delta1 = lmm.optdelta(_UY,_UX,S)
    print "%.2f versus %.2f" % (delta0,delta1)

if 1:
    print "testing eval on all SNPs"
    for i in xrange(UX.shape[1]):
        _UX = UX[:,i:i+1]
        _UY = SP.array(UY[:,0])
        lml0=lmm_fast.nLLeval(ldelta,_UY,_UX,S)
        lml1=lmm.nLLeval(ldelta,_UY,SP.array(_UX),S)
        lml2=lmm.nLLeval(ldelta,_UY,_UX,S)
        assert SP.absolute(lml1-lml2)<1E-10, 'outch'
        print "lml: %.2f delta lml (rel) : %.2f " % (lml1,(lml1-lml0)/SP.absolute(lml1))
       
Exemplo n.º 3
0
 def update_delta(self, mean):
     Umean = SP.dot(self.U.T, mean).reshape(-1, 1)
     self.ldelta = lmm_fast.optdelta(self.Uy[:, 0], Umean, self.S, ldeltamin=self.ldelta-1., ldeltamax=self.ldelta+1.)
     self.delta = SP.exp(self.ldelta)
     return self.delta
Exemplo n.º 4
0
S, U = LA.eigh(K)
UY = SP.dot(U.T, Y)
UX = SP.dot(U.T, X)

ldelta = +8

import time

#need to create copies to ensure it is all properly lined up in memory
#TODO: I am sure this issues is common to cython stuff and other people have similar problems
_UX = SP.array(UX[:, 0:2])
_UY = SP.array(UY[:, 0])

if 1:
    print "testing delta opt"
    delta0 = lmm_fast.optdelta(_UY, _UX, S)
    delta1 = lmm.optdelta(_UY, _UX, S)
    print "%.2f versus %.2f" % (delta0, delta1)

if 1:
    print "testing eval on all SNPs"
    for i in xrange(UX.shape[1]):
        _UX = UX[:, i:i + 1]
        _UY = SP.array(UY[:, 0])
        lml0 = lmm_fast.nLLeval(ldelta, _UY, _UX, S)
        lml1 = lmm.nLLeval(ldelta, _UY, SP.array(_UX), S)
        lml2 = lmm.nLLeval(ldelta, _UY, _UX, S)
        assert SP.absolute(lml1 - lml2) < 1E-10, 'outch'
        print "lml: %.2f delta lml (rel) : %.2f " % (lml1, (lml1 - lml0) /
                                                     SP.absolute(lml1))