Python 没有索引详细信息
我正在学习Theano教程(特别是),并试图理解这段“不言而喻”的代码: 我的问题是:Python 没有索引详细信息,python,theano,Python,Theano,我正在学习Theano教程(特别是),并试图理解这段“不言而喻”的代码: 我的问题是: 函数调用后的[T.arange(y.shape[0]),y]是什么 它如何返回[LP[0,y[0]],LP[1,y[1]],LP[2,y[2]],…,LP[n-1,y[n-1]] T.mean怎么知道如何计算这样的平均值(不管是什么) 你能概括一下我不懂的概念吗 找到答案(NLL代表负对数可能性): NLL是一个符号变量;要获取NLL的实际值,请使用以下符号 表达式必须编译为Theano函数(请参见Thean
NLL=-T.sum(T.log(p\y\u给定x)[T.arange(y.shape[0]),y])
语法注释:T.arange(y.shape[0])
是整数向量[0,1,2,…,len(y)]
。
通过两个向量对矩阵M进行索引[0,1,…,K],[a,b,…,K]
返回
元素M[0,a],M[1,b],…,M[K,K]
作为向量。这里,我们用这个
检索正确标签的日志概率y的语法
# y.shape[0] is (symbolically) the number of rows in y, i.e.,
# number of examples (call it n) in the minibatch
# T.arange(y.shape[0]) is a symbolic vector which will contain
# [0,1,2,... n-1] T.log(self.p_y_given_x) is a matrix of
# Log-Probabilities (call it LP) with one row per example and
# one column per class LP[T.arange(y.shape[0]),y] is a vector
# v containing [LP[0,y[0]], LP[1,y[1]], LP[2,y[2]], ...,
# LP[n-1,y[n-1]]] and T.mean(LP[T.arange(y.shape[0]),y]) is
# the mean (across minibatch examples) of the elements in v,
# i.e., the mean log-likelihood across the minibatch.
return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])