我使用Theano有点问题。似乎division 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中执行的一些计算来说是个问题,我不想从GPU中取回数据,用inf
替换0
来继续我的计算,当然,因为这样会大大减慢计算过程。你知道吗
theano.tensor
计算元素方向逆np.linalg.inv
计算逆矩阵矩阵从数学上讲,这不是一回事
你可能在寻找实验性的^{}
相关问题 更多 >
编程相关推荐