我在使用 Theano 时遇到了一点问题。似乎 adivision by 0
结果inf
不像使用例如 Numpy 那样导致 0 (至少反函数的行为确实如此)。看一看:
from theano import function, sandbox, Out, shared
import theano.tensor as T
import numpy as np
reservoirSize = 7
_eye = np.eye(reservoirSize)
gpu_I = shared( np.asarray(_eye, np.float32 ) )
simply_inverse = function(
[],
Out(sandbox.cuda.basic_ops.gpu_from_host(
T.inv( gpu_I )
),
borrow=True
)
)
gpu_wOut = simply_inverse()
Wout = np.linalg.inv(_eye)
print "gpu_wOut:\n"
print np.asarray(gpu_wOut)
print "\nWout:\n"
print np.asarray(Wout)
diff_wOut = np.asarray(gpu_wOut) - Wout
diff_wOut = [ diff_wOut[0][i] if diff_wOut[0][i] > epsilon else 0 for i in range(reservoirSize)]
print "\n\nDifference of output weights: (only first row)\n"
print np.asarray(diff_wOut)
结果:
gpu_wOut:
[[ 1. inf inf inf inf inf inf]
[ inf 1. inf inf inf inf inf]
[ inf inf 1. inf inf inf inf]
[ inf inf inf 1. inf inf inf]
[ inf inf inf inf 1. inf inf]
[ inf inf inf inf inf 1. inf]
[ inf inf inf inf inf inf 1.]]
Wout:
[[ 1. 0. 0. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0. 0.]
[ 0. 0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 1. 0. 0.]
[ 0. 0. 0. 0. 0. 1. 0.]
[ 0. 0. 0. 0. 0. 0. 1.]]
Difference of output weights (only first row):
[ 0. inf inf inf inf inf inf]
这对于我想在我的 GPU 中执行的一些计算来说是一个问题,我不想从中取回数据来替换inf
以0
继续我的计算,因为这会大大减慢这个过程。