java实现K-means算法,k-means聚类算法原理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hotpots/article/details/80384850
	/**
	 * 需要所有point 以及族中心list
	 * 
	 * @author:Yien
	 * @when:2018年5月20日下午3:14:09
	 * @Description:TODO
	 * @param:@param pointList
	 * @param:@param centerPointList
	 * @param:@return
	 * @return:Map<UserScorePoint,UserScorePoint>
	 * @throws:
	 */
	public static Map<UserScorePoint, UserScorePoint> 迭代函数(List<UserScorePoint> pointList,
			List<UserScorePoint> centerPointList) {

		/**
		 * 
		 * centerPointList可能为空;
		 */
		// System.out.println("三个新的族中心是:" + Arrays.toString(centerPointList.toArray()));

		Map<UserScorePoint, UserScorePoint> pointCenterMap = new HashMap<UserScorePoint, UserScorePoint>();
		/**
		 * 已经初始化了族心 就往Map自动添加进去
		 */
		if (!centerPointList.isEmpty()) {

			for (UserScorePoint point : centerPointList) {

				pointCenterMap.put(point, point);

			}
			/**
			 * 在列表中去掉族中心集合
			 */
			pointList.removeAll(centerPointList);
		}
		for (int i = centerPointList.size(); i < pointList.size(); ++i) {
			/**
			 * 添加族中心列表
			 */
			if (centerPointCount > i) {

				centerPointList.add(pointList.get(i));
				/**
				 * 族心自动添加到族
				 */
				pointCenterMap.put(pointList.get(i), pointList.get(i));
			}

			/**
			 * 继续遍历 找族中心;
			 */
			else {

				UserScorePoint centerPoint = findWhichPoint(pointList.get(i), centerPointList);
				// System.out.println("这里是找到的族心"+centerPoint);

				/**
				 * 向Map添加族心信息;
				 */
				pointCenterMap.put(pointList.get(i), centerPoint);
			}

		}

		return pointCenterMap;

	}

猜你喜欢

转载自blog.csdn.net/hotpots/article/details/80384850