我有一个简单的问题,我希望已经在网上找到了一个简单的答案,但我没有。
由于矩阵运算,我有一个 python 项目可以与 numpy 一起使用。我想加快代码速度,所以我做了一些分析以找出适合这项工作的工具。原来开销不是python,而是矩阵运算。因此我认为我应该使用 Theano(特别是考虑到我正在实现机器学习算法的情况,这就是为之而生的)。
我项目的大部分开销都在一个函数中,我想知道是否有可能只用 theano 重写该函数,然后从中取出 numpy 数组并像往常一样继续计算。
这再次只是为了测试在不承诺更改大量代码的情况下我将获得多少速度。
谢谢!
编辑:万一是这个功能
def backprop(weights, layerValues, finalLayerErrors, activationFunctions):
nrLayers = len(weights) + 1
deDw = []
deDbias = []
upperLayerErrors = finalLayerErrors
for layer in xrange(nrLayers - 1, 0, -1):
deDz = activationFunctions[layer - 1].derivativeForLinearSum(
upperLayerErrors, layerValues[layer])
upperLayerErrors = np.dot(deDz, weights[layer - 1].T)
dw = np.einsum('ij,ik->jk', layerValues[layer - 1], deDz)
dbias = deDz.sum(axis=0)
# Iterating in decreasing order of layers, so we are required to
# append the weight derivatives at the front as we go along
deDw.insert(0, dw)
deDbias.insert(0, dbias)
return deDw, deDbias