I am developing a simple classification algorithm using Scala Breeze. I would like to use Breeze numerics to apply different functions to the matrices I'm working with, specifically sigmoid and tanh. Use of sigmoid alone is fine, but I want to choose sigmoid or tanh by specifying the function as a string parameter and then using it in the method. I have tried:
// 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)
The error is
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)
and the next error is:
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.
Unspecified value parameter impl. val H: BDM[Double] = activationFuncBreeze(af)((M(::,*) + bias).t)
I've looked up Breeze numerics and implementing UFuncs but sigmoid and tanh already exist in the Breeze.numerics library as elementwise UFuncs so I should be able to use them easily. Any suggestions appreciated
Bringing the matrices to the function seems to work: