Apache SystemML DML不允许在函数

时间:2017-07-11 10:06:18

标签: neural-network deep-learning systemml

我正在尝试在SystemlML的DML中构建一个简单的hello world神经网络,但却无法从UDF函数返回多个值。我成功地运行了this code的灵感,但我无法弄清楚它的区别:

按照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:错误:null -   第22行,第0列 - 赋值语句不能返回多个   值

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

SystemML确实支持函数中的多个返回值。见http://apache.github.io/systemml/dml-language-reference.html#user-defined-function-udf

下面的Python示例返回2个矩阵。

DMLstr = """
M1M2 = function( matrix[double] M) 
           return (matrix[double] M1, 
                   matrix[double] M2) {
    M1 = M + 1
    M2 = M + 2
}

X=matrix("3 5 5 1 10 2", rows=3, cols=2) 
[M1, M2] = M1M2 (X)
"""

[M1, M2] = ml.execute(dml(DMLstr).output('M1', 'M2')).get('M1','M2')

print M1.toNumPy()
print M2.toNumPy()

您的代码段未显示“前馈”的调用。你能发帖吗?

答案 1 :(得分:0)

您调用" feedForward"返回输出时不正确。换成这样的东西:

[Yhat1, Yhat2]=feedForward(X,W1,W2)