Return the ids of all spikes belonging to the specified clusters.
165520
def _spikes_in_clusters(spike_clusters, clusters):
    """"""
    if len(spike_clusters) == 0 or len(clusters) == 0:
        return np.array([], dtype=np.int)
    return np.nonzero(np.in1d(spike_clusters, clusters))[0]
1165392
def getclusters(self, count):
        

        # only proceed if we got sensible input
        if count <= 1:
            raise ClusteringError("When clustering, you need to ask for at "
                                  "least two clusters! "
                                  "You asked for %d" % count)

        # return the data straight away if there is nothing to cluster
        if (self.__data == [] or len(self.__data) == 1 or
                count == self.__initial_length):
            return self.__data

        # It makes no sense to ask for more clusters than data-items available
        if count > self.__initial_length:
            raise ClusteringError(
                "Unable to generate more clusters than "
                "items available. You supplied %d items, and asked for "
                "%d clusters." % (self.__initial_length, count))

        self.initialise_clusters(self.__data, count)

        items_moved = True  # tells us if any item moved between the clusters,
                            # as we initialised the clusters, we assume that
                            # is the case

        while items_moved is True:
            items_moved = False
            for cluster in self.__clusters:
                for item in cluster:
                    res = self.assign_item(item, cluster)
                    if items_moved is False:
                        items_moved = res
        return self.__clusters
390616
private List<Pair<Subspace, ModifiableDBIDs>> determineClusters(List<CLIQUESubspace> denseSubspaces) {
    List<Pair<Subspace, ModifiableDBIDs>> clusters = new ArrayList<>();

    for(CLIQUESubspace subspace : denseSubspaces) {
      List<Pair<Subspace, ModifiableDBIDs>> clustersInSubspace = subspace.determineClusters();
      if(LOG.isDebugging()) {
        LOG.debugFine("Subspace " + subspace + " clusters " + clustersInSubspace.size());
      }
      clusters.addAll(clustersInSubspace);
    }
    return clusters;
  }
86169
def split(self, spike_ids=None, spike_clusters_rel=0):
        """"""
        if spike_ids is None:
            spike_ids = self.emit('request_split', single=True)
            spike_ids = np.asarray(spike_ids, dtype=np.int64)
            assert spike_ids.dtype == np.int64
            assert spike_ids.ndim == 1
        if len(spike_ids) == 0:
            msg = ("You first need to select spikes in the feature "
                   "view with a few Ctrl+Click around the spikes "
                   "that you want to split.")
            self.emit('error', msg)
            return
        self.clustering.split(spike_ids,
                              spike_clusters_rel=spike_clusters_rel)
        self._global_history.action(self.clustering)
421289
public List<Cluster<M>> getAllClusters() {
    ArrayList<Cluster<M>> res = new ArrayList<>(hierarchy.size());
    for(It<Cluster<M>> iter = hierarchy.iterAll(); iter.valid(); iter.advance()) {
      res.add(iter.get());
    }
    Collections.sort(res, Cluster.BY_NAME_SORTER);
    return res;
  }
748975
private ArrayList<String[]> findCluster(Cluster cluster, double cutDist, int minPatternPerCls) {

    ArrayList<String[]> clusterTSIdx = new ArrayList<String[]>();

    if (cluster.getDistance() != null) {
      // if (cluster.getDistance() > cutDist) {
      if (cluster.getDistanceValue() > cutDist) {
        if (cluster.getChildren().size() > 0) {
          clusterTSIdx.addAll(findCluster(cluster.getChildren().get(0), cutDist, minPatternPerCls));
          clusterTSIdx.addAll(findCluster(cluster.getChildren().get(1), cutDist, minPatternPerCls));
        }
      }
      else {
        // String[] idxes = cluster.getName().split("&");
        ArrayList<String> itemsInCluster = getNameInCluster(cluster);
        String[] idxes = itemsInCluster.toArray(new String[itemsInCluster.size()]);
        if (idxes.length > minPatternPerCls) {
          clusterTSIdx.add(idxes);
        }
      }
    }

    return clusterTSIdx;
  }
979688
function collectNodeIds(stmt) {
  var ids = {},
      stack = [],
      curr;

  var push = stack.push.bind(stack);

  push(stmt);
  while(stack.length) {
    curr = stack.pop();
    switch(curr.type) {
      case "node": ids[curr.id] = true; break;
      case "edge": _.each(curr.elems, push); break;
      case "subgraph": _.each(curr.stmts, push); break;
    }
  }

  return _.keys(ids);
}
349401
public List<Set<Integer>> clusters() {
        List<Set<Integer>> clusters = new ArrayList<Set<Integer>>();
        for (int c = 0; c < numClusters; ++c)
            clusters.add(new HashSet<Integer>());
        for (int i = 0; i < assignments.length; ++i)
            for (int k : assignments[i].assignments()) {
                // Check that the item was place in a cluster
                if (k >= 0)
                    clusters.get(k).add(i);
            }
        return clusters;
    }
641275
def _kmedoids_run(X, n_clusters, distance, max_iter, tol, rng):
    
    membs = np.empty(shape=X.shape[0], dtype=int)
    centers = kmeans._kmeans_init(X, n_clusters, method='', rng=rng)

    sse_last = 9999.9
    n_iter = 0
    for it in range(1,max_iter):
        membs = kmeans._assign_clusters(X, centers)
        centers,sse_arr = _update_centers(X, membs, n_clusters, distance)
        sse_total = np.sum(sse_arr)
        if np.abs(sse_total - sse_last) < tol:
            n_iter = it
            break
        sse_last = sse_total

    return(centers, membs, sse_total, sse_arr, n_iter)
555439
def save(self):
        """"""
        spike_clusters = self.clustering.spike_clusters
        groups = {c: self.cluster_meta.get('group', c) or 'unsorted'
                  for c in self.clustering.cluster_ids}
        # List of tuples (field_name, dictionary).
        labels = [(field, self.get_labels(field))
                  for field in self.cluster_meta.fields
                  if field not in ('next_cluster')]
        # TODO: add option in add_field to declare a field unsavable.
        self.emit('request_save', spike_clusters, groups, *labels)
        # Cache the spikes_per_cluster array.
        self._save_spikes_per_cluster()
1107341
def undo(self):
        
        _, _, undo_state = self._undo_stack.back()

        # Retrieve the initial spike_cluster structure.
        spike_clusters_new = self._spike_clusters_base.copy()

        # Loop over the history (except the last item because we undo).
        for spike_ids, cluster_ids, _ in self._undo_stack:
            # We update the spike clusters accordingly.
            if spike_ids is not None:
                spike_clusters_new[spike_ids] = cluster_ids

        # What are the spikes affected by the last changes?
        changed = np.nonzero(self._spike_clusters !=
                             spike_clusters_new)[0]
        clusters_changed = spike_clusters_new[changed]

        up = self._do_assign(changed, clusters_changed)
        up.history = 'undo'
        # Add the undo_state object from the undone object.
        up.undo_state = undo_state

        self.emit('cluster', up)
        return up
715663
def list_clusters(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The list_clusters function must be called with '
            '-f or --function.'
        )

    return {'Clusters': salt.utils.vmware.list_clusters(_get_si())}
150931
def select_spikes(cluster_ids=None,
                  max_n_spikes_per_cluster=None,
                  spikes_per_cluster=None,
                  batch_size=None,
                  subset=None,
                  ):
    """"""
    subset = subset or 'regular'
    assert _is_array_like(cluster_ids)
    if not len(cluster_ids):
        return np.array([], dtype=np.int64)
    if max_n_spikes_per_cluster in (None, 0):
        selection = {c: spikes_per_cluster(c) for c in cluster_ids}
    else:
        assert max_n_spikes_per_cluster > 0
        selection = {}
        n_clusters = len(cluster_ids)
        for cluster in cluster_ids:
            # Decrease the number of spikes per cluster when there
            # are more clusters.
            n = int(max_n_spikes_per_cluster * exp(-.1 * (n_clusters - 1)))
            n = max(1, n)
            spike_ids = spikes_per_cluster(cluster)
            if subset == 'regular':
                # Regular subselection.
                if batch_size is None or len(spike_ids) <= max(batch_size, n):
                    spike_ids = regular_subset(spike_ids, n_spikes_max=n)
                else:
                    # Batch selections of spikes.
                    spike_ids = get_excerpts(spike_ids,
                                             n // batch_size,
                                             batch_size)
            elif subset == 'random' and len(spike_ids) > n:
                # Random subselection.
                spike_ids = np.random.choice(spike_ids, n, replace=False)
                spike_ids = np.unique(spike_ids)
            selection[cluster] = spike_ids
    return _flatten_per_cluster(selection)
787269
private ArrayList<String> getNameInCluster(Cluster cluster) {
    ArrayList<String> itemsInCluster = new ArrayList<String>();

    String nodeName;
    if (cluster.isLeaf()) {
      nodeName = cluster.getName();
      itemsInCluster.add(nodeName);
    }
    else {
      // String[] clusterName = cluster.getName().split("#");
      // nodeName = clusterName[1];
    }

    for (Cluster child : cluster.getChildren()) {
      ArrayList<String> childrenNames = getNameInCluster(child);
      itemsInCluster.addAll(childrenNames);
    }
    return itemsInCluster;
  }
530765
def get_resources(self, ids, cache=True):
        
        cluster_resources = {}
        for i in ids:
            _, ident = i.rsplit(':', 1)
            parts = ident.split('/', 2)
            if len(parts) != 3:
                raise PolicyExecutionError("New format ecs arn required")
            cluster_resources.setdefault(parts[1], []).append(parts[2])

        results = []
        client = local_session(self.manager.session_factory).client('ecs')
        for cid, resource_ids in cluster_resources.items():
            results.extend(
                self.process_cluster_resources(client, cid, resource_ids))
        return results
934471
def bin_spikes(spike_times, binsz):
    
    bins = np.empty((len(spike_times),), dtype=int)
    for i, stime in enumerate(spike_times):
        # around to fix rounding errors
        bins[i] = np.floor(np.around(stime/binsz, 5))
    return bins
1160792
def read_clusters(self, min_cluster_size):
        """"""
        num_found = 0
        clusters = []
        with open(self.get_path(OslomRunner.OUTPUT_FILE), "r") as reader:
            # Read the output file every two lines
            for line1, line2 in itertools.izip_longest(*[reader] * 2):
                info = OslomRunner.RE_INFOLINE.match(line1.strip()).groups()
                nodes = line2.strip().split(" ")
                if len(nodes) >= min_cluster_size: # Apply min_cluster_size
                    clusters.append({
                        "id": int(info[0]),
                        "bs": float(info[2]),
                        "nodes": [{"id": self.id_remapper.get_str_id(int(n))} for n in nodes],
                    })
                num_found += 1
        return {"num_found": num_found, "clusters": clusters}