⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pointcluster.java

📁 上传试试看 不知道 是不是一定成功的
💻 JAVA
字号:
package k_means;

import java.util.LinkedList;

public class PointCluster
{
	private LinkedList<OneData> CluData; // using a Link structor tostore the data of the current cluster
	private int Count; // the number of the current cluster
	private double[] Centriod;
	private double[] CentroidOld; //the centriod of the culster


	/**
	 * Structor function :initialize the attribute
	 * para is the dimesion of data int the current cluster
	 */
	public PointCluster()
	{

		Count = 0;
		CluData = new LinkedList<OneData>();
		Centriod = new double[2];
		CentroidOld = new double[2];
	}
	/**
	 * calculate the average of this cluster
	 */
	public double[] avgCluster()
	{
		countNum();
		double[] avg = new double[2];
		for (int i = 0; i < avg.length; i++)
		{
			avg[i] =0;
		}




				for (int i = 0; i < Count; i++)
				{
					avg[0] +=  CluData.get(i).x;
				}
				avg[0] = avg[0]/Count;

				for (int i = 0; i < Count; i++)
				{
					avg[1] +=  CluData.get(i).y;
				}
				avg[1] = avg[1]/Count;

			return avg;
	}
	/**
	 * calculate the number of rhis cluster
	 *
	 */
	public void countNum()
	{
		Count = CluData.size();
	}
	/**
	 * get data of the cluster
	 * @return
	 */
	public LinkedList<OneData> getCluData()
	{
		return CluData;
	}
	/**
	 * set data of the cluster
	 *
	 */
	public void setCluData(LinkedList<OneData> cluData)
	{
		CluData = cluData;
	}
	/**
	 * get centroid of the cluster
	 *
	 */
	public double[] getCentriod()
	{
		return Centriod;
	}
	/**
	 * update centroid of the cluster
	 *
	 */
	public void updateCentriod()
	{
		Centriod = avgCluster();
	}
	/**
	 * set centroid of the cluster
	 *
	 */
	public void setCentriod(double[] a)
	{
		Centriod = a;
	}

	public void setCentroidOld(double[] centroidOld)
	{
		CentroidOld = centroidOld;
	}
	public double[] getCentroidOld()
	{
		// TODO Auto-generated method stub
		return CentroidOld;
	}
	/**
	 * output the current cluster
	 */
	public void output()
	{
		System.out.println("绫

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -