Sets the location of each cluster to the average location of all its members.
427291
protected void updateClusterCenters() {
		// compute the new centers of each cluster
		for (int i = 0; i < clusters.size; i++) {
			double mc = memberCount.get(i);
			double[] w = workClusters.get(i);
			double[] c = clusters.get(i);

			for (int j = 0; j < w.length; j++) {
				c[j] = w[j] / mc;
			}
		}
	}
462652
public void setClusterNodes(java.util.Collection<ClusterNode> clusterNodes) {
        if (clusterNodes == null) {
            this.clusterNodes = null;
            return;
        }

        this.clusterNodes = new com.amazonaws.internal.SdkInternalList<ClusterNode>(clusterNodes);
    }
893138
protected void initClusters() {
        log.info("Generating initial clusters");
        List<Point> points = new ArrayList<>(initialPoints);

        //Initialize the ClusterSet with a single cluster center (based on position of one of the points chosen randomly)
        val random = Nd4j.getRandom();
        Distance distanceFn = clusteringStrategy.getDistanceFunction();
        int initialClusterCount = clusteringStrategy.getInitialClusterCount();
        clusterSet = new ClusterSet(distanceFn,
                        clusteringStrategy.inverseDistanceCalculation(), new long[]{initialClusterCount, points.get(0).getArray().length()});
        clusterSet.addNewClusterWithCenter(points.remove(random.nextInt(points.size())));


        //dxs: distances between
        // each point and nearest cluster to that point
        INDArray dxs = Nd4j.create(points.size());
        dxs.addi(clusteringStrategy.inverseDistanceCalculation() ? -Double.MAX_VALUE : Double.MAX_VALUE);

        //Generate the initial cluster centers, by randomly selecting a point between 0 and max distance
        //Thus, we are more likely to select (as a new cluster center) a point that is far from an existing cluster
        while (clusterSet.getClusterCount() < initialClusterCount && !points.isEmpty()) {
            dxs = ClusterUtils.computeSquareDistancesFromNearestCluster(clusterSet, points, dxs, exec);
            double r = random.nextFloat() * dxs.maxNumber().doubleValue();
            for (int i = 0; i < dxs.length(); i++) {
                double distance = dxs.getDouble(i);
                Preconditions.checkState(distance >= 0, "Encountered negative distance: distance function is not valid? Distance " +
                        "function must return values >= 0, got distance %s for function s", distance, distanceFn);
                if (dxs.getDouble(i) >= r) {
                    clusterSet.addNewClusterWithCenter(points.remove(i));
                    dxs = Nd4j.create(ArrayUtils.remove(dxs.data().asDouble(), i));
                    break;
                }
            }
        }

        ClusterSetInfo initialClusterSetInfo = ClusterUtils.computeClusterSetInfo(clusterSet);
        iterationHistory.getIterationsInfos().put(currentIteration,
                        new IterationInfo(currentIteration, initialClusterSetInfo));
    }
86689
private void setMeanDistancesToCentroids() {
        meanDistancesToCentroids = new HashMap<>();
        for (int i = 0; i < clusterCentroids.numInstances(); i++) {    //For each centroid
            int countAssignedInstances = 0;
            double sumDistancesToCentroid = 0.0;
            Instance centroidInstance = clusterCentroids.instance(i);
            for (int j = 0; j < trainingData.numInstances(); j++) {       //For each data point
                 if (i == centroidAssignments[j]) {
                     Instance valueInstance = trainingData.instance(j);
                     double distanceToCentroid = Math.abs(valueInstance.value(0) -
                                                    centroidInstance.value(0));
                     sumDistancesToCentroid += distanceToCentroid;
                     countAssignedInstances++;
                 }
            }
            double meanDistanceToCentroid = sumDistancesToCentroid / countAssignedInstances;
            meanDistancesToCentroids.put(centroidInstance, meanDistanceToCentroid);
        }
    }
838076
def set_distributed_assembled(self, irn_loc, jcn_loc, a_loc):
        
        self.set_distributed_assembled_rows_cols(irn_loc, jcn_loc)
        self.set_distributed_assembled_values(a_loc)
1105152
public void merge(ClusteringFeature x) {
		assert (this.sumPoints.length == x.sumPoints.length);
		this.numPoints += x.numPoints;
		super.setWeight(this.numPoints);
		for (int i = 0; i < this.sumPoints.length; i++) {
			this.sumPoints[i] += x.sumPoints[i];
		}
		this.sumSquaredLength += x.sumSquaredLength;
	}
1343327
function cluster(points) {
    // number of clusters has to be smaller or equal the number of data points
    if (points.length < k) {
      throw 'Too many clusters';
    }

    // create the initial clusters
    var clusters = chooseInitialCenters(points);

    // create an array containing the latest assignment of a point to a cluster
    // no need to initialize the array, as it will be filled with the first assignment
    var assignments = new Int32Array(points.length);
    assignPointsToClusters(clusters, points, assignments);
    // iterate through updating the centers until we're done
    var max = (maxIterations < 0) ? Number.MAX_VALUE : maxIterations;
    for (var count = 0; count < max; count++) {
      var emptyCluster = false;
      var newClusters = [];
      for (var clusterIndex = 0; clusterIndex < clusters.length; clusterIndex++) {
        var cluster = clusters[clusterIndex];
        var newCenter;
        if (cluster.getPoints().length === 0) {
          newCenter = getPointFromLargestVarianceCluster(clusters);
          emptyCluster = true;
        } else {
          newCenter = centroidOf(cluster.getPoints(), cluster.getCenter().getPoint().size());
        }
        newClusters.push(new CentroidCluster(newCenter));
      }
      var changes = assignPointsToClusters(newClusters, points, assignments);
      clusters = newClusters;

      // if there were no more changes in the point-to-cluster assignment
      // and there are no empty clusters left, return the current clusters
      if (changes === 0 && !emptyCluster) {
        return clusters;
      }
    }
    return clusters;
  }
595879
private void setLocation(List<Step> steps) {
		List<Location> sublocations = new ArrayList<Location>();
		int start = 0, step = 0, oStep = numBefore+numAfter, oMax = this.original.getLength(), pStep = 0, pMax =
				(prev == null) ? 0 : prev.getLength();
		boolean inGap = true;

		// build sublocations: pieces of sequence separated by gaps
		for (; step < length; step++) {
			boolean isGapStep = (steps.get(step) == Step.GAP),
					isGapPrev = (pStep < pMax && prev.isGap(pStep + 1));
			if (!isGapStep && !isGapPrev) {
				oStep++;
				if (inGap) {
					inGap = false;
					start = step + 1;
				}
			} else if (!inGap) {
				inGap = true;
				sublocations.add(new SimpleLocation(start, step, Strand.UNDEFINED));
			}
			if (prev != null && !isGapStep) {
				pStep++;
			}
		}
		if (!inGap) {
			sublocations.add(new SimpleLocation(start, step, Strand.UNDEFINED));
		}

		// combine sublocations into 1 Location
		if (sublocations.size() == 0) {
			location = null;
		} else if (sublocations.size() == 1) {
			location = sublocations.get(0);
		} else {
			location = new SimpleLocation(sublocations.get(0).getStart(), sublocations.get(sublocations.size() - 1).getEnd(),
					Strand.UNDEFINED,
					false, sublocations);
		}
		// TODO handle circular alignments

		// check that alignment has correct number of compounds in it to fit original sequence
		if (step != length || oStep != oMax || pStep != pMax) {
			throw new IllegalArgumentException("Given sequence does not fit in alignment.");
		}
	}
335535
def move_point_num(point, to_clust, from_clust, cl_attr_sum, cl_memb_sum):
    """"""
    # Update sum of attributes in cluster.
    for iattr, curattr in enumerate(point):
        cl_attr_sum[to_clust][iattr] += curattr
        cl_attr_sum[from_clust][iattr] -= curattr
    # Update sums of memberships in cluster
    cl_memb_sum[to_clust] += 1
    cl_memb_sum[from_clust] -= 1
    return cl_attr_sum, cl_memb_sum
1068564
function Cluster(markerClusterer) {
  this.markerClusterer_ = markerClusterer;
  this.map_ = markerClusterer.getMap();
  this.gridSize_ = markerClusterer.getGridSize();
  this.minClusterSize_ = markerClusterer.getMinClusterSize();
  this.averageCenter_ = markerClusterer.isAverageCenter();
  this.center_ = null;
  this.markers_ = [];
  this.bounds_ = null;
  this.clusterIcon_ = new ClusterIcon(this, markerClusterer.getStyles(),
      markerClusterer.getGridSize());
}
159543
def set_base_location(self, location):
        """"""
        self.base_location = location
        self._utm_zone = location.zone
        self._utm_datum = location.datum
        self._utm_convergence = location.convergence
3196
private void setCurrentLocationToNextValidPosition(Point aLocation)    {
        // set latest location to next valid position
        int i, j;
        i = aLocation.x;
        j = aLocation.y;
        do {
            if ( (j + 1)  == columns ) {    // goto next row
                i++;
                j = 0;
            }
            else {
                j++;
            }
        }
        while (
        (i < rows.size()) && (j < columns) && (((Row) rows.get(i)).isReserved(j))
        );
        curPosition = new Point(i, j);
    }
134611
public void setCacheClusters(java.util.Collection<CacheCluster> cacheClusters) {
        if (cacheClusters == null) {
            this.cacheClusters = null;
            return;
        }

        this.cacheClusters = new com.amazonaws.internal.SdkInternalList<CacheCluster>(cacheClusters);
    }
49849
public void setChainLength(int nrClusters) throws IOException {
        if (nrClusters < 0) throw new IllegalArgumentException(
                "negative cluster count"); //NOI18N
                
        if ((this.startCluster == 0) && (nrClusters == 0)) {
            /* nothing to do */
        } else if ((this.startCluster == 0) && (nrClusters > 0)) {
            final long[] chain = fat.allocNew(nrClusters);
            this.startCluster = chain[0];
        } else {
            final long[] chain = fat.getChain(startCluster);
            
            if (nrClusters != chain.length) {
                if (nrClusters > chain.length) {
                    /* grow the chain */
                    int count = nrClusters - chain.length;
                    
                    while (count > 0) {
                        fat.allocAppend(getStartCluster());
                        count--;
                    }
                } else {
                    /* shrink the chain */
                    if (nrClusters > 0) {
                        fat.setEof(chain[nrClusters - 1]);
                        for (int i = nrClusters; i < chain.length; i++) {
                            fat.setFree(chain[i]);
                        }
                    } else {
                        for (int i=0; i < chain.length; i++) {
                            fat.setFree(chain[i]);
                        }
                        
                        this.startCluster = 0;
                    }
                }
            }
        }
    }
1311401
public void setClusterStates(java.util.Collection<String> clusterStates) {
        if (clusterStates == null) {
            this.clusterStates = null;
            return;
        }

        this.clusterStates = new com.amazonaws.internal.SdkInternalList<String>(clusterStates);
    }
652385
public void setClusterDbRevisions(java.util.Collection<ClusterDbRevision> clusterDbRevisions) {
        if (clusterDbRevisions == null) {
            this.clusterDbRevisions = null;
            return;
        }

        this.clusterDbRevisions = new com.amazonaws.internal.SdkInternalList<ClusterDbRevision>(clusterDbRevisions);
    }
570637
def distance(cluster, method = 0)
      d = 0
      norm = 0

      cluster.lengths.each do |elem1|
        lengths.each do |elem2|
          if method == 1
            d += elem1[1] * elem2[1] * (elem1[0] - elem2[0]).abs
            norm += elem1[1] * elem2[1]
          else
            d += (elem1[0] - elem2[0]).abs
            norm = cluster.lengths.length * lengths.length
          end
        end
      end

      # group average distance
      d /= (norm + 0.0)
      d.round(4)
    end