【发布时间】:2017-09-13 21:29:47
【问题描述】:
我正在使用 Scala Breeze 开发一个简单的分类算法。我想使用 Breeze 数字将不同的函数应用于我正在使用的矩阵,特别是 sigmoid 和 tanh。单独使用 sigmoid 很好,但我想通过将函数指定为字符串参数然后在方法中使用它来选择 sigmoid 或 tanh。我试过了:
// this code works
import breeze.numerics._
val H: BDM[Double] = sigmoid((M(::,*) + bias).t)
// this code throws an error
def activationFuncBreeze(af: String) = af match {
case "sigmoid" => sigmoid
case "tanh" => tanh
}
val H: BDM[Double] = activationFuncBreeze(af)((M(::,*) + bias).t)
错误是
Error:(60, 50) could not find implicit value for parameter impl: breeze.generic.UFunc.UImpl[_13.type,breeze.linalg.DenseMatrix[Double],VR]
val H: BDM[Double] = activationFuncBreeze(af)((M(::,*) + bias).t)
下一个错误是:
Error:(60, 50) not enough arguments for method apply: (implicit impl: breeze.generic.UFunc.UImpl[_13.type,breeze.linalg.DenseMatrix[Double],VR])VR in trait UFunc.
未指定值参数 impl。 val H: BDM[Double] = activationFuncBreeze(af)((M(::,*) + bias).t)
我查看了 Breeze numerics 并实现了 UFuncs,但 Breeze.numerics 库中已经存在 sigmoid 和 tanh 作为元素 UFuncs,所以我应该能够轻松使用它们。任何建议表示赞赏
【问题讨论】:
标签: scala scala-breeze