public double costOfPoint(int k, Point[] centres){
		double nearestCost = -1.0;
		for(int j=0; j<k; j++){
			double distance = 0.0;
			int l = 0;
			for(l=0;l<this.dimension;l++){
				//Centroid coordinate of the point
				double centroidCoordinatePoint;
				if(this.weight != 0.0){
					centroidCoordinatePoint = this.coordinates[l] / this.weight;
				} else {
					centroidCoordinatePoint = this.coordinates[l];
				}
				//Centroid coordinate of the centre
				double centroidCoordinateCentre;
				if(centres[j].weight != 0.0){
					centroidCoordinateCentre = centres[j].coordinates[l] / centres[j].weight;
				} else {
					centroidCoordinateCentre = centres[j].coordinates[l];
				}
				distance += (centroidCoordinatePoint-centroidCoordinateCentre) * 
						(centroidCoordinatePoint-centroidCoordinateCentre) ;
			}
			
			if(nearestCost <0 || distance < nearestCost) {
				nearestCost = distance;
			} 
		}
		return this.weight * nearestCost;
	}
public double costOfPoint ( int k , Point [ ] centres ) { double nearestCost = - 1.0 ; for ( int j = 0 ; j < k ; j ++ ) { double distance = 0.0 ; int l = 0 ; for ( l = 0 ; l < this . dimension ; l ++ ) { double centroidCoordinatePoint ; if ( this . weight != 0.0 ) { centroidCoordinatePoint = this . coordinates [ l ] / this . weight ; } else { centroidCoordinatePoint = this . coordinates [ l ] ; } double centroidCoordinateCentre ; if ( centres [ j ] . weight != 0.0 ) { centroidCoordinateCentre = centres [ j ] . coordinates [ l ] / centres [ j ] . weight ; } else { centroidCoordinateCentre = centres [ j ] . coordinates [ l ] ; } distance += ( centroidCoordinatePoint - centroidCoordinateCentre ) * ( centroidCoordinatePoint - centroidCoordinateCentre ) ; } if ( nearestCost < 0 || distance < nearestCost ) { nearestCost = distance ; } } return this . weight * nearestCost ; }
Computes the cost of this point with the given array of centres centres[] (of size k)