// When updateing the tree, the manager goes through and deactivates every node in the tree and then reactivates the root. // It then goes through the entire array of interactive shapes and adds them back into the tree. void QuadTreeManager::UpdateQuadtree() { unsigned int treeSize = _quadTree.size(); for (unsigned int i = 0; i < treeSize; ++i) { DeactivateNode(_quadTree[i]); } ActivateNode(_quadTree[0]); unsigned int shapesSize = _shapes.size(); for (unsigned int i = 0; i < shapesSize; ++i) { AddShape(_shapes[i], 0); } }
void Decoder::WordEndBeamPruning(LexNodeInst* head, TokScore &beamLimit) { TokScore bestWEscore = LZERO; LexNodeInst *next; LexNodeInst *prev = NULL; for (auto inst = head; inst; inst = next) { next = inst->next; // global main beam if (inst->best < beamLimit) { RemoveLexNode(head, prev, inst); DeactivateNode (inst->node); } else { HandleWordend (inst->node); bestWEscore = std::max(bestWEscore, inst->best); prev = inst; } } beamLimit = std::max(bestWEscore - _dec->weBeamWidth, _dec->beamLimit); }
/* ProcessFrame Takes the observation vector and propatagets all tokens and performs pruning as necessary. */ void Decoder::ProcessFrame (Observation **obsBlock, int nObs, AdaptXForm *xform) { inXForm = xform; /* sepcifies the transform to use */ /* reset obs */ SetObservation(obsBlock, nObs); GarbageCollectPaths (); InternalPropagation(); // Set the lowerbound of beam _dec->beamLimit = _dec->bestScore - _dec->curBeamWidth; // Beam pruning & External propagation for (int l = 0; l < _dec->nLayers; ++l) { LexNodeInst* &head = _dec->instsLayer[l]; // Update word end time/score in tok->path when passing through layer if (l == _dec->net->wordEndLayerId) { for (auto inst = head; inst; inst = inst->next) UpdateWordEndHyp (inst); } TokScore beamLimit = _dec->beamLimit; if ((_dec->weBeamWidth < _dec->beamWidth) && (l == LAYER_WE)) WordEndBeamPruning(head, beamLimit); else if ((_dec->zsBeamWidth < _dec->beamWidth) && (l == LAYER_ZS || l == LAYER_SA)) ZSLayerBeamPruning(head, beamLimit); // Go external propagation and pruning LexNodeInst* prev = NULL, *next = NULL; for (auto inst = head; inst; inst = next) { next = inst->next; if (inst->node->type != LN_WORDEND && inst->node->lmlaIdx != 0 && inst->ts->n > 0) { /* don't bother if inst will be pruned anyway */ if (inst->ts[0].score >= beamLimit) UpdateLMlookahead (inst->node); /* UpLMLA might have killed the entire TS, esp. in latlm */ if (inst->ts->n > 0) inst->best = std::max(inst->best, inst->ts[0].score); } // Pruning if (inst->best < beamLimit) { RemoveLexNode(head, prev, inst); DeactivateNode (inst->node); continue; } ++_dec->stats.nActive; // Pronprob handling before sil layer if (_dec->net->silDict && (l == _dec->net->spSkipLayer) && inst->ts[0].n > 0) { HandleSpSkipLayer (inst); continue; } // Normal case: non silDict or non spSkipLayer if (l == LAYER_SIL && inst->node->type == LN_MODEL) this->SetWordEndTag(inst); bool handleWE = !(_dec->weBeamWidth < _dec->beamWidth) || (l == LAYER_SIL) || (l == LAYER_AB); ExternalPropagation (inst, handleWE, l == LAYER_BY); prev = inst; } // for each node in the same layer } // for each layer this->RelaxBeamLimit(); ++_dec->stats.nFrames; _dec->outPCache->cacheHit = _dec->outPCache->cacheMiss = 0; _dec->lmCache->transHit = _dec->lmCache->transMiss = 0; _dec->lmCache->laHit = _dec->lmCache->laMiss = 0; if (_dec->nPhone > 0) CalcPhonePost (); }