theano中的index好怪异。。比如最大似然估计的损失计算部分。

来源:互联网 发布:知柏地黄丸主治什么 编辑:程序博客网 时间:2024/04/20 08:07
  1. # NLL is a symbolic variable ; to get the actual value of NLL, this symbolic  
  2. # expression has to be compiled into a Theano function (see the Theano  
  3. # tutorial for more details)  
  4. NLL = -T.sum(T.log(p_y_given_x)[T.arange(y.shape[0]), y])  
  5. # note on syntax: T.arange(y.shape[0]) is a vector of integers [0,1,2,...,len(y)].  
  6. # Indexing a matrix M by the two vectors [0,1,...,K], [a,b,...,k] returns the  
  7. # elements M[0,a], M[1,b], ..., M[K,k] as a vector.  Here, we use this  
  8. # syntax to retrieve the log-probability of the correct labels, y.  
0 0
原创粉丝点击