centroid.java

来自「一个k-means算法的改进。使用了模糊聚类的方法」· Java 代码 · 共 87 行

JAVA
87
字号
package kc.test.kmeans;

import java.awt.geom.Point2D;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Thomas Neidhart, thomas.neidhart@gmail.com, all rights by Know-Center
 * Date: Aug 3, 2005
 *
 * Represents a cluster centroid
 */
public class Centroid extends Point
{
    private ArrayList<Point> points;
    private ArrayList<Point2D> history;

    /**
     * Create a new centroid object
     * @param p the point on the x-y plane
     * @param c the color associated with this cluster
     */
    public Centroid(Point2D p, Color c) {
        super(p, c);

        points = new ArrayList<Point>();
        history = new ArrayList<Point2D>();
    }

    /**
     * add a point to the point list
     * @param p
     */
    public void addPoint(Point p) {
        points.add(p);
    }

    /**
     * clear point list
     */
    public void clearPoints() {
        points.clear();
    }

    /**
     * get an iterator containing all points associated with this cluster centroid
     * @return
     */
    public List<Point> getPoints() {
        return points;
    }

    /**
     * add a 2d point as track for history information
     * @param p the point
     */
    public void addTrack(Point2D p) {
        history.add(p);
    }

    /**
     * Get a list of all history points
     * @return
     */
    public List<Point2D> getHistory() {
        return history;
    }

    /**
     * Clear the history information
     */
    public void clearHistory() {
        history.clear();
    }

    /**
     * create a clone of this centroid
     * @return the clone centroid
     */
    public Centroid clone() {
        Centroid c = null;
        c = (Centroid) super.clone();
        return c;
    }
}

⌨️ 快捷键说明

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