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

📄 kmeanspoint.java

📁 聚类算法kmeans
💻 JAVA
字号:
/*
 * Represents an abstraction for a data point in two dimensional space
 *
 */
public class kMeansPoint {


	/** Value in dimension x */
	private int x;
	

	/** Value in dimension y */
	private int y;
	

	/** Assigned cluster */
	private int clusterNumber;
	

	/**
	 * Creates a new instance of data point
	 *
	 * @param	_x	value in dimension x
	 * @param	_y	value in dimension y
	 */
	public kMeansPoint(int _x, int _y) {
	
		this.x = _x;
		this.y = _y;
		this.clusterNumber=0;
	} // end of kMeansPoint()
	
	
	/**
	 * Assigns the data point to a cluster
	 *
	 * @param	_clusterNumber	the cluster to which this data point is to be assigned
	 */
	public void assignToCluster(int _clusterNumber) {
	
		this.clusterNumber = _clusterNumber;
	
	} // end of assignToCluster()
	
	
	/**
	 * Returns the cluster to which the data point belongs
	 *
	 * @return	the cluster number to which the data point belongs
	 */
	public int getClusterNumber() {
	
		return this.clusterNumber;
	
	} // end of getClusterNumber()
	
	
	/**
	 * Returns the value of data point in x dimension
	 *
	 * @return	the value in x dimension
	 */
	public int getX() {
	
		return this.x;
	
	} // end of getX()
	
	
	/**
	 * Returns the value of data point in y dimension
	 *
	 * @return	the value in y dimension
	 */
	public int getY() {
	
		return this.y;
	
	} // end of getY()
	
	
	/**
	 * Returns the distance between two data points
	 *
	 * @param	dp1 	the first data point
	 * @param	dp2 	the second data point
	 * @return	the distance between the two data points
	 */
	public static double distance(kMeansPoint dp1, kMeansPoint dp2) {
	
		double result = 0;
		double resultX = dp1.getX() - dp2.getX();
		double resultY = dp1.getY() - dp2.getY();
		result = Math.sqrt(resultX*resultX + resultY*resultY);
		return result;
	
	} // end of distance()
	
	
	/**
	 * Returns a string representation of this kMeansPoint
	 *
	 * @return	a string representation of this data point
	 */
	public String toString(){
	
		return "(" + this.x + "," + this.y + ")[" + this.clusterNumber + "]";
	
	} // end of toString()
} // end of class

⌨️ 快捷键说明

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