norm implicit resolution

43 views
Skip to first unread message

Andy Zelinski

unread,
Feb 16, 2015, 10:45:00 AM2/16/15
to scala-...@googlegroups.com
Im working on a project where i will add some additional norm based distances. (Gower, weighted gower, Soergel, Wave Hedges, etc). I was hoping to get some help wrapping my head around the indirection around norm calculations.

im a little unclear looking at trait NormBasedDistance:

from what I understand it looks up, in the norm object, an implicit Impl2[V,Double,Double] that is needed to create a new function that takes a T and a U and returns a Double. 

but in norm object, from looking at norm.scala, i cant tell which direction the  resolution for Impl2[V, Double, Double] goes. 


David Hall

unread,
Feb 16, 2015, 1:15:26 PM2/16/15
to scala-...@googlegroups.com
Well, you probably won't want to use that class, since really it requires a p-norm. Let's look at the signature:

implicit def distanceFromNormAndSub[T, U, V]
(implicit subImpl: OpSub.Impl2[T, U, V],
normImpl: norm.Impl2[V, Double, Double]): Impl2[T, U, Double] = {

This method says that we can provide a distance implementation for any types T and U that have subtraction defined to produce a V, and where the V has a norm(v: V, p: Double) implementation (which is to say a p-norm)

For starters, you probably want to implement things in terms of Dense or SparseVector directly.

--
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/0a7903ed-64a2-4e50-97bf-21f988018a92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andy Zelinski

unread,
Feb 16, 2015, 3:04:34 PM2/16/15
to scala-...@googlegroups.com
ok I see. I guess I just assumed extend NormBased since thats what the existing Manhattan implementation does.

so instead I should just do something like the following?

object GowerDistanceWithPenalties extends UFunc {

implicit object mygowerFromDV extends Impl3[DenseVector[Double], DenseVector[Double],
DenseVector[Double], Double] {
override def apply(...

Thanks for your help, and thanks for this excellent library. a holy grail for my use case!

David Hall

unread,
Feb 16, 2015, 3:10:47 PM2/16/15
to scala-...@googlegroups.com
Yeah that looks great. Breeze convention is (usually) to name UFuncs with lower case initial letters, with exceptions for things like QR and LU, for reasons that aren't entirely principled. If you're not planning on submitting a PR, then feel free to name it however you want, of course :-)

-- David

Reply all
Reply to author
Forward
0 new messages