it.unibz.algorithms.types
Class Centroid

java.lang.Object
  extended by it.unibz.algorithms.types.Centroid

public class Centroid
extends java.lang.Object

This class represent a centroid. This class is useful for example for the k-means algorithm that assigns each point to the cluster whose centroid is nearest. It contains the coordinates x, y and also an object of type cluster.


Field Summary
private  Cluster cluster
           
private  double x
           
private  double y
           
 
Constructor Summary
Centroid(double x, double y)
          This constructor assigns only the coordinates to the centroid object
 
Method Summary
 void calcCentroid()
          This method retrieves the number of data points, then calculates the new centroid.
 double getClusterX()
          This method returns the x coordinate of the cluster
 double getClusterY()
          This method returns the y coordinate of the cluster
 void setCluster(Cluster c)
          This method sets the cluster object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

private double x

y

private double y

cluster

private Cluster cluster
Constructor Detail

Centroid

public Centroid(double x,
                double y)
This constructor assigns only the coordinates to the centroid object

Parameters:
x - coordinate x
y - coordinate y
Method Detail

calcCentroid

public void calcCentroid()
This method retrieves the number of data points, then calculates the new centroid. After that it calculates the new euclidean distance for each Instance. Finally, it calculates the new sum of squares for the cluster.


setCluster

public void setCluster(Cluster c)
This method sets the cluster object. Crucial because the constructor does not touch this class variable.

Parameters:
c - Cluster Object

getClusterX

public double getClusterX()
This method returns the x coordinate of the cluster

Returns:
x coordinate

getClusterY

public double getClusterY()
This method returns the y coordinate of the cluster

Returns:
y coordinate