Using LBFGS for custom objects

77 views
Skip to first unread message

Nikhil J Joshi

unread,
Oct 30, 2015, 7:43:24 PM10/30/15
to Scala Breeze
Hi,

I am extending Spark ML package locally to include one of the specialized model I need to try. In particular, I am trying to extend the LogisticRegression model with one which takes a custom object Weights as weights, and I am getting the following compilation error
could not find implicit value for parameter space: breeze.math.MutableInnerProductModule[breeze.linalg.DenseMatrix[Double],Double]
 [error]       new BreezeLBFGS[Weights]($(maxIter), 10, $(top))

While LogisticRegressionModel object uses Breeze DenseVectors for the weights, I also tried using Breeze DenseMatrix and it generated the same error as before. The question is how to make LBFGS use custom-type parameter space.

I imagine I need to specify the MutableInnerProductModel someway, but not sure how and where. Could someone hint/help?

Thanks in advance,

Nikhil

David Hall

unread,
Oct 30, 2015, 7:51:40 PM10/30/15
to scala-...@googlegroups.com
DenseMatrices don't come with an inner product by default, and so they don't conform to an "MutableInnerProductModule".

The fastest way to make it do this is to add this just above your call to new BreezeLBFGS:

val norms = EntrywiseMatrixNorms.make[DenseMatrix[Double], Double]
import norms._
implicit val space = MutableInnerProductModule.make[DenseMatrix[Double], Double]

(I didn't check this, but it should work)

-- David


--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/6b8916c7-bbe4-4b56-b7ec-bad6587d119d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikhil J Joshi

unread,
Nov 2, 2015, 12:54:10 AM11/2/15
to Scala Breeze
Hi David,

Thanks a lot for the workaround. 
I could guess from the name itself that I need to make my custom object-space an inner product to succeed. I wasn't sure of the side-effects of defining an inner produce in an arbitrary way. 
For now, I am using your method, but in general I think my best bet would be to lay all model coefficients as components of a single long-vector. Any thoughts?

Thanks again :).
Nikhil

David Hall

unread,
Nov 2, 2015, 3:34:53 AM11/2/15
to scala-...@googlegroups.com
Yeah, I usually do the long-vector thing.

Reply all
Reply to author
Forward
0 new messages