【问题标题】:Apache SystemML DML doesn't allow for multiple return values in functionApache SystemML DML 不允许函数中有多个返回值
【发布时间】:2017-07-11 10:06:17
【问题描述】:

我正在尝试在 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: ERROR: null -- 第 22 行,第 0 列——赋值语句不能返回多个 价值观

有什么想法吗?

【问题讨论】:

    标签: neural-network deep-learning systemml


    【解决方案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()
    

    您的 sn-p 没有显示“前馈”的调用。可以发帖吗?

    【讨论】:

    • 调用错误 [z3,Yhat]=feedForward(X,W1,W2) 有效,但我已经把 Yhat=feedForward(X,W1,W2)
    【解决方案2】:

    当您返回输出时,您对“feedForward”的调用不正确。改成这样:

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

    【讨论】:

      猜你喜欢
      • 2020-04-10
      • 2022-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      相关资源
      最近更新 更多