day57
2021/7/17 23:06:12
本文主要是介绍day57,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
// Step 2.4 Find the new center double[] tempCenterDistance = new double[tempNewCenters.length]; double[] tempNearest = new double[tempNewCenters.length]; for (int i = 0; i < tempNewCenters.length; i++) { for (int j = 0; j < numClusters; j++) { tempCenterDistance[j] = newDistance(tempNewCenters[i], tempCenters[j], tempNewCenters.length); if (tempCenterDistance[j] > tempNearest[j]) { tempCenterDistance[j] = tempNearest[j]; tempNewCenters[i] = tempCenters[j]; }//of if }//of for j }//of for i
以上为定位准确位置,以下为距离计算
/** ********************* * The distance between two instances. * * @param paraI * The index of the first instance. * @param paraArray * The array representing a point in the space. * @return The distance. ********************* */ public double newDistance(double[] paraI, double[] paraArray, int paraLength) { int resultDistance = 0; double tempDifference; switch (distanceMeasure) { case MANHATTAN: for (int i = 0; i < paraLength; i++) { for (int j = 0; i < dataset.numAttributes() - 1; i++) { tempDifference = paraI[i] - paraArray[j]; //将距离绝对值加上 if (tempDifference < 0) { resultDistance -= tempDifference; } else { resultDistance += tempDifference; }//of if }//of for j }//of for i break; case EUCLIDEAN: for (int i = 0; i < paraLength; i++) { for (int j = 0; j < dataset.numAttributes() - 1; j++) { tempDifference = paraI[i] - paraArray[j]; resultDistance += tempDifference * tempDifference; //根据维度求欧式距离 }//of for j }//of for i break; default: System.out.println("Unsupported distance measure: " + distanceMeasure); }//of switch return resultDistance; }//of newDistance
这篇关于day57的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24怎么修改Kafka的JVM参数?-icode9专业技术文章分享
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?