Created
March 23, 2015 23:04
-
-
Save antonycourtney/023f5062ef46b36e5b31 to your computer and use it in GitHub Desktop.
Breeze MultivariateGaussian Timing Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import breeze.linalg._ | |
import breeze.math._ | |
import breeze.stats.distributions._ | |
object TimingTest { | |
def timeIt[R](block: => R): R = { | |
val t0 = System.nanoTime() | |
val result = block // call-by-name | |
val t1 = System.nanoTime() | |
val elapsed = t1 - t0 | |
println("Elapsed time: " + elapsed + "ns (" + elapsed / 1e9 + " sec)") | |
result | |
} | |
def testMVGaussian(): Double = { | |
val dm = DenseMatrix((1.0,-0.9),(-0.9,1.0)) | |
val mvd = MultivariateGaussian(DenseVector(0.0,0.0),dm) | |
val n = 10000 | |
var zs : IndexedSeq[DenseVector[Double]] = null | |
for (i <- 1 to 100) { | |
zs = mvd.sample(n) | |
} | |
zs(n-1)(1) | |
} | |
def main(args: Array[String]) = { | |
val v = timeIt { testMVGaussian } | |
println("v: " + v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment