is the svd function robust

已查看 10 次
跳至第一个未读帖子

Jim Newton

未读,
2021年4月4日 11:58:542021/4/4
收件人 Scala Breeze
I'm trying to use breeze to test some of my own code.
I.e., I have some code that computes exp(M).
I'd like to test using breeze.
My testing code computes (u,s,v) by calling svd(m)
Then I compute: exp(m) = u * (s.map {x:Double => math.exp(x)}) * v

There are two issues I see.  Are these known issues?  Or do I need to prepare a test case and file a bug report?   I'm a 1st time user, so maybe these are known issues?

1.  I get a bunch of unwanted INFO messages of the form:

Apr 04, 2021 11:35:58 AM com.github.fommil.jni.JniLoader liberalLoad
INFO: successfully loaded 
Apr 04, 2021 11:35:58 AM com.github.fommil.jni.JniLoader load

2. java.lang.IllegalArgumentException on the following code

val dm = DenseMatrix.tabulate(dim, dim){case (i, j) => this(i,j)}
val svd.SVD(u,s,v) = svd(dm)
println(s"dm=[$dm]")
println(s"u=[$u]")
println(s"s=[$s]")
println(s"v=[$v]")
println("exp lambda = " + (s.map {x:Double => math.exp(x)}))

val em = u * (s.map {x:Double => math.exp(x)}) * v



Here is the output

dm=[-0.9315079940605946  -0.8636480438490705  
-0.9371076081540446  0.3813488062121273   ]
u=[-0.8593567106990224  -0.5113766163763811  
-0.5113766163763811  0.8593567106990224   ]
s=[DenseVector(1.39178232086381, 0.8367404849973938)]
v=[0.9194775249120006    0.39314257106258693  
-0.39314257106258693  0.9194775249120006   ]
exp lambda = DenseVector(4.02201218472115, 2.308829035558848)


requirement failed: b.rows == 1 (2 != 1)
java.lang.IllegalArgumentException: requirement failed: b.rows == 1 (2 != 1)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$$anon$3.apply(DenseMatrixOps.scala:126)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$$anon$3.apply(DenseMatrixOps.scala:124)
at breeze.linalg.ImmutableNumericOps.$times(NumericOps.scala:118)
at breeze.linalg.ImmutableNumericOps.$times$(NumericOps.scala:117)
at breeze.linalg.DenseVector.$times(DenseVector.scala:56)
at homework.Transcendentals$sqMatrix.expB(HW-Transcendentals-solution.scala:308)
at TranscendentalsTestSuite.$anonfun$new$76(TranscendentalsTestSuite.scala:515)
at scala.collection.immutable.Vector.foreach(Vector.scala:1856)
at TranscendentalsTestSuite.$anonfun$new$70(TranscendentalsTestSuite.scala:494)
at scala.runtime.java8.JFunction1$mcVI$sp.apply(JFunction1$mcVI$sp.scala:18)
at scala.collection.immutable.List.foreach(List.scala:333)
at TranscendentalsTestSuite.$anonfun$new$69(TranscendentalsTestSuite.scala:493)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)

Jim Newton

未读,
2021年4月6日 10:50:352021/4/6
收件人 Scala Breeze
I figured out problem #2.  The middle value returned from svd is not a nxn diagonal matrix, but rather a vector. I can convert it back to a matrix with the diag function

David Hall

未读,
2021年4月6日 19:35:362021/4/6
收件人 scala-...@googlegroups.com
The info messages should only show up the first the time any breeze function is called. Netlib-java uses java's builtin java.util.logging stuff and can be configured that way. It's a bit of a pain to do honestly.

-- 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 view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/03c7ce12-9001-4bc8-a9da-f064799023c1n%40googlegroups.com.
回复全部
回复作者
转发
0 个新帖子