Skip to content

Instantly share code, notes, and snippets.

View cmcbride's full-sized avatar

Cameron McBride cmcbride

  • Boston, MA (USA)
View GitHub Profile
@cmcbride
cmcbride / SparkConjugateGradient.scala
Created September 29, 2015 19:20
Test Implementation of Conjugate Gradient for Linear Problem
import org.apache.spark.mllib.linalg.{Vector, Vectors, Matrices}
import org.apache.spark.mllib.linalg.distributed.{IndexedRow, IndexedRowMatrix}
// Ensure a properly ordered local vector from a distributed RDD
// (Int,Double) corresponds to (index, value) where index is the proper order
def array_from_rdd( rdd: RDD[(Int,Double)] ) : Array[Double] =
rdd.sortBy(_._1).map(_._2).toArray
def vec_from_rdd( rdd: RDD[(Int,Double)] ) =
Vectors.dense( array_from_rdd( rdd ) )

Keybase proof

I hereby claim:

  • I am cmcbride on github.
  • I am cmcbride (https://keybase.io/cmcbride) on keybase.
  • I have a public key ASA9sGOXeTsPKKs8InpZXzPbfGr3v0ehS9zIdPDK6pK1Rwo

To claim this, I am signing this object: