scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 692 forks source link

Symmetry Exception #784

Closed rteehas closed 4 years ago

rteehas commented 4 years ago

I'm getting a MatrixNotSymmetricException for matrices that by construction should be symmetric when they are plugged in as the covariance matrix of a Multivariate Gaussian. The full trace is:

Exception in thread "main" breeze.linalg.MatrixNotSymmetricException: Matrix is not symmetric at breeze.linalg.package$.$anonfun$requireSymmetricMatrix$2(package.scala:151) at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:156) at breeze.linalg.package$.$anonfun$requireSymmetricMatrix$1(package.scala:149) at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:156) at breeze.linalg.package$.requireSymmetricMatrix(package.scala:149) at breeze.linalg.cholesky$ImplCholesky_DM$.apply(cholesky.scala:25) at breeze.linalg.cholesky$ImplCholesky_DM$.apply(cholesky.scala:16) at breeze.generic.UFunc.apply(UFunc.scala:46) at breeze.generic.UFunc.apply$(UFunc.scala:45) at breeze.linalg.cholesky$.apply(cholesky.scala:15) at breeze.stats.distributions.MultivariateGaussian.<init>(MultivariateGaussian.scala:38) at MetropolisHastings$.coarseAndLambda(MetropolisHastings.scala:180) at MetropolisHastings$.gibbsIter(MetropolisHastings.scala:51) at MetropolisHastings$.gibbs(MetropolisHastings.scala:151) at HRM.fit(HRM.scala:43) at MetropolisHastings$.main(MetropolisHastings.scala:314) at MetropolisHastings.main(MetropolisHastings.scala)

It seems to be related to #356 but it still persists on the current version of Breeze. For reference, this is using Scala version 2.12.3. My current approach has been to round the matrices, but this slows down the work considerably.

dlwh commented 4 years ago

Sorry for being slow, can you give a reproducible case? I can take a stab at this based on a guess of the issue.