简体   繁体   中英

Implementing gradient descent with Scala and Breeze - error : could not find implicit value for parameter op:

I'm attempting to apply a gradient descent implementation in Scala and breeze based on Octave from : Gradient Descent implementation in octave

The octave code I'm attempting to re-write is :

theta = theta -((1/m) * ((X * theta) - y)' * X)' * alpha;

I've come up with :

  val xv =       DenseVector[Double](1.0, 1.0)  
  val yv =       DenseVector[Double](1.0, 1.0)  
  val mymatrix : DenseMatrix[Double] = DenseMatrix( (1.0,2.0) , (3.0,4.0) )

  val myvalue = (mymatrix - ((1 / m) * (( (xv * mymatrix - yv).t * xv).t * .0001)

but im receiving a compile time error :

Multiple markers at this line:
◾could not find implicit value for parameter op: breeze.linalg.operators.OpSub.Impl2[breeze.linalg.DenseMatrix[Double],breeze.linalg.DenseVector[Double],That]
◾not enough arguments for method -: (implicit op: breeze.linalg.operators.OpSub.Impl2[breeze.linalg.DenseMatrix[Double],breeze.linalg.DenseVector[Double],That])That. Unspecified value parameter op.

Have I implemented gradient descent correctly using Scala and Breeze ?

It seems I need to provide an implicit for - operator ?

    val myvalue = (mymatrix - ((1 / m) * (( (xv * mymatrix - yv).t * xv).t * .0001)

xv is Vector and the mymatrix is the Matrix which is unsupported . that is the error u are encountering

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM