Helper function for determining what the clusters/chains/other collections are.
359947
def get_collections(self):
        """"""
        if not self.quiet:
            print
            print "Finding " + self.current_collection_type + "s..."

        self.compute_collections()

        if not self.quiet:
            print self.current_similarity_measure, self.current_collection_type, "information:"
            table_contents = [("Collection","Indices","Size")]
            for (i, j, k) in zip(self.collection_indices,self.collection_sizes,self.collection_list):
                table_contents.append(([unit.text for unit in k], i, j))
            print_table(table_contents)
935037
def get_closest_clusters(cluster_id, cluster_ids, sim_func, max_n=None):
    """"""
    l = [(_as_scalar(candidate), _as_scalar(sim_func(cluster_id, candidate)))
         for candidate in _as_scalars(cluster_ids)]
    l = sorted(l, key=itemgetter(1), reverse=True)
    max_n = None or len(l)
    return l[:max_n]
960650
def check_collections_are_supported(saved_model_handler, supported):
  """"""
  for meta_graph in saved_model_handler.meta_graphs:
    used_collection_keys = set(meta_graph.collection_def.keys())
    unsupported = used_collection_keys - supported
    if unsupported:
      raise ValueError("Unsupported collections in graph: %s\n"
                       "Use hub.create_module_spec(..., drop_collections=[...])"
                       " as appropriate." % list(unsupported))
1262481
def cluster(self, dist_type='cosine', run_clustering=True,
                 dendro=True, views=['N_row_sum', 'N_row_var'],
                 linkage_type='average', sim_mat=False, filter_sim=0.1,
                 calc_cat_pval=False, run_enrichr=None, enrichrgram=None):
    '''
    
    '''
    initialize_net.viz(self)

    make_clust_fun.make_clust(self, dist_type=dist_type, run_clustering=run_clustering,
                                   dendro=dendro,
                                   requested_views=views,
                                   linkage_type=linkage_type,
                                   sim_mat=sim_mat,
                                   filter_sim=filter_sim,
                                   calc_cat_pval=calc_cat_pval,
                                   run_enrichr=run_enrichr,
                                   enrichrgram=enrichrgram)
258216
def iteritems(self):
        ""
        return chain(self._pb.StringMap.items(),
                     self._pb.IntMap.items(),
                     self._pb.FloatMap.items(),
                     self._pb.BoolMap.items())
695858
def partitions(collection):
    
    collection = list(collection)

    # Special cases
    if not collection:
        return

    if len(collection) == 1:
        yield [collection]
        return

    first = collection[0]
    for smaller in partitions(collection[1:]):
        for n, subset in enumerate(smaller):
            yield smaller[:n] + [[first] + subset] + smaller[n+1:]
        yield [[first]] + smaller
321700
function Collection(nodes) {
  this.length = 0;
  if (nodes) {
    nodes = unique(nodes);
    this.length = nodes.length;
    // add each node to an index-based property on collection, in order to
    // appear "array"-like
    for (var i = 0, len = nodes.length; i < len; i++) {
      this[i] = nodes[i];
    }
  }
}
982125
def _make_clusters(self, matrix, num_clusters_per_roi, metric):
        """"""

        from scipy.cluster.hierarchy import fclusterdata

        # maxclust needed to ensure t is interpreted as # clusters in heirarchical clustering
        group_ids = fclusterdata(matrix, metric=metric, t=num_clusters_per_roi,
                                 criterion='maxclust')
        group_set = np.unique(group_ids)
        clusters = [
            self._summary_func(matrix[group_ids == group, :], axis=0, keepdims=True)
            for group in group_set]

        return np.vstack(clusters).squeeze()
611904
def clusterstatus(self):
        

        res = self.cluster_status_raw()

        cluster = res['cluster']['collections']
        out = {}
        try:
            for collection in cluster:
                out[collection] = {}
                for shard in cluster[collection]['shards']:
                    out[collection][shard] = {}
                    for replica in cluster[collection]['shards'][shard]['replicas']:
                        out[collection][shard][replica] = cluster[collection]['shards'][shard]['replicas'][replica]
                        if out[collection][shard][replica]['state'] != 'active':
                            out[collection][shard][replica]['doc_count'] = False
                        else:
                            out[collection][shard][replica]['doc_count'] = self._get_collection_counts(
                                out[collection][shard][replica])
        except Exception as e:
            self.logger.error("Couldn't parse response from clusterstatus API call")
            self.logger.exception(e)

        return out
1092413
private Clustering<SubspaceModel> computeClusters(Relation<V> database, DiSHClusterOrder clusterOrder) {
    final int dimensionality = RelationUtil.dimensionality(database);

    // extract clusters
    Object2ObjectOpenCustomHashMap<long[], List<ArrayModifiableDBIDs>> clustersMap = extractClusters(database, clusterOrder);
    logClusterSizes("Step 1: extract clusters", dimensionality, clustersMap);

    // check if there are clusters < minpts
    checkClusters(database, clustersMap);
    logClusterSizes("Step 2: check clusters", dimensionality, clustersMap);

    // sort the clusters
    List<Cluster<SubspaceModel>> clusters = sortClusters(database, clustersMap);
    if(LOG.isVerbose()) {
      StringBuilder msg = new StringBuilder("Step 3: sort clusters");
      for(Cluster<SubspaceModel> c : clusters) {
        msg.append('\n').append(BitsUtil.toStringLow(c.getModel().getSubspace().getDimensions(), dimensionality)).append(" ids ").append(c.size());
      }
      LOG.verbose(msg.toString());
    }

    // build the hierarchy
    Clustering<SubspaceModel> clustering = new Clustering<>("DiSH clustering", "dish-clustering");
    buildHierarchy(database, clustering, clusters, dimensionality);
    if(LOG.isVerbose()) {
      StringBuilder msg = new StringBuilder("Step 4: build hierarchy");
      for(Cluster<SubspaceModel> c : clusters) {
        msg.append('\n').append(BitsUtil.toStringLow(c.getModel().getSubspace().getDimensions(), dimensionality)).append(" ids ").append(c.size());
        for(It<Cluster<SubspaceModel>> iter = clustering.getClusterHierarchy().iterParents(c); iter.valid(); iter.advance()) {
          msg.append("\n   parent ").append(iter.get());
        }
        for(It<Cluster<SubspaceModel>> iter = clustering.getClusterHierarchy().iterChildren(c); iter.valid(); iter.advance()) {
          msg.append("\n   child ").append(iter.get());
        }
      }
      LOG.verbose(msg.toString());
    }

    // build result
    for(Cluster<SubspaceModel> c : clusters) {
      if(clustering.getClusterHierarchy().numParents(c) == 0) {
        clustering.addToplevelCluster(c);
      }
    }
    return clustering;
  }
195350
function(collection, options, cb) {
    var ids = [];
    var keys = _.isFunction(collection.url) ? collection.url() : collection.url;
    keys += options.keys;
    debug('findKeys', keys);
    this.store().getItem(keys, function(err, data) {
      if (data) ids.push(keys);
      cb(null, ids);
    });
  }
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]
40952
def collect_related(self, finder_funcs, obj, count, *args, **kwargs):
        
        collected = []
        for func in finder_funcs:
            gathered = func(obj, count, collected, *args, **kwargs)
            if gathered:
                collected += gathered
            if len(collected) >= count:
                return collected[:count]

        return collected
344454
def get_chains(self):
        """"""
        chains = []
        try:
            content = os.listdir(self._directory)
            for c in content:
                if os.path.isdir(os.path.join(self._directory, c)) and c.startswith(
                        CHAIN_NAME[:-2]):
                    chains.append(c)
        except:
            pass
        chains.sort()
        return chains
281168
def is_instance_collection(c, cls):
    
    if not (hasattr(c, '__iter__') and len(c) > 0):
        # make sure it's iterable and not empty
        return False

    cls = make_list(cls)
    for i in get_collection_values(c):
        instance = False
        for cl in cls:
            if isinstance(i, cl):
                instance = True
                break
        if not instance:
            return False

    return True
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}
1017729
def _find_matching_collections_internally(collections, record):
    
    for name, data in iteritems(collections):
        if _build_query(data['query']).match(record):
            yield data['ancestors']
    raise StopIteration