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

📄 cluster.java

📁 聚类算法
💻 JAVA
字号:
package cluster.kmeans;

import java.util.Vector;

/**
 * This class represents a Cluster in a Cluster Analysis Instance. A Cluster is
 * associated with one and only one JCA Instance. A Cluster is related to more
 * than one DataPoints and one centroid.
 * 
 * @author bigjava
 * @version 1.1
 * @see DataPoint
 * @see Centroid
 */

class Cluster {
	private String mName;

	private Centroid mCentroid;

	private double mSumSqr;

	private Vector mDataPoints;

	public Cluster(String name) {
		this.mName = name;
		this.mCentroid = null; // will be set by calling setCentroid()
		mDataPoints = new Vector();
	}

	public void setCentroid(Centroid c) {
		mCentroid = c;
	}

	public Centroid getCentroid() {
		return mCentroid;
	}

	public void addDataPoint(DataPoint dp) { // called from CAInstance
		dp.setCluster(this); // initiates a inner call to calc
								// EuclideanDistance() in DP.
		this.mDataPoints.addElement(dp);
		calcSumOfSquares();
	}

	public void removeDataPoint(DataPoint dp) {
		this.mDataPoints.removeElement(dp);
		calcSumOfSquares();
	}

	public int getNumDataPoints() {
		return this.mDataPoints.size();
	}

	public DataPoint getDataPoint(int pos) {
		return (DataPoint) this.mDataPoints.elementAt(pos);
	}

	public void calcSumOfSquares() { // called from Centroid
		int size = this.mDataPoints.size();
		double temp = 0;
		for (int i = 0; i < size; i++) {
			temp = temp
					+ ((DataPoint) this.mDataPoints.elementAt(i))
							.getCurrentEuDt();
		}
		this.mSumSqr = temp;
	}

	public double getSumSqr() {
		return this.mSumSqr;
	}

	public String getName() {
		return this.mName;
	}

	public Vector getDataPoints() {
		return this.mDataPoints;
	}

}

⌨️ 快捷键说明

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