static void ngram_fwdflat_expand_all(ngram_search_t *ngs) { int n_words, i; /* For all "real words" (not fillers or <s>/</s>) in the dictionary, * * 1) Add the ones which are in the LM to the fwdflat wordlist * 2) And to the expansion list (since we are expanding all) */ ngs->n_expand_words = 0; n_words = ps_search_n_words(ngs); bitvec_clear_all(ngs->expand_word_flag, ps_search_n_words(ngs)); for (i = 0; i < n_words; ++i) { if (!ngram_model_set_known_wid(ngs->lmset, dict_basewid(ps_search_dict(ngs),i))) continue; ngs->fwdflat_wordlist[ngs->n_expand_words] = i; ngs->expand_word_list[ngs->n_expand_words] = i; bitvec_set(ngs->expand_word_flag, i); ngs->n_expand_words++; } E_INFO("Utterance vocabulary contains %d words\n", ngs->n_expand_words); ngs->expand_word_list[ngs->n_expand_words] = -1; ngs->fwdflat_wordlist[ngs->n_expand_words] = -1; }
static void get_expand_wordlist(ngram_search_t *ngs, int32 frm, int32 win) { int32 f, sf, ef; ps_latnode_t *node; if (!ngs->fwdtree) { ngs->st.n_fwdflat_word_transition += ngs->n_expand_words; return; } sf = frm - win; if (sf < 0) sf = 0; ef = frm + win; if (ef > ngs->n_frame) ef = ngs->n_frame; bitvec_clear_all(ngs->expand_word_flag, ps_search_n_words(ngs)); ngs->n_expand_words = 0; for (f = sf; f < ef; f++) { for (node = ngs->frm_wordlist[f]; node; node = node->next) { if (!bitvec_is_set(ngs->expand_word_flag, node->wid)) { ngs->expand_word_list[ngs->n_expand_words++] = node->wid; bitvec_set(ngs->expand_word_flag, node->wid); } } } ngs->expand_word_list[ngs->n_expand_words] = -1; ngs->st.n_fwdflat_word_transition += ngs->n_expand_words; }
void acmod_clear_active(acmod_t *acmod) { if (acmod->compallsen) return; bitvec_clear_all(acmod->senone_active_vec, bin_mdef_n_sen(acmod->mdef)); acmod->n_senone_active = 0; }
void treeview_mark_all(treeview_t *tr, treeview_mark mark) { switch (mark) { case treeview_mark_COLLAPSE: bitvec_clear_all(tr->open); break; case treeview_mark_EXPAND: bitvec_set_all(tr->open); break; } }
static int filerwin_event_user_drag_box(wimp_event_no event_no, wimp_block *block, void *handle) { wimp_dragged *dragged; filerwin *fw; NOT_USED(event_no); dragged = &block->dragged; fw = handle; if (fw->drag_type == drag_type_SELECTION_SELECT || fw->drag_type == drag_type_SELECTION_ADJUST) { wimp_version_no version; mapfn *selector; wimp_window_state wstate; xwimpreadsysinfo_version(&version); if (version >= wimp_VERSION_RO40) wimp_auto_scroll(0, NULL); // convert dragged.final to workarea relative // (note fiddling with dragged->final in place) wstate.w = fw->w; wimp_get_window_state(&wstate); screen_box_to_workarea(&dragged->final, &wstate); // for each icon: do we hit it? if (fw->drag_type == drag_type_SELECTION_SELECT) { bitvec_clear_all(fw->selection); selector = select_bobs; } else { selector = adjust_bobs; } map(fw, selector, 0,0, &dragged->final, NULL); fw->drag_type = -1; }
static int32 senactive_to_mgauactive (acoustic_t *am) { int32 n, s; gauden_t *gau; senone_t *sen; sen = am->sen; gau = am->gau; bitvec_clear_all(am->gauden_active, gau->n_mgau); n = 0; for (s = 0; s < sen->n_sen; s++) { if (bitvec_is_set (am->sen_active, s)) { bitvec_set (am->gauden_active, sen->sen2mgau[s]); n++; } } return n; }
void ngram_fwdflat_finish(ngram_search_t *ngs) { int32 cf; destroy_fwdflat_chan(ngs); destroy_fwdflat_wordlist(ngs); bitvec_clear_all(ngs->word_active, ps_search_n_words(ngs)); /* This is the number of frames processed. */ cf = ps_search_acmod(ngs)->output_frame; /* Add a mark in the backpointer table for one past the final frame. */ ngram_search_mark_bptable(ngs, cf); ptmr_stop(&ngs->fwdflat_perf); /* Print out some statistics. */ if (cf > 0) { double n_speech = (double)(cf + 1) / cmd_ln_int32_r(ps_search_config(ngs), "-frate"); E_INFO("%8d words recognized (%d/fr)\n", ngs->bpidx, (ngs->bpidx + (cf >> 1)) / (cf + 1)); E_INFO("%8d senones evaluated (%d/fr)\n", ngs->st.n_senone_active_utt, (ngs->st.n_senone_active_utt + (cf >> 1)) / (cf + 1)); E_INFO("%8d channels searched (%d/fr)\n", ngs->st.n_fwdflat_chan, ngs->st.n_fwdflat_chan / (cf + 1)); E_INFO("%8d words searched (%d/fr)\n", ngs->st.n_fwdflat_words, ngs->st.n_fwdflat_words / (cf + 1)); E_INFO("%8d word transitions (%d/fr)\n", ngs->st.n_fwdflat_word_transition, ngs->st.n_fwdflat_word_transition / (cf + 1)); E_INFO("fwdflat %.2f CPU %.3f xRT\n", ngs->fwdflat_perf.t_cpu, ngs->fwdflat_perf.t_cpu / n_speech); E_INFO("fwdflat %.2f wall %.3f xRT\n", ngs->fwdflat_perf.t_elapsed, ngs->fwdflat_perf.t_elapsed / n_speech); }
int DBSCAN(void *data, unsigned int *d, unsigned int dlen, float eps, unsigned int minpoints, unsigned int (*neighbours_search)(bitvec_t *out, void *, unsigned int, float, unsigned int *) ) { unsigned int cluster = 1; unsigned int count, i, j, k; bitvec_t *visited, *clustered, *neighbours, *neighbours2; bitvec_alloc(&visited, dlen); bitvec_alloc(&clustered, dlen); bitvec_alloc(&neighbours, dlen); bitvec_alloc(&neighbours2, dlen); // d is a list of identifiers for (i = 0; i < dlen; i++) { count = 0; // Already visited this point if (bitvec_check(visited, i)) continue; fprintf(stderr, "Cluster: %.2f\n", 100.0*i/dlen); // Mark this point as visited bitvec_set(visited, i); bitvec_clear_all(neighbours); // Get the first set of neighbours if(neighbours_search(neighbours, data, i, eps, &count)) { return 1; } if (count < minpoints) { *(d + i) = 0; // Noise continue; } *(d + i) = cluster; bitvec_set(clustered, i); // Expand the cluster for (j = 0; j < dlen; j++) { if(!bitvec_check(neighbours, j)) continue; if(!bitvec_check(visited, j)) { bitvec_set(visited, j); count = 0; bitvec_clear_all(neighbours2); if (neighbours_search(neighbours2, data, j, eps, &count)) { return 1; } if (count >= minpoints) { // Merge two bitarrays bitvec_union(neighbours, neighbours2); j = 0; } } if (!bitvec_check(clustered, j)) { *(d + j) = cluster; bitvec_set(clustered, j); } } cluster++; } bitvec_free(visited); bitvec_free(clustered); bitvec_free(neighbours); bitvec_free(neighbours2); return 0; }
static void fwdflat_prune_chan(ngram_search_t *ngs, int frame_idx) { int32 i, cf, nf, w, pip, newscore, thresh, wordthresh; int32 *awl; root_chan_t *rhmm; chan_t *hmm, *nexthmm; cf = frame_idx; nf = cf + 1; i = ngs->n_active_word[cf & 0x1]; awl = ngs->active_word_list[cf & 0x1]; bitvec_clear_all(ngs->word_active, ps_search_n_words(ngs)); thresh = ngs->best_score + ngs->fwdflatbeam; wordthresh = ngs->best_score + ngs->fwdflatwbeam; pip = ngs->pip; E_DEBUG(3,("frame %d thresh %d wordthresh %d\n", frame_idx, thresh, wordthresh)); /* Scan all active words. */ for (w = *(awl++); i > 0; --i, w = *(awl++)) { rhmm = (root_chan_t *) ngs->word_chan[w]; /* Propagate active root channels */ if (hmm_frame(&rhmm->hmm) == cf && hmm_bestscore(&rhmm->hmm) BETTER_THAN thresh) { hmm_frame(&rhmm->hmm) = nf; bitvec_set(ngs->word_active, w); /* Transitions out of root channel */ newscore = hmm_out_score(&rhmm->hmm); if (rhmm->next) { assert(!dict_is_single_phone(ps_search_dict(ngs), w)); newscore += pip; if (newscore BETTER_THAN thresh) { hmm = rhmm->next; /* Enter all right context phones */ if (hmm->info.rc_id >= 0) { for (; hmm; hmm = hmm->next) { if ((hmm_frame(&hmm->hmm) < cf) || (newscore BETTER_THAN hmm_in_score(&hmm->hmm))) { hmm_enter(&hmm->hmm, newscore, hmm_out_history(&rhmm->hmm), nf); } } } /* Just a normal word internal phone */ else { if ((hmm_frame(&hmm->hmm) < cf) || (newscore BETTER_THAN hmm_in_score(&hmm->hmm))) { hmm_enter(&hmm->hmm, newscore, hmm_out_history(&rhmm->hmm), nf); } } } } else { assert(dict_is_single_phone(ps_search_dict(ngs), w)); /* Word exit for single-phone words (where did their * whmms come from?) (either from * ngram_search_fwdtree, or from * ngram_fwdflat_allocate_1ph(), that's where) */ if (newscore BETTER_THAN wordthresh) { ngram_search_save_bp(ngs, cf, w, newscore, hmm_out_history(&rhmm->hmm), 0); } } } /* Transitions out of non-root channels. */ for (hmm = rhmm->next; hmm; hmm = hmm->next) { if (hmm_frame(&hmm->hmm) >= cf) { /* Propagate forward HMMs inside the beam. */ if (hmm_bestscore(&hmm->hmm) BETTER_THAN thresh) { hmm_frame(&hmm->hmm) = nf; bitvec_set(ngs->word_active, w); newscore = hmm_out_score(&hmm->hmm); /* Word-internal phones */ if (hmm->info.rc_id < 0) { newscore += pip; if (newscore BETTER_THAN thresh) { nexthmm = hmm->next; /* Enter all right-context phones. */ if (nexthmm->info.rc_id >= 0) { for (; nexthmm; nexthmm = nexthmm->next) { if ((hmm_frame(&nexthmm->hmm) < cf) || (newscore BETTER_THAN hmm_in_score(&nexthmm->hmm))) { hmm_enter(&nexthmm->hmm, newscore, hmm_out_history(&hmm->hmm), nf); } } } /* Enter single word-internal phone. */ else { if ((hmm_frame(&nexthmm->hmm) < cf) || (newscore BETTER_THAN hmm_in_score(&nexthmm->hmm))) { hmm_enter(&nexthmm->hmm, newscore, hmm_out_history(&hmm->hmm), nf); } } } } /* Right-context phones - apply word beam and exit. */ else { if (newscore BETTER_THAN wordthresh) { ngram_search_save_bp(ngs, cf, w, newscore, hmm_out_history(&hmm->hmm), hmm->info.rc_id); } } } /* Zero out inactive HMMs. */ else if (hmm_frame(&hmm->hmm) != nf) { hmm_clear_scores(&hmm->hmm); } } } } }
/** * Find all active words in backpointer table and sort by frame. */ static void build_fwdflat_wordlist(ngram_search_t *ngs) { int32 i, f, sf, ef, wid, nwd; bptbl_t *bp; ps_latnode_t *node, *prevnode, *nextnode; /* No tree-search, use statically allocated wordlist. */ if (!ngs->fwdtree) return; memset(ngs->frm_wordlist, 0, ngs->n_frame_alloc * sizeof(*ngs->frm_wordlist)); /* Scan the backpointer table for all active words and record * their exit frames. */ for (i = 0, bp = ngs->bp_table; i < ngs->bpidx; i++, bp++) { sf = (bp->bp < 0) ? 0 : ngs->bp_table[bp->bp].frame + 1; ef = bp->frame; wid = bp->wid; /* Anything that can be transitioned to in the LM can go in * the word list. */ if (!ngram_model_set_known_wid(ngs->lmset, dict_basewid(ps_search_dict(ngs), wid))) continue; /* Look for it in the wordlist. */ for (node = ngs->frm_wordlist[sf]; node && (node->wid != wid); node = node->next); /* Update last end frame. */ if (node) node->lef = ef; else { /* New node; link to head of list */ node = listelem_malloc(ngs->latnode_alloc); node->wid = wid; node->fef = node->lef = ef; node->next = ngs->frm_wordlist[sf]; ngs->frm_wordlist[sf] = node; } } /* Eliminate "unlikely" words, for which there are too few end points */ for (f = 0; f < ngs->n_frame; f++) { prevnode = NULL; for (node = ngs->frm_wordlist[f]; node; node = nextnode) { nextnode = node->next; /* Word has too few endpoints */ if ((node->lef - node->fef < ngs->min_ef_width) || /* Word is </s> and doesn't actually end in last frame */ ((node->wid == ps_search_finish_wid(ngs)) && (node->lef < ngs->n_frame - 1))) { if (!prevnode) ngs->frm_wordlist[f] = nextnode; else prevnode->next = nextnode; listelem_free(ngs->latnode_alloc, node); } else prevnode = node; } } /* Form overall wordlist for 2nd pass */ nwd = 0; bitvec_clear_all(ngs->word_active, ps_search_n_words(ngs)); for (f = 0; f < ngs->n_frame; f++) { for (node = ngs->frm_wordlist[f]; node; node = node->next) { if (!bitvec_is_set(ngs->word_active, node->wid)) { bitvec_set(ngs->word_active, node->wid); ngs->fwdflat_wordlist[nwd++] = node->wid; } } } ngs->fwdflat_wordlist[nwd] = -1; E_INFO("Utterance vocabulary contains %d words\n", nwd); }
main (int32 argc, char *argv[]) { kb_t kb; kbcore_t *kbcore; bitvec_t active; int32 w; cmd_ln_parse (arglist, argc, argv); unlimit(); kbcore = kbcore_init (cmd_ln_float32("-logbase"), cmd_ln_str("-feat"), cmd_ln_str("-mdef"), cmd_ln_str("-dict"), cmd_ln_str("-fdict"), cmd_ln_str("-compsep"), cmd_ln_str("-lm"), cmd_ln_str("-fillpen"), cmd_ln_float32("-silprob"), cmd_ln_float32("-fillprob"), cmd_ln_float32("-lw"), cmd_ln_float32("-wip"), cmd_ln_str("-mean"), cmd_ln_str("-var"), cmd_ln_float32("-varfloor"), cmd_ln_str("-senmgau"), cmd_ln_str("-mixw"), cmd_ln_float32("-mixwfloor"), cmd_ln_str("-tmat"), cmd_ln_float32("-tmatfloor")); /* Here's the perfect candidate for inheritance */ kb.mdef = kbcore->mdef; kb.dict = kbcore->dict; kb.lm = kbcore->lm; kb.fillpen = kbcore->fillpen; kb.tmat = kbcore->tmat; kb.dict2lmwid = kbcore->dict2lmwid; if ((kb.am = acoustic_init (kbcore->fcb, kbcore->gau, kbcore->sen, cmd_ln_float32("-mgaubeam"), S3_MAX_FRAMES)) == NULL) { E_FATAL("Acoustic models initialization failed\n"); } kb.beam = logs3 (cmd_ln_float64("-beam")); kb.wordbeam = logs3 (cmd_ln_float64("-wordbeam")); kb.wordmax = cmd_ln_int32("-wordmax"); /* Mark the active words and build lextree */ active = bitvec_alloc (dict_size (kb.dict)); bitvec_clear_all (active, dict_size(kb.dict)); for (w = 0; w < dict_size(kb.dict); w++) { if (IS_LMWID(kb.dict2lmwid[w]) || dict_filler_word (kb.dict, w)) bitvec_set (active, w); } kb.lextree_root = lextree_build (kb.dict, kb.mdef, active, cmd_ln_int32("-flatdepth")); kb.vithist = (glist_t *) ckd_calloc (S3_MAX_FRAMES+2, sizeof(glist_t)); kb.vithist++; /* Allow for dummy frame -1 for start word */ kb.lextree_active = NULL; kb.wd_last_sf = (int32 *) ckd_calloc (dict_size(kb.dict), sizeof(int32)); kb.tm = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t)); kb.tm_search = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t)); ctl_process (cmd_ln_str("-ctl"), cmd_ln_int32("-ctloffset"), cmd_ln_int32("-ctlcount"), decode_utt, &kb); exit(0); }