Calculate the SSE to the cluster center
190548
def _cal_dist2center(X, center):
    
    dmemb2cen = scipy.spatial.distance.cdist(X, center.reshape(1,X.shape[1]), metric='seuclidean')
    return(np.sum(dmemb2cen))
1295305
public static double initialCenter(DenseMatrix64F points, DenseMatrix64F center)
    {
        assert points.numCols == 2;
        assert center.numCols == 1;
        assert center.numRows == 2;
        center.zero();
        int count = 0;
        int len1 = points.numRows;
        int len2 = len1-1;
        int len3 = len2-1;
        for (int i=0;i<len3;i++)
        {
            for (int j=i+1;j<len2;j++)
            {
                for (int k=j+1;k<len1;k++)
                {
                    if (center(points, i, j, k, center))
                    {
                        count++;
                    }
                }
            }
        }
        if (count > 0)
        {
            divide(center, count);
            DenseMatrix64F di = new DenseMatrix64F(points.numRows, 1);
            computeDi(center, points, di);
            return elementSum(di) / (double)points.numRows;
        }
        else
        {
            return Double.NaN;
        }
    }
728607
def sse(mean, estimator):
    
    return np.sum((np.asarray(estimator) - np.asarray(mean)) ** 2, axis=0)
449585
def centerLatLon(self):
        
        # GET CENTROID FROM GSSHA GRID
        gssha_grid = self.getGrid()

        min_x, max_x, min_y, max_y = gssha_grid.bounds()
        x_ext, y_ext = transform(gssha_grid.proj,
                                 Proj(init='epsg:4326'),
                                 [min_x, max_x, min_x, max_x],
                                 [min_y, max_y, max_y, min_y],
                                 )
        return np.mean(y_ext), np.mean(x_ext)
659623
public static int nvgraphAnalyzeClustering(
        nvgraphHandle handle, 
        nvgraphGraphDescr graph_descr, 
        long weight_index, 
        int n_clusters, 
        Pointer clustering, 
        int metric, 
        Pointer score)
    {
        return checkResult(nvgraphAnalyzeClusteringNative(handle, graph_descr, weight_index, n_clusters, clustering, metric, score));
    }
666113
protected double computeMseR() {
        double p_c;
        double mse_r = 0;

        for (int i = 0; i < this.classDistributions.length; i++) {
            p_c = (double) this.classDistributions[i] / (double) this.chunkSize;
            mse_r += p_c * ((1 - p_c) * (1 - p_c));
        }

        return mse_r;
    }
1016684
private void exteriorAreaInteriorPoint_(int cluster, int id_a) {
		if (m_matrix[MatrixPredicate.ExteriorInterior] == 0)
			return;

		int clusterParentage = m_topo_graph.getClusterParentage(cluster);

		if ((clusterParentage & id_a) == 0) {
			int chain = m_topo_graph.getClusterChain(cluster);
			int chainParentage = m_topo_graph.getChainParentage(chain);

			if ((chainParentage & id_a) == 0) {
				m_matrix[MatrixPredicate.ExteriorInterior] = 0;
			}
		}
	}
610011
def getCenter(self):
        
        return Location(self.x+(self.w/2), self.y+(self.h/2))
1259067
def get_center(self):
        """"""

        lr_x, lr_y = self.get_vec_lr()
        tb_x, tb_y = self.get_vec_tb()

        center_x = self.x + (lr_x + tb_x) / 2.0
        center_y = self.y + (lr_y + tb_y) / 2.0

        return center_x, center_y
611351
def cluster_assignments(self):
        
        array = javabridge.call(self.jobject, "getClusterAssignments", "()[D")
        if array is None:
            return None
        else:
            return javabridge.get_env().get_double_array_elements(array)
154517
void updateClusterXY(int cluster, Point2D pt) {
		int vertexList = getClusterVertices(cluster);
		for (int vh = m_cluster_vertices.getFirst(vertexList); vh != -1; vh = m_cluster_vertices
				.getNext(vh)) {
			int vertex = m_cluster_vertices.getElement(vh);
			m_shape.setXY(vertex, pt);
		}
	}
9275
private float calculateClusterQuality (ArrayList<Instance> docs,
			HashSparseVector centroid) {
		float quality = 0.0f;
		HashSparseVector c = centroid;

		for (int i = 0; i < docs.size(); ++i) {
			Instance doc = docs.get(i);

			quality += c.distanceEuclidean((HashSparseVector) doc.getData());
		}

		return quality;
	}
595943
protected void computeMseR() {
		double p_c;
		this.mse_r = 0;

		for (int i = 0; i < this.classDistributions.length; i++) {
			p_c = (double) this.classDistributions[i] / (double) this.windowSize;
			this.mse_r += p_c * ((1 - p_c) * (1 - p_c));
		}
	}
1231533
def _kmeans(X, n_clusters, max_iter, n_trials, tol):
    
    n_samples, n_features = X.shape[0], X.shape[1]

    centers_best = np.empty(shape=(n_clusters,n_features), dtype=float)
    labels_best  = np.empty(shape=n_samples, dtype=int)
    for i in range(n_trials):
        centers, labels, sse_tot, sse_arr, n_iter  = _kmeans_run(X, n_clusters, max_iter, tol)
        if i==0:
            sse_tot_best = sse_tot
            sse_arr_best = sse_arr
            n_iter_best = n_iter
            centers_best = centers.copy()
            labels_best  = labels.copy()
        if sse_tot < sse_tot_best:
            sse_tot_best = sse_tot
            sse_arr_best = sse_arr
            n_iter_best = n_iter
            centers_best = centers.copy()
            labels_best  = labels.copy()

    return(centers_best, labels_best, sse_arr_best, n_iter_best)
1307439
def init_centers_widths(self, R):
        

        kmeans = KMeans(
            init='k-means++',
            n_clusters=self.K,
            n_init=10,
            random_state=100)
        kmeans.fit(R)
        centers = kmeans.cluster_centers_
        widths = self._get_max_sigma(R) * np.ones((self.K, 1))
        return centers, widths
3265
def _calculate_cluster_distance(end_iter):
    
    out = []
    sizes = []
    for x in end_iter:
        out.append(x)
        sizes.append(x.end1 - x.start1)
        sizes.append(x.end2 - x.start2)
    distance = sum(sizes) // len(sizes)
    return distance, out
832642
def compute_center_of_mass(self, filename):
        
        sens = np.loadtxt(filename, skiprows=1)

        X = sens[:, 0]
        Z = sens[:, 1]
        # C = (np.abs(sens[:,2]))# ./ np.max(np.abs(sens[:,2]))
        C = sens[:, 2]

        x_center = 0
        z_center = 0
        sens_sum = 0

        for i in range(0, C.shape[0]):
            # unweighted
            if(self.weight == 0):
                weight = (C[i])
            # abs
            if(self.weight == 1):
                weight = np.abs(C[i])
            # log10
            if(self.weight == 2):
                weight = np.log10(np.abs(C[i]))
            # sqrt
            if(self.weight == 3):
                weight = np.sqrt(np.abs(C[i]))

            x_center += (X[i] * weight)
            z_center += (Z[i] * weight)
            sens_sum += weight
        x_center /= sens_sum
        z_center /= sens_sum

        return (x_center, z_center)