我正在尝试在 SystemlML 的 DML 中构建一个简单的 hello world 神经网络,但遇到了从 UDF 函数返回多个值的问题。我受到成功运行的这段代码的启发,但我无法弄清楚其中的区别:
按照 Berthold 的要求进行编辑(完整代码):
script = """
#
sigmoid = function(matrix[double] z) return (matrix[double] z) {
z = 1/(1+exp(-z))
}
sigmoidPrime = function(matrix[double] z) return (matrix[double] z) {
#Gradient of sigmoid
z = exp(-z)/(1+exp(-z))
}
X=matrix("3 5 5 1 10 2", rows=3, cols=2)
inputLayerSize = 2
outputLayerSize = 1
hiddenLayerSize = 3
W1 = rand(rows=inputLayerSize,cols=hiddenLayerSize)
W2 = rand(rows=hiddenLayerSize,cols=outputLayerSize)
feedForward = function (matrix[double] X,
matrix[double] W1,
matrix[double] W2) return (matrix[double] z3,matrix[double] Y) {
z2 = X %*% W1
a2 = sigmoid(z2)
z3 = (a2 %*% W2)
Y = sigmoid(z3)
}
#feedForward = function (matrix[double] X,
# matrix[double] W1,
# matrix[double] W2) return (matrix[double] z2,matrix[double] z3,matrix[double] Y) {
# z2 = X %*% W1
# a2 = sigmoid(z2)
# z3 = a2 %*% W2
# Y = sigmoid(z3)
# z2,z3,Y
#}
#gradient = function(matrix[double] X,
# matrix[double] W1,
# matrix[double] W2,
# matrix[double] Y) return (matrix[double] Y) {
# #Compute derivative with respect to W and W2 for a given X and y:
# z2,z3,yHat = feedForward(X,W1,W2)
# delta3 = -(Y-yHat) * sigmoidPrime(z3)
# dJdW2 = t(a2) %*% delta3
# delta2 = (delta3 %*% t(W2))*sigmoidPrime(z2)
# dJdW1 = t(X) %*% delta2
# return dJdW1, dJdW2
#}
Yhat=feedForward(X,W1,W2)
nrx = nrow(X)
ncx = ncol(X)
nrw1 = nrow(W1)
ncw1 = ncol(W1)
"""
如果我删除
matrix[double] z3
它有效,否则我得到:
原因:org.apache.sysml.parser.LanguageException: ERROR: null -- 第 22 行,第 0 列 -- 赋值语句不能返回多个值
有任何想法吗?