我正在編寫一個代碼來執行內核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