SBT编译器使用Scala-Breeze崩溃

时间:2017-08-05 13:59:04

标签: scala sbt scala-breeze

我正在编写一个代码来执行内核K-Means(又名https://en.wikipedia.org/wiki/K-means_clustering,但有一个技巧)。我需要生成数据,作为第一个简单的生成器,我试图实现高斯混合模型。这是我的代码:

package p02kmeans

import breeze.linalg._
import breeze.stats.distributions._

/**
 * First data generation is simple, gaussian mixture model.
 */
object Data {
  class GaussianClassParam (
      val mean: Double,
      val sd: Double)

  /**
   * @param proportion marginal probability for each label
   * @param param param[j][k] returns the GaussianClassParam for the k class of the j variable
   * @param nObs number of observations to be generated
   * @result DenseMatrix_ij where i is the observation index and j is the variable number
   */
  def gaussianMixture(
      proportion: DenseVector[Double],
      param: Vector[Vector[GaussianClassParam]],
      nObs: Int)
  : DenseMatrix[Double] = {
    val nVar = param.size
    val multiSampler = Multinomial(proportion) // sampler for the latent class
    val varSamplerVec = param.map(v => v.map(c => Gaussian(c.mean, c.sd)))
    val zi = DenseVector.fill[Int](nObs)(multiSampler.sample)

    val data = DenseMatrix.tabulate[Double](nObs, nVar)((i, j) => varSamplerVec(j)(zi(i)).sample)

    return data
  }
}

当我尝试编译我的代码时(我在Windows 10上使用Scala-Ide和sbt eclipse)我得到2个错误:

  • Error in Scala compiler: assertion failed: List(method apply$mcI$sp, method apply$mcI$sp)
  • SBT builder crashed while compiling. The error message is 'assertion failed: List(method apply$mcI$sp, method apply$mcI$sp)'. Check Error Log for details.

错误由以下行触发:

val data = DenseMatrix.tabulate[Double](nObs, nVar)((i, j) => varSamplerVec(j)(zi(i)).sample)

然后消失:

val data = DenseMatrix.tabulate[Double](nObs, nVar)((i, j) => 12.0)

你能帮我调试吗?

我的sbt配置:

name := "Sernel"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies  ++= Seq(
  "org.scalanlp" %% "breeze" % "0.13.1",
  "org.scalanlp" %% "breeze-natives" % "0.13.1",
  "org.scalanlp" %% "breeze-viz" % "0.13.1"
)

我在OSX设置上遇到了同样的错误。

如果你想测试整个包(因为,如果你想重现错误),代码可以在Github上找到:https://github.com/vkubicki/sernel,我可以提供指示:)。

1 个答案:

答案 0 :(得分:0)

这似乎是一个编译器错误(我想在scala宏中,因为Breeze正在使用它们)。您可以尝试在项目中执行完全清理(甚至可能包括.ivy2文件夹 - 这可能是您的MacOS和Windows安装程序之间的差异)并且还将scala更新为2.11.11(或者甚至可能是2.12.x)

然而,Scala 2.11.6的类似问题(以及某些东西告诉我它在后续版本的Scala中继承)并没有修复:https://issues.scala-lang.org/browse/SI-9284

所以可能,你有时需要反复进行清洁,或者尝试一些其他的NumPy类似物:scalala,Nd4j / Ndjs。

它还可以帮助尝试另一个IDE(IDEA / Atom)或尝试使用“裸”SBT,因为Eclipse可能会干扰调用Scala的编译器前端。

相关问题