Computes the term frequency and stores it as a dictionary

        :param cluster: the cluster that contains the metadata
        :return: tf dictionary
323213
def tf(cluster):
        
        counts = dict()
        words = cluster.split(' ')
        for word in words:
            counts[word] = counts.get(word, 0) + 1
        return counts
880956
def frequencies_iter(self):
        
        f = self.__matrix.mean(axis=0)
        for i, m in self.mappings.iteritems():
            yield m, f[i]
1330650
def ref_frequency(self, context):
        
        ref_freq = np.empty(context.shape, context.dtype)
        ref_freq[:] = 1.415e9

        return ref_freq
1208641
def _convert_to_clusters(c):
    """"""
    new_dict = {}
    n_cluster = 0
    logger.debug("_convert_to_cluster: loci %s" % c.loci2seq.keys())
    for idl in c.loci2seq:
        n_cluster += 1
        new_c = cluster(n_cluster)
        #new_c.id_prev = c.id
        new_c.loci2seq[idl] = c.loci2seq[idl]
        new_dict[n_cluster] = new_c
    logger.debug("_convert_to_cluster: new ids %s" % new_dict.keys())
    return new_dict
1222327
def rc_stats(stats):
    
    rc_nucs = {'A':'T', 'T':'A', 'G':'C', 'C':'G', 'N':'N'}
    rcs = []
    for pos in reversed(stats):
        rc = {}
        rc['reference frequencey'] = pos['reference frequency']
        rc['consensus frequencey'] = pos['consensus frequency']
        rc['In'] = pos['In']
        rc['Del'] = pos['Del']
        rc['ref'] = rc_nucs[pos['ref']]
        rc['consensus'] = (rc_nucs[pos['consensus'][0]], pos['consensus'][1])
        for base, stat in list(pos.items()):
            if base in rc_nucs:
                rc[rc_nucs[base]] = stat
        rcs.append(rc)
    return rcs
574453
def as_dict(self):
        
        return {"@module": self.__class__.__module__,
                "@class": self.__class__.__name__,
                "frequencies": list(self.frequencies),
                "densities": list(self.densities)}
710025
def clusterMetrics(timeValues, massValues, massScalingFactor=1):
    
    metrics = dict()
    metrics['meanTime'] = numpy.mean(timeValues)
    metrics['meanMass'] = numpy.mean(massValues)
    metrics['devTime'] = timeValues - metrics['meanTime']
    metrics['devMass'] = massValues - metrics['meanMass']
    #metrics['devMass'] = (1-metrics['meanMass']/massValues)
    metrics['spreadTime'] = numpy.max(timeValues) - numpy.min(timeValues)
    metrics['spreadMass'] = numpy.max(massValues) - numpy.min(massValues)
    #metrics['spreadMass'] = (1-numpy.min(massValues) / numpy.max(massValues))
    metrics['devEuc'] = numpy.sqrt(numpy.power(metrics['devTime'], 2) +
                                   numpy.power(metrics['devMass']*massScalingFactor, 2)
                                   )
    metrics['meanEuc'] = numpy.mean(metrics['devEuc'])
    metrics['devTime'] = metrics['devTime'].tolist()
    metrics['devMass'] = metrics['devMass'].tolist()
    metrics['devEuc'] = metrics['devEuc'].tolist()
    return metrics
573135
def serialize(self):
        
        pickle = super(ResourceParameter, self).serialize()
        pickle['frequency'] = self.frequency
        pickle['unit'] = self._unit.serialize()
        return pickle
1372144
def _get_cluster_dict(cluster_name, cluster_ref):
    '''
    
    '''

    log.trace('Building a dictionary representation of cluster \'%s\'', cluster_name)
    props = salt.utils.vmware.get_properties_of_managed_object(
        cluster_ref,
        properties=['configurationEx'])
    res = {'ha': {'enabled': props['configurationEx'].dasConfig.enabled},
           'drs': {'enabled': props['configurationEx'].drsConfig.enabled}}
    # Convert HA properties of interest
    ha_conf = props['configurationEx'].dasConfig
    log.trace('ha_conf = %s', ha_conf)
    res['ha']['admission_control_enabled'] = ha_conf.admissionControlEnabled
    if ha_conf.admissionControlPolicy and \
       isinstance(ha_conf.admissionControlPolicy,
                  vim.ClusterFailoverResourcesAdmissionControlPolicy):
        pol = ha_conf.admissionControlPolicy
        res['ha']['admission_control_policy'] = \
                {'cpu_failover_percent': pol.cpuFailoverResourcesPercent,
                 'memory_failover_percent': pol.memoryFailoverResourcesPercent}
    if ha_conf.defaultVmSettings:
        def_vm_set = ha_conf.defaultVmSettings
        res['ha']['default_vm_settings'] = \
                {'isolation_response': def_vm_set.isolationResponse,
                 'restart_priority': def_vm_set.restartPriority}
    res['ha']['hb_ds_candidate_policy'] = \
            ha_conf.hBDatastoreCandidatePolicy
    if ha_conf.hostMonitoring:
        res['ha']['host_monitoring'] = ha_conf.hostMonitoring
    if ha_conf.option:
        res['ha']['options'] = [{'key': o.key, 'value': o.value}
                                for o in ha_conf.option]
    res['ha']['vm_monitoring'] = ha_conf.vmMonitoring
    # Convert DRS properties
    drs_conf = props['configurationEx'].drsConfig
    log.trace('drs_conf = %s', drs_conf)
    res['drs']['vmotion_rate'] = 6 - drs_conf.vmotionRate
    res['drs']['default_vm_behavior'] = drs_conf.defaultVmBehavior
    # vm_swap_placement
    res['vm_swap_placement'] = props['configurationEx'].vmSwapPlacement
    # Convert VSAN properties
    si = salt.utils.vmware.get_service_instance_from_managed_object(
        cluster_ref)

    if salt.utils.vsan.vsan_supported(si):
        # XXX The correct way of retrieving the VSAN data (on the if branch)
        #  is not supported before 60u2 vcenter
        vcenter_info = salt.utils.vmware.get_service_info(si)
        if int(vcenter_info.build) >= 3634794:  # 60u2
            # VSAN API is fully supported by the VC starting with 60u2
            vsan_conf = salt.utils.vsan.get_cluster_vsan_info(cluster_ref)
            log.trace('vsan_conf = %s', vsan_conf)
            res['vsan'] = {'enabled': vsan_conf.enabled,
                           'auto_claim_storage':
                           vsan_conf.defaultConfig.autoClaimStorage}
            if vsan_conf.dataEfficiencyConfig:
                data_eff = vsan_conf.dataEfficiencyConfig
                res['vsan'].update({
                    # We force compression_enabled to be True/False
                    'compression_enabled':
                    data_eff.compressionEnabled or False,
                    'dedup_enabled': data_eff.dedupEnabled})
        else:  # before 60u2 (no advanced vsan info)
            if props['configurationEx'].vsanConfigInfo:
                default_config = \
                        props['configurationEx'].vsanConfigInfo.defaultConfig
                res['vsan'] = {
                    'enabled': props['configurationEx'].vsanConfigInfo.enabled,
                    'auto_claim_storage': default_config.autoClaimStorage}
    return res
260482
def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
        ''''''
        if rename_dict is None:
            rename_dict = {}

        # check that every sequence in the clusters file can be
        # found in the fasta file
        seq_reader = pyfastaq.sequences.file_reader(self.infile)
        names_list_from_fasta_file = [seq.id for seq in seq_reader]
        names_set_from_fasta_file = set(names_list_from_fasta_file)

        clusters = self._load_user_clusters_file(clusters_infile, all_ref_seqs, rename_dict=rename_dict)

        if len(names_set_from_fasta_file) != len(names_list_from_fasta_file):
            raise Error('At least one duplicate name in fasta file ' + self.infile + '. Cannot continue')

        names_from_clusters_file = set()
        for new_names in clusters.values():
            names_from_clusters_file.update(new_names)

        if not names_set_from_fasta_file.issubset(names_from_clusters_file):
            raise Error('Some names in fasta file "' + self.infile + '" not given in cluster file. Cannot continue')

        return clusters
1184159
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'type') and self.type is not None:
            _dict['type'] = self.type
        if hasattr(self, 'frequency') and self.frequency is not None:
            _dict['frequency'] = self.frequency
        if hasattr(self, 'arguments') and self.arguments is not None:
            _dict['arguments'] = [x._to_dict() for x in self.arguments]
        if hasattr(self, 'evidence') and self.evidence is not None:
            _dict['evidence'] = [x._to_dict() for x in self.evidence]
        return _dict
8563
def get_topic_keyword_dictionary():
    
    topic_keyword_dictionary = dict()
    file_row_gen = get_file_row_generator(get_package_path() + "/twitter/res/topics/topic_keyword_mapping" + ".txt",
                                          ",",
                                          "utf-8")
    for file_row in file_row_gen:
        topic_keyword_dictionary[file_row[0]] = set([keyword for keyword in file_row[1:]])

    return topic_keyword_dictionary
654150
def get_cluster(self, word):
        
        idx = self.ix(word)
        return self.clusters[idx]
1074641
def word_freqs() -> List[Tuple[str, int]]:
    
    lines = list(get_corpus(_FILENAME))
    listword = []
    for line in lines:
        listindata = line.split("\t")
        listword.append((listindata[0], int(listindata[1])))

    return listword
938498
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'document_retrieval_strategy'
                  ) and self.document_retrieval_strategy is not None:
            _dict[
                'document_retrieval_strategy'] = self.document_retrieval_strategy
        return _dict
644186
def clusters_sites_obj(clusters):
    
    result = {}
    all_clusters = get_all_clusters_sites()
    clusters_sites = {c: s for (c, s) in all_clusters.items()
                        if c in clusters}
    for cluster, site in clusters_sites.items():

        # here we want the site python-grid5000 site object
        result.update({cluster: get_site_obj(site)})
    return result
325762
public static <TERM> Map<TERM, Double> idf(Iterable<Iterable<TERM>> documentVocabularies,
                                               boolean smooth, boolean addOne)
    {
        Map<TERM, Integer> df = new HashMap<TERM, Integer>();
        int d = smooth ? 1 : 0;
        int a = addOne ? 1 : 0;
        int n = d;
        for (Iterable<TERM> documentVocabulary : documentVocabularies)
        {
            n += 1;
            for (TERM term : documentVocabulary)
            {
                Integer t = df.get(term);
                if (t == null) t = d;
                df.put(term, t + 1);
            }
        }
        Map<TERM, Double> idf = new HashMap<TERM, Double>();
        for (Map.Entry<TERM, Integer> e : df.entrySet())
        {
            TERM term = e.getKey();
            double f = e.getValue();
            idf.put(term, Math.log(n / f) + a);
        }
        return idf;
    }