本文整理汇总了Scala中breeze.linalg.squaredDistance类的典型用法代码示例。如果您正苦于以下问题:Scala squaredDistance类的具体用法?Scala squaredDistance怎么用?Scala squaredDistance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了squaredDistance类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: KMeans
//设置package包名称以及导入依赖的类
package hu.sztaki.tutorial.spark
import breeze.linalg.{Vector, DenseVector, squaredDistance}
import org.apache.spark.{SparkConf, SparkContext}
object KMeans {
def parseVector(line: String): Vector[Double] = {
DenseVector(line.split(' ').map(_.toDouble))
}
def generateData(): List[String] = {
(1 to 1000).map( i =>
(1 to 5).map(j => Math.random()).mkString(" ")
).toList
}
def closestPoint(p: Vector[Double], centers: Array[Vector[Double]]): Int = {
var bestIndex = 0
var closest = Double.PositiveInfinity
for (i <- 0 until centers.length) {
val tempDist = squaredDistance(p, centers(i))
if (tempDist < closest) {
closest = tempDist
bestIndex = i
}
}
bestIndex
}
def main(args: Array[String]) {
if (args.length < 2) {
System.err.println("Usage: KMeans <k> <convergeDist>")
System.exit(1)
}
val sparkConf = new SparkConf().setAppName("KMeans")
val sc = new SparkContext(sparkConf)
val lines = sc.parallelize(generateData())
val K = args(0).toInt
val convergeDist = args(1).toDouble
var tempDist = 1.0
println("Finished iteration (delta = " + tempDist + ")")
}
println("Final centers:")
sc.stop()
}
}
开发者ID:zzvara,项目名称:sztaki-spark-workshop,代码行数:56,代码来源:KMeans.scala
注:本文中的breeze.linalg.squaredDistance类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论