我目前正在通过逻辑回归theano tutorial,非常像这篇文章中讨论: what-does-negative-log-likelihood-of-logistic-regression-in-theano-look-like。然而,原始tutorial使用共享变量 W和B,以及一个称为输入矩阵。输入是一个n x n_in
矩阵,W是n_in x n_out
,b是一个n_out x 1
列向量。与逻辑回归广播共享变量与theano
self.W = theano.shared(
value=numpy.zeros(
(n_in, n_out),
dtype=theano.config.floatX
),
name='W',
borrow=True
)
self.b = theano.shared(
value=numpy.zeros(
(n_out,),
dtype=theano.config.floatX
),
name='b',
borrow=True
)
self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
现在,据我了解共享变量的文档,共享变量的广播模式默认为false。那么为什么这行代码不会因为尺寸不匹配而导致错误?
self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
毕竟,我们还添加了矩阵T.dot(input, self.W)
为矢量b
。毕竟默认共享变量是否广播?即使有广播,维度也不会加起来。 T.dot(input, self.W)
是n x n_out
矩阵和b a n_out x 1
向量。
我缺少什么?
感谢您的回答。但是,我仍然缺少一个细节:'self.b'是一个共享变量,它被添加到'T.dot(input,self.W)'中。因此,似乎我们需要广播来完成这项工作,但是'self.b'没有被定义为可广播。为什么它工作呢?我明白为什么它可以与符号变量或纯粹的numpy一起工作,但不是为什么它可以与共享变量一起工作。 – aifos324
由于'T.dot(input,self.W)'将返回符号矩阵/向量。 [theano.tensor.dot(X,Y)](http://deeplearning.net/software/theano/library/tensor/basic.html#theano.tensor.dot) – uyaseen
好的,在你的帮助下,我发现我的错误。当我在theano的[docu](http://deeplearning.net/software/theano/library/tensor/basic.html)中读到这个时,它会产生点击:当一个元素操作的两个参数(如加法或减法)不同数量的维度,通过填充True_可将可播放模式展开到左侧。因此,假设在运行时,这也适用于共享变量,默认情况下它具有可传播模式'[false,false,...]',现在都是有道理的。我的错误是假设填充不会发生在共享变量上。谢谢! – aifos324