wow what a clusterfuck
166153
function(plugin, message, opt) {
  opt = opt || {};
  if (typeof plugin === 'object') {
    opt = plugin;
  } else {
    if (message instanceof Error) {
      opt.error = message;
    } else if (typeof message === 'object') {
      opt = message;
    } else {
      opt.message = message;
    }
    opt.plugin = plugin;
  }

  return objectAssign({
    showStack: false,
    showProperties: true
  }, opt);
}
1282509
void getClusterXY(int cluster, Point2D ptOut) {
		int vindex = getClusterVertexIndex(cluster);
		m_shape.getXYWithIndex(vindex, ptOut);
	}
145885
public synchronized void destroy() throws IOException {
    if (mState == State.DESTROYED) {
      return;
    }
    if (!mSuccess) {
      saveWorkdir();
    }
    mCloser.close();
    LOG.info("Destroyed cluster {}", mClusterName);
    mState = State.DESTROYED;
  }
530197
public double evaluateClusteringPerformance(Clustering clustering, Clustering trueClustering, ArrayList<DataPoint> points) throws Exception{
        long start = System.nanoTime();
        evaluateClustering(clustering, trueClustering, points);
        long duration = System.nanoTime()-start;
        time+=duration;
        duration/=10e5;
        return duration;
     }
1271194
function WTFAmazon (array) {
  var result = {};
  array.map(function (item) { result[item.Key] = item.Value; });
  return result;
}
1360989
final void rebalance() {
        // Let's start distribute the vbuckets across the servers
        configurationRwLock.writeLock().lock();
        try {
            Info.incrementConfigRevision();
            List<MemcachedServer> nodes = activeServers();
            for (int ii = 0; ii < numVBuckets; ++ii) {
                Collections.shuffle(nodes);
                vbInfo[ii].setOwner(nodes.get(0));
                if (nodes.size() < 2) {
                    continue;
                }
                List<MemcachedServer> replicas = nodes.subList(1, nodes.size());
                if (replicas.size() > numReplicas) {
                    replicas = replicas.subList(0, numReplicas);
                }
                vbInfo[ii].setReplicas(replicas);
            }
        } finally {
            Info.incrementConfigRevision();
            configurationRwLock.writeLock().unlock();
        }
    }
274780
function Cluster(mc) {
  this.markerClusterer_ = mc;
  this.map_ = mc.getMap();
  this.gridSize_ = mc.getGridSize();
  this.minClusterSize_ = mc.getMinimumClusterSize();
  this.averageCenter_ = mc.getAverageCenter();
  this.markers_ = [];
  this.center_ = null;
  this.bounds_ = null;
  this.clusterIcon_ = new ClusterIcon(this, mc.getStyles());
}
299763
def run
      return if _clusters.empty?
      warn "warning: running aggregation on many clusters (#{_clusters.size})" if _clusters.size > 100

      if DENSITY_BIAS_FACTOR
        @min_density, @max_density = _clusters.collect(&:density).minmax
      end

      # build the set of pairs (n²/2)
      pairs  = []
      source = _clusters.dup
      while left = source.pop
        source.each do |right| 
          pairs << _build_pair(left, right, _fence)
        end
      end

      # pop & merge
      while pairs.any?
        best_pair = pairs.min
        break if best_pair.distance > min_distance

        # remove the closest pair
        left, right = best_pair.values
        left_id  = left.id
        right_id = right.id

        # remove pairs containing one of the items
        pairs.delete_if { |p| p.has?(left) || p.has?(right) }

        # merge clusters
        left.merge(right)
        _clusters.delete_if { |c| c.id == right_id }
        _updated_clusters.remove right
        _dropped_clusters.add    right
        _updated_clusters.add    left

        # create new pairs
        _clusters.each do |cluster|
          next if cluster.id == left_id
          pairs << _build_pair(left, cluster, _fence)
        end
      end
      nil
    end
714745
@Override
  public Clustering<M> run(Database database, Relation<V> relation) {
    MutableProgress prog = LOG.isVerbose() ? new MutableProgress("X-means number of clusters", k_max, LOG) : null;

    // Run initial k-means to find at least k_min clusters
    innerKMeans.setK(k_min);
    LOG.statistics(new StringStatistic(KEY + ".initialization", initializer.toString()));
    splitInitializer.setInitialMeans(initializer.chooseInitialMeans(database, relation, k_min, getDistanceFunction()));
    Clustering<M> clustering = innerKMeans.run(database, relation);

    if(prog != null) {
      prog.setProcessed(k_min, LOG);
    }

    ArrayList<Cluster<M>> clusters = new ArrayList<>(clustering.getAllClusters());
    while(clusters.size() <= k_max) {
      // Improve-Structure:
      ArrayList<Cluster<M>> nextClusters = new ArrayList<>();
      for(Cluster<M> cluster : clusters) {
        // Try to split this cluster:
        List<Cluster<M>> childClusterList = splitCluster(cluster, database, relation);
        nextClusters.addAll(childClusterList);
        if(childClusterList.size() > 1) {
          k += childClusterList.size() - 1;
          if(prog != null) {
            if(k >= k_max) {
              prog.setTotal(k + 1);
            }
            prog.setProcessed(k, LOG);
          }
        }
      }
      if(clusters.size() == nextClusters.size()) {
        break;
      }
      // Improve-Params:
      splitInitializer.setInitialClusters(nextClusters);
      innerKMeans.setK(nextClusters.size());
      clustering = innerKMeans.run(database, relation);
      clusters.clear();
      clusters.addAll(clustering.getAllClusters());
    }

    // Ensure that the progress bar finished.
    if(prog != null) {
      prog.setTotal(k);
      prog.setProcessed(k, LOG);
    }
    return new Clustering<>("X-Means Result", "X-Means", clusters);
  }
874082
def cluster_forget(self, node_id):
        """"""
        fut = self.execute(b'CLUSTER', b'FORGET', node_id)
        return wait_ok(fut)
828584
public void sumUp() {
        int offset=0;
        int tmp=0;
        for (int i = 0; i < numChunks; i++) {
            int[] chunk = chunks[i];
            if (chunk==null) throw new IllegalStateException("Chunks are not continous, null fragement at offset "+i);
            for (int j = 0; j < chunkSize; j++) {
                tmp = chunk[j];
                chunk[j] = offset;
                offset += tmp;
            }
        }
    }
592952
def _regroup(self):
        
        # clean up old maps
        for j in range(self.nout):
            self.inv_map[j] = []

        # find smallest divergence between input component i
        # and output component j of the cluster mixture density
        for i in range(self.nin):
            self.min_kl[i] = np.inf
            j_min = None
            for j in range(self.nout):
                kl = kullback_leibler(self.f.components[i], self.g.components[j])
                if kl < self.min_kl[i]:
                    self.min_kl[i] = kl
                    j_min = j
            assert j_min is not None
            self.inv_map[j_min].append(i)
1319668
function() { 
        var l = this.children.length;
        for (var i=0;i<l;++i) {
            var c = this.children[i];
            if (c.isDynamic()) {
                break;
            } else if (! c.multiExpand) {
                break;
            } else {
                c.expand();
                c.expandAll();
            }
        }
    }
96025
@Override
	public void resetLearningImpl() {
		this.numClusters = this.numClustersOption.getValue();
		this.numDimensions = this.numDimensionsOption.getValue();
		this.maxNumClusterFeatures = this.maxNumClusterFeaturesOption.getValue();
		this.numProjections = this.numProjectionsOption.getValue();

		this.bufferPhase = true;
		this.buffer = new ArrayList<double[]>(
				this.maxNumClusterFeaturesOption.getValue() + 1);
		this.minDistance = Double.POSITIVE_INFINITY;
		this.pairwiseDifferent = 0;

		int hashSize = (int) Math.ceil(Math.log(
				5 * this.maxNumClusterFeaturesOption.getValue()) / Math.log(2));
		this.root = new ClusteringTreeHeadNode(null, new ClusteringFeature(
				new double[0], 1), this.numDimensionsOption.getValue(),
				this.numProjectionsOption.getValue(), Math.min(hashSize, 30),
				this.clustererRandom);
		this.rootCount = 0;
	}
274370
private void bfs(int[] membership, int cluster, int id) {
        int n = merge.length + 1;
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(cluster);

        for (Integer i = queue.poll(); i != null; i = queue.poll()) {
            if (i < n) {
                membership[i] = id;
                continue;
            }

            i -= n;

            int m1 = merge[i][0];

            if (m1 >= n) {
                queue.offer(m1);
            } else {
                membership[m1] = id;
            }

            int m2 = merge[i][1];

            if (m2 >= n) {
                queue.offer(m2);
            } else {
                membership[m2] = id;
            }
        }
    }
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());
}
875687
private void clusterDown(){
		int classIndex = this.ltm.classIndex();
		for (int c = 0; c <= this.maxClassValue; c++){
			List<double[]> classSamples = new ArrayList<>();
			for (int i = this.ltm.numInstances()-1; i >-1 ; i--) {
				if (this.ltm.get(i).classValue() == c) {
					classSamples.add(this.ltm.get(i).toDoubleArray());
					this.ltm.delete(i);
				}
			}
			if (classSamples.size() > 0) {
				//used kMeans++ implementation expects the weight of each sample at the first index,
				// make sure that the first value gets the uniform weight 1, overwrite class value
				for (double[] sample : classSamples) {
					if (classIndex != 0) {
						sample[classIndex] = sample[0];
					}
					sample[0] = 1;
				}

				List<double[]> centroids = this.kMeans(classSamples, Math.max(classSamples.size() / 2, 1));

				for (double[] centroid : centroids) {

					double[] attributes = new double[this.ltm.numAttributes()];
					//returned centroids do not contain the weight anymore, but simply the data
					System.arraycopy(centroid, 0, attributes, 1, this.ltm.numAttributes() - 1);
					//switch back if necessary
					if (classIndex != 0) {
						attributes[0] = attributes[classIndex];
					}
					attributes[classIndex] = c;
					Instance inst = new InstanceImpl(1, attributes);
					inst.setDataset(this.ltm);
					this.ltm.add(inst);
				}
			}

		}
	}