我正在尝试在theano中实现cox回归。
我使用逻辑回归教程(http://deeplearning.net/tutorial/logreg.html)作为框架,并用cox回归LL函数(https://en.wikipedia.org/wiki/Proportional_hazards_model#The_partial_likelihood)替换逻辑对数似然(LL)函数。
这是我到目前为止所知道的:
class CoxRegression(object):
def __init__(self, x, n_in):
self.W = theano.shared(value=numpy.zeros(n_in,dtype=theano.config.floatX), name='W',borrow=True)
self.b = theano.shared(numpy.cast['float64'](0), borrow=True)
self.theta = T.dot(x, self.W) + self.b
self.exp_theta = T.exp(self.theta)
self.params = [self.W, self.b]
self.x = x
def negative_log_likelihood(self, ytime, ystatus):
LL_i = T.switch(T.eq(ystatus[i],1), self.theta - T.log(T.sum(self.exp_theta * T.gt(ytime, ytime[i]))),0)基本上,我需要对LL_i (其中i是0到ytime.shape - 1)求和。但我不确定该怎么做。我应该使用扫描功能吗?
发布于 2015-09-02 09:20:57
我想通了。诀窍不是使用扫描函数,而是将双重求和转换为纯矩阵运算。
https://stackoverflow.com/questions/32341493
复制相似问题