我正在编写一个代码来执行内核K-Means(别名https://en.wikipedia.org/wiki/K-means_clustering,但有一个技巧)。我需要生成数据,并且作为第一个简单的生成器,我试图实现高斯混合模型。这里是我的代码:SBT编译器崩溃使用Scala-Breeze
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
}
}
当我尝试编译我的代码(我用的Scala的IDE和Windows 10 SBT蚀)我得到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,我可以提供方向:)。
它看起来像一个编译器错误(我猜想在微风使用这些的scala宏)。您可以尝试在项目中执行全面清理(甚至可能包括'.ivy2'文件夹 - 这可能是您的MacOS和Windows设置之间的区别),并且还会将您的Scala更新为2.11.11(或甚至2.12.x) – dk14
这是,谢谢你!我必须在Eclipse中编辑更新站点,因为此处提出的Scala IDE仅限于Scala 2.11.8。现在使用最新版本的Scala 2.12.2,错误消失了:)。 – vkubicki
如果你想提出这个评论作为答案,我会选择它,这将关闭问题:)。 – vkubicki