Using LBFGS for custom objects

77 wyświetleń
Przejdź do pierwszej nieodczytanej wiadomości

Nikhil J Joshi

nieprzeczytany,
30 paź 2015, 19:43:2430.10.2015
do 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

nieprzeczytany,
30 paź 2015, 19:51:4030.10.2015
do 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

nieprzeczytany,
2 lis 2015, 00:54:102.11.2015
do 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

nieprzeczytany,
2 lis 2015, 03:34:532.11.2015
do scala-...@googlegroups.com
Yeah, I usually do the long-vector thing.

Odpowiedz wszystkim
Odpowiedz autorowi
Przekaż
Nowe wiadomości: 0