我有flagVectorOutlier
如下代码所示的功能。我正在使用 BreezeDenseVector
和DenseMatrix
对象来计算distance
. 我希望按照函数签名上的编码,得到一个 Spark RDD[(Double, Boolean)]
。mi
和invCovMatrix
分别是 Breeze 的DenseVector[Double]
和DenseMatrix[Double]
:
def flagVectorOutlier(testVectors: RDD[(String, SparkVector)], distanceThreshold: Double): RDD[(Double, Boolean)] = {
val testVectorsDenseRDD = testVectors.map { vector => DenseVector(vector._2.toArray)}
val mahalanobisDistancesRDD = testVectorsDenseRDD.map { vector =>
val distance = DenseVector[Double](DenseVector(Transpose(vector - mi) * invCovMatrix) * DenseVector(vector - mi)).toArray
(distance(0), if(distance(0) >= distanceThreshold) true else false)
}
mahalanobisDistancesRDD
}
编译器最终向我显示以下 2 个错误:
Error:(75, 93) could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2[breeze.linalg.DenseVector[breeze.linalg.Transpose[breeze.linalg.DenseVector[Double]]],breeze.linalg.DenseVector[breeze.linalg.DenseVector[Double]],That]
val distance = DenseVector[Double](DenseVector(Transpose(vector - mi) * invCovMatrix) * DenseVector(vector - mi)).toArray
^
和
Error:(75, 93) not enough arguments for method *: (implicit op: breeze.linalg.operators.OpMulMatrix.Impl2[breeze.linalg.DenseVector[breeze.linalg.Transpose[breeze.linalg.DenseVector[Double]]],breeze.linalg.DenseVector[breeze.linalg.DenseVector[Double]],That])That.
Unspecified value parameter op.
val distance = DenseVector[Double](DenseVector(Transpose(vector - mi) * invCovMatrix) * DenseVector(vector - mi)).toArray
^
我错过了什么?我正在考虑以这种方式在 Breeze's 之间进行乘法运算是可能的DenseVector
。