Is there any way to compute the distance matrix of given Vectors?

892 views
Skip to first unread message

farzad nozarian

unread,
Mar 23, 2015, 3:45:54 PM3/23/15
to scala-...@googlegroups.com
Hi, I'm new in scala and also Breeze and I'd like to know what is the best way to calculate the distance matrix of set of Vector using Breeze APIs.
Assume that the distance method is Euclidean and the Vector's set is very large.
And also another question: Is there any pdist-like matrix?

David Hall

unread,
Mar 26, 2015, 4:38:55 PM3/26/15
to scala-...@googlegroups.com

There's nothing built-in sorry. Happy to take a patch if you write it :)

--
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/c79d43b0-7d83-4e3a-9c03-9cd22af6242b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Debasish Das

unread,
Mar 27, 2015, 11:45:26 AM3/27/15
to scala-...@googlegroups.com
You can certainly use all of breeze distance functions from Spark distributed/multi-core matrices...

Saleem Ansari

unread,
Mar 28, 2015, 9:59:31 AM3/28/15
to scala-...@googlegroups.com
On Fri, Mar 27, 2015 at 9:15 PM, Debasish Das <debasis...@gmail.com> wrote:
> You can certainly use all of breeze distance functions from Spark
> distributed/multi-core matrices...
>

Could you point to any examples that use Breeze API to do operations
on Spark RRDs ( matrix, vector etc ) ?

Thanks!

Regards,
Saleem
Message has been deleted

Daniel Korzekwa

unread,
Apr 9, 2015, 8:26:45 AM4/9/15
to scala-...@googlegroups.com
actually I would need it too, as I plan to migrate from ejml to breeze for some of my work. So far I use this code on top of ejml:

-------------------------------------
val vec1 = Array(1,2,3)
val vevc = Array(4,5,6)

covarianceMatrix(3,3,(rowIndex,colIndex) => vec1(rowIndex)-vec2(colIndex) ) //simply the difference between corresponding elements in vectors 1 and 2

def covarianceMatrix(numRows: Int, numCols: Int, cell: (Int, Int) => Double): Matrix= {

   val data = new Array[Array[Double]](numRows)

    for (rowIndex <- 0 until numRows) {
      val rowVector = new Array[Double](numCols)

      for (colIndex <- 0 until numCols) {
        rowVector(colIndex) = cell(rowIndex, colIndex)
      }

      data(rowIndex) = rowVector
    }

    Matrix(data)
  }
Reply all
Reply to author
Forward
0 new messages