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

📄 cluster.java

📁 上传试试看 不知道 是不是一定成功的
💻 JAVA
字号:
/**
 *
 */
package k_means;
import java.util.LinkedList;
/**
 * stored data of the one cluster
 * @author  YU
 *
 */
public class Cluster
{
	private LinkedList<Double[]> CluData; // using a Link structor tostore the data of the current cluster
	private int Count; // the number of the current cluster
	private int DimensionData;//the dimesion of data int the current cluster
	private Double[] Centriod;
	private Double[] CentroidOld; //the centriod of the culster


	/**
	 * Structor function :initialize the attribute
	 * @param dimension is the dimesion of data int the current cluster
	 */
	public Cluster(int dimension)
	{
		this.DimensionData = dimension;
		Count = 0;
		CluData = new LinkedList<Double[]>();
		Centriod = new Double[dimension];
		CentroidOld = new Double[dimension];
	}
	/**
	 * calculate the average of this cluster
	 */
	public Double[] avgCluster()
	{
		countNum();
		Double[] avg = new Double[this.DimensionData];
		for (int i = 0; i < avg.length; i++)
		{
			avg[i] = Double.valueOf(0);
		}


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

	}
	/**
	 * calculate the number of this cluster
	 *
	 */
	public void countNum()
	{
		Count = CluData.size();
	}
	/**
	 * get data of the cluster
	 * @return LinkedList<Double[]>
	 */
	public LinkedList<Double[]> getCluData()
	{
		return CluData;
	}
	/**
	 * set data of the cluster
	 *
	 */
	public void setCluData(LinkedList<Double[]> 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;
	}
	/**
	 *  set  the old centroid of the cluster
	 * @param centroidOld
	 */
	public void setCentroidOld(Double[] centroidOld)
	{
		CentroidOld = centroidOld;
	}
	/**
	 * get  the old centroid of the cluster
	 * @return
	 */
	public Double[] getCentroidOld()
	{
		// TODO Auto-generated method stub
		return CentroidOld;
	}
	/**
	 * output the current cluster
	 */
	public void output()
	{
		System.out.println("类");
		for (int i = 0; i < this.CluData.size(); i++)
		{
			for(int j = 0; j < DimensionData; j++)
			{
				System.out.print(CluData.get(i)[j] + "	");
			}
			System.out.println();

		}
		System.out.println("--------------------");
	}
}

⌨️ 快捷键说明

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