Python theano : how does the R-operation work?

标签 python theano

我正在 theano 上执行以下操作:

>>> import theano
>>> import theano.tensor as T
>>> x = T.dvector('x')
>>> y = T.dvector('y')
>>> f = T.dot(x,y)
>>> Jy= T.Rop(f,x,y)
>>> fun = theano.function([x,y],Jy)
>>> fun([1000,2000,3000],[2,4,8])
array(84.0)

但是,如果我手动计算一个简单的例子,我会得到:

x = [x1,x2,x3]
y = [y1,y2,y3]
f = [x1y1,x2y2,x3y3]
df/dx = |y1, 0, 0|
        |0, y2, 0|
        |0,  0,y3|
(df/dx)*y = [y1^2, y2^2, y3^2]

因此,我期望得到 [4, 16, 64] 的结果,但我得到的是这些结果的总和。 Rop 的计算方式有何不同?

最佳答案

差异是由于对示例代码中 theano.dot 所做操作的误解造成的。

theano.dot(x, y) 等于给定示例输入的标量 34000,因为它计算的是向量内积而不是逐元素积,正如您的手牌示例所表明的那样。

通过改变就能得到你期望的结果

f = T.dot(x,y)

f = x * y

关于Python theano : how does the R-operation work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32781847/

相关文章:

python - SWIG - 映射 C++ 右移和左移运算符

python - Keras Convolution2D 输入 : Error when checking model input: expected convolution2d_input_1 to have shape

python - 如何在 Theano 中进行 "generalized"矩阵运算?

machine-learning - SHOGUN Toolbox 卷积神经网络与 Caffe 和 Theano 相比如何?

python - 线性回归 Lasagne/Theano

python - 在C中查看日志文件

python - Python和Opencv中的人脸识别

python - 两个 3dim 矩阵的 numpy einsum 的 Theano 版本

python - 使用 'and' 关键字链接语句

python - 通过 shapefile 切割 NetCDF 文件