获取词聚类特征
@param data 输入数据
@param cluster4
@param cluster6
@param cluster
181159
void get_cluster_from_dependency(final Dependency data,
                                     List<Integer> cluster4,
                                     List<Integer> cluster6,
                                     List<Integer> cluster)
    {
        if (use_cluster)
        {
            int L = data.forms.size();
            for (int i = 0; i < L; ++i)
            {
                int form = data.forms.get(i);
                cluster4.add(i == 0 ?
                                     cluster4_types_alphabet.idOf(SpecialOption.ROOT) : form_to_cluster4.get(form));
                cluster6.add(i == 0 ?
                                     cluster6_types_alphabet.idOf(SpecialOption.ROOT) : form_to_cluster6.get(form));
                cluster.add(i == 0 ?
                                    cluster_types_alphabet.idOf(SpecialOption.ROOT) : form_to_cluster.get(form));
            }
        }
    }
1200842
public <E extends Edge> MultiMap<Integer,Integer> cluster(
                      final Graph<E> graph, int numClusters, Properties props) {
        return singleLink(graph, numClusters);
        // throw new Error();
    }
951069
private static byte[] sha256(byte[] data) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance(ALGORITHM_SHA256);
			md.reset();
			md.update(data);
			return md.digest();
		} catch (Exception e) {
			LogUtil.writeErrorLog("SHA256计算失败", e);
			return null;
		}
	}
1368172
@Override
    protected List<Row> rows(List<SearchResult> searchResults, long timestamp, boolean usesRelevance) {
        // Initialize result
        List<Row> rows = new ArrayList<>(searchResults.size());

        // Group key queries by partition keys
        Map<CellName, Float> scoresByClusteringKey = new HashMap<>(searchResults.size());
        Map<DecoratedKey, List<CellName>> keys = new HashMap<>();
        for (SearchResult searchResult : searchResults) {
            DecoratedKey partitionKey = searchResult.getPartitionKey();
            CellName clusteringKey = searchResult.getClusteringKey();
            Float score = searchResult.getScore();
            scoresByClusteringKey.put(clusteringKey, score);
            List<CellName> clusteringKeys = keys.get(partitionKey);
            if (clusteringKeys == null) {
                clusteringKeys = new ArrayList<>();
                keys.put(partitionKey, clusteringKeys);
            }
            clusteringKeys.add(clusteringKey);
        }

        for (Map.Entry<DecoratedKey, List<CellName>> entry : keys.entrySet()) {
            DecoratedKey partitionKey = entry.getKey();
            for (List<CellName> clusteringKeys : Lists.partition(entry.getValue(), 1000)) {
                Map<CellName, Row> partitionRows = rows(partitionKey, clusteringKeys, timestamp);
                for (Map.Entry<CellName, Row> entry1 : partitionRows.entrySet()) {
                    Row row = entry1.getValue();
                    if (usesRelevance) {
                        CellName clusteringKey = entry1.getKey();
                        Float score = scoresByClusteringKey.get(clusteringKey);
                        Row scoredRow = addScoreColumn(row, timestamp, score);
                        rows.add(scoredRow);
                    } else {
                        rows.add(row);
                    }
                }
            }
        }
        return rows;
    }
195910
function Cluster(data) {
  var self = this;
  self.data = data;

  if (cluster.isMaster) {
    if (data.pid) {
      fs.writeFileSync(data.pid, process.pid);
    }
    let numCPUs = 1;
    if (data.count) {
      numCPUs = data.count;
    } else {
      numCPUs = require('os').cpus().length;
    }

    self.debug.log('Starting up %s workers.', numCPUs);
    for (var i = 0; i < numCPUs; i++) {
      cluster.fork();
    }

    cluster.on('online', function(worker) {
      self.debug.log('Worker %s is online', worker.process.pid);
    });

    cluster.on('exit', function(worker, code, signal) {
      self.debug.log('Worker %s died. code %s signal %s', worker.process.pid, code, signal);
      self.debug.log('Starting a new worker');
      cluster.fork();
    });

    cluster.on('listening', function(worker, address) {
      if (self.data.callbacks['init']) {
        self.data.callbacks['init'](cluster, worker, address);
      }
    });

    process.on('SIGINT', function() {
      self.debug.log('Caught interrupt signal');
      if (data.pid) {
        fs.unlinkSync(data.pid);
      }
      process.exit();
    });
  } else {
    var webServer = new WebHttp(self.data);

    process.on('SIGINT', function() {
      self.debug.worker('Caught interrupt signal');
      webServer.stop();
    });

    process.on('SIGTERM', function() {
        self.debug.worker('Caught termination signal');
        webServer.stop();
      }
    );
  }
  return cluster;
}
412917
public void setClusters(java.util.Collection<String> clusters) {
        if (clusters == null) {
            this.clusters = null;
            return;
        }

        this.clusters = new java.util.ArrayList<String>(clusters);
    }
1207040
public void markClustered(boolean clustered) {
        Map<StorableIndex<S>, StorableIndex<S>> replacements = null;
        for (StorableIndex<S> index : this) {
            StorableIndex<S> replacement = index.clustered(clustered);
            if (replacement != index) {
                if (replacements == null) {
                    replacements = new HashMap<StorableIndex<S>, StorableIndex<S>>();
                }
                replacements.put(index, replacement);
            }
        }
        replaceEntries(replacements);
    }
699998
private void clusterTerm(String senseName,
                             List<SparseDoubleVector> contextSet,
                             Properties props) {
        // Convert the data points to a sparse matrix.
        SparseMatrix contexts = Matrices.asSparseMatrix(contextSet);

        // Cluster the context set.
        LOG.info("Clustering term: " + senseName);
        Assignments assignments = (numClusters > 0) 
            ? clustering.cluster(contexts, numClusters, props)
            : clustering.cluster(contexts, props);
        LOG.info("Finished clustering term: " + senseName);

        SparseDoubleVector[] centroids = assignments.getSparseCentroids();

        // Add the centroids to the splitSenses map.
        for (int index = 0; index < centroids.length; ++index) {
            String sense = (index > 0)
                    ? senseName + "-" + index
                    : senseName;
            wordSpace.put(sense, centroids[index]);
        }

        LOG.info("Finished creating centroids for term: " + senseName);

        // Empty out the stored contexts to free up memory for later processes.
        contextSet.clear();

        // If the reporter is null, avoid making any report.
        if (reporter == null)
            return;

        // Generate the secondary context labels for each data point.
        String[] contextLabels = reporter.contextLabels(senseName);
        if (contextLabels.length == 0)
            return;

        LOG.info("Making assignment report: " + senseName);
        // Report the assignments for each clustered data point.  Note that some
        // data points might not have been clustered (Cluto based clustering
        // does this on occasion) so we must check for the number of assignments
        // first.
        for (int i = 0; i < assignments.size(); ++i)
            if (assignments.get(i).assignments().length > 0)
                reporter.updateAssignment(senseName, contextLabels[i],
                                          assignments.get(i).assignments()[0]);
        LOG.info("Finished making assignment report: " + senseName);
    }
922449
public void write(byte[] data) {
        for(int i=0;i<data.length;i++) {
            writeByte(data[i]);
        }
    }
477779
function (clusterTimeout) {
        if (clusterUrl != null) {
            getServerFromCluster({
                clusterUri : clusterUrl, 
                clusterTimeout : clusterTimeout,
                appKey : ortc.appKey
            }, 
            function (error, body) {
                if (error != null) {
                    delegateExceptionCallback(ortc, 'Error getting server from Cluster');
                }
                else {
                    if (body.indexOf('SOCKET_SERVER') >= 0) {
                        url = body.substring(body.indexOf('=') + 3, body.length - 2);
                        sockjs = createSocketConnection(ortc.getUrl());
                    }
                }
            });
        }
    }
117828
public Cluster setCluster(Cluster newCluster) {
        // 开始切换
        Cluster old = this.cluster;
        this.cluster = newCluster;
        return old;
    }
798220
public ClusteringModelPrediction predictClustering(RowData data) throws PredictException {
    ClusteringModelPrediction p = new ClusteringModelPrediction();
    if (useExtendedOutput && (m instanceof IClusteringModel)) {
      IClusteringModel cm = (IClusteringModel) m;
      // setup raw input
      double[] rawData = nanArray(m.nfeatures());
      rawData = fillRawData(data, rawData);
      // get cluster assignment & distances
      final int k = cm.getNumClusters();
      p.distances = new double[k];
      p.cluster = cm.distances(rawData, p.distances);
    } else {
      double[] preds = preamble(ModelCategory.Clustering, data);
      p.cluster = (int) preds[0];
    }

    return p;
  }
521560
public static ClusterSetInfo classifyPoints(final ClusterSet clusterSet, List<Point> points,
                    ExecutorService executorService) {
        final ClusterSetInfo clusterSetInfo = ClusterSetInfo.initialize(clusterSet, true);

        List<Runnable> tasks = new ArrayList<>();
        for (final Point point : points) {
            //tasks.add(new Runnable() {
              //  public void run() {
                    try {
                        PointClassification result = classifyPoint(clusterSet, point);
                        if (result.isNewLocation())
                            clusterSetInfo.getPointLocationChange().incrementAndGet();
                        clusterSetInfo.getClusterInfo(result.getCluster().getId()).getPointDistancesFromCenter()
                                        .put(point.getId(), result.getDistanceFromCenter());
                    } catch (Throwable t) {
                        log.warn("Error classifying point", t);
                    }
            //    }
            }

        //MultiThreadUtils.parallelTasks(tasks, executorService);
        return clusterSetInfo;
    }
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());
}
26740
public static int numPoints(Clustering<? extends MeanModel> clustering) {
    int n = 0;
    for(Cluster<? extends MeanModel> aCluster : clustering.getAllClusters()) {
      n += aCluster.size();
    }
    return n;
  }
999198
protected void processCluster( List<SquareNode> cluster ) {
		invalid = false;
		// handle a special case
		if( cluster.size() == 1 ) {
			SquareNode n = cluster.get(0);
			if( n.getNumberOfConnections() == 0 ) {
				SquareGrid grid = grids.grow();
				grid.reset();
				grid.columns = grid.rows = 1;
				grid.nodes.add(n);
				return;
			}
		}

		for (int i = 0; i < cluster.size(); i++) {
			cluster.get(i).graph = SquareNode.RESET_GRAPH;
		}

		SquareNode seed = findSeedNode(cluster);

		if( seed == null )
			return;

		// find the first row
		List<SquareNode> firstRow;
		if( seed.getNumberOfConnections() == 1 ) {
			firstRow = firstRow1(seed);
		} else if( seed.getNumberOfConnections() == 2 ) {
			firstRow = firstRow2(seed);
		} else {
			throw new RuntimeException("BUG");
		}
		if( invalid || firstRow == null )
			return;

		// Add the next rows to the list, one after another
		List<List<SquareNode>> listRows = new ArrayList<>();// TODO remove memory declaration here
		listRows.add(firstRow);
		while(true ) {
			List<SquareNode> previous = listRows.get(listRows.size()-1);
			if( !addNextRow(previous.get(0),listRows)) {
				break;
			}
		}

		if( invalid || listRows.size() < 2)
			return;

		// re-organize into a grid data structure
		SquareGrid grid = assembleGrid(listRows);

		// check the grids connectivity
		if( grid == null || !checkEdgeCount(grid) ) {
			grids.removeTail();
		}
	}
904997
public long allocAppend(long cluster)
            throws IOException {
        
        testCluster(cluster);
        
        while (!isEofCluster(entries[(int) cluster])) {
            cluster = entries[(int) cluster];
        }
        
        long newCluster = allocNew();
        entries[(int) cluster] = newCluster;

        return newCluster;
    }