📄 hresults.c
字号:
p = &grid[nTest][nRef]; err = p->del+p->sub+p->ins; if (best==0 || err < berr) { berr = err; best=i; bp = *p; } FreeGrid(); /* Actually frees much more */ if (trace & T_EVN) { if (i == 1) printf("%s:",NameOf(recfn,buf)); printf(" %2d",err);fflush(stdout); } } if (best==0) return; /* Empty test labels */ if (trace & T_EVN) printf("\n"),fflush(stdout); err = RecordFileStats(&bp); if (fullResults) PrintFileStats(NameOf(recfn,buf),bp.hit,bp.del,bp.sub,bp.ins); if ((outTrans && err) || outPStats) { test=GetLabelList(ans,best); CreateGrid(); if (nistAlign) DoCompareNIST(); else DoCompare(); if (outTrans && err) OutTrans(); if (outPStats) CollectStats(nTest,nRef); FreeGrid(); /* Actually frees much more */ }}/* ------------------ Word Spot Recording --------------------- *//* Linked list of keyword spots, these are chained to the labels in descending score order - nasty but convenient */typedef struct _SpotRec{ float score; /* score for this hit */ Boolean hit; /* true if real occurrence */ struct _SpotRec *next;} SpotRec;typedef int FAVec[10];static int spotWidth = 66;static SpotRec **spots;static int nonKeys=0; /* count of nonKeyWords encountered */static int *keyOccs; /* array[1..kn] of actual keyword occurrences */static int fomN; /* num FA levels needed */static float fomA; /* interpolation factor */static Matrix fomTab; /* array[1..kn+1,1..fomN+1] of hitRate *//* kn = #keywords, fomN = int >10T-0.5, T = total duration in hours *//* fomA = 10T - fomN, kn+1'th key index corresponds to sum over all keys *//* InitSpotLists: initialise the spot lists. Every entry has a sentinel record attached to avoid the 'empty list' case. */void InitSpotLists(void){ SpotRec *p; int i; keyOccs=(int *)New(&permHeap,nLabs*sizeof(int)); keyOccs--; spots=(SpotRec**)New(&permHeap,sizeof(SpotRec*)*nLabs); spots--; for (i=1; i<=nLabs; i++){ p = (SpotRec *) New(&permHeap,sizeof(SpotRec)); p->score = LZERO; p->hit = FALSE; p->next = NULL; keyOccs[i] = 0; spots[i] = p; }}/* AddSpot: insert given keyword spot into list */void AddSpot(LabId key, Boolean hit, float score){ SpotRec *newRec,*p,*q; int i; if (score <LZERO) HError(3333,"AddSpot: score %f too small to store",score); i = Index(key); if (i==0){ ++nonKeys; if (trace&T_NKY) { printf(" AddSpot: non keyword %s in test file\n",key->name); fflush(stdout); } return; } newRec = (SpotRec *) New(&permHeap,sizeof(SpotRec)); newRec->score = score; newRec->hit = hit; p = spots[i]; q = NULL; while (score < p->score) { q = p; p = p->next; } newRec->next = p; if (q==NULL) spots[i] = newRec; else q->next = newRec;}/* PrintSpotList: print the entries in the given spot list */void PrintSpotList(SpotRec *p){ while (p->next != NULL){ printf("%12f %s\n",p->score,p->hit?"":"FA"); p = p->next; }}/* PrintKeySpots: print all recorded key spots */void PrintKeySpots(void){ SpotRec *p; int i; printf("Spot Records\n"); for (i=1; i<=nLabs; i++){ printf("Key Spot list for %s [%d actual occurrences]\n", names[i]->name,keyOccs[i]); p = spots[i]; PrintSpotList(p); printf("\n"); } fflush(stdout);}/* IsHit: true if test label occurs in ref label list */Boolean IsHit(LLink t){ LLink l; HTime mid; int i,n; n=CountAuxLabs(ref,rlev); for (i=1; i<=n; i++) { l = GetAuxLabN(ref,i,rlev); mid = (l->start + AuxLabEndTime(l,rlev))/2.0; if (t->labid == l->labid && (t->start <= mid && t->end >= mid)){ return TRUE; } } return FALSE;}/* CreateFOMTab: calculate size of fomTab and create it */void CreateFOMTab(void){ float T; int kn; kn = nLabs; T = totalDur / (1.0E7*faTimeUnit*3600.0); fomN = (int) (10.0*T + 0.49999); fomA = 10.0*T - (float)fomN; fomTab = CreateMatrix(&permHeap,kn+1,fomN+1); ZeroMatrix(fomTab); if (trace&T_SPT) printf("FOM Table: kn=%d, fomN=%d, fomA=%f\n",kn,fomN,fomA);} /* CalcKeyFOM: Calculate the fomTab entries for given keyword */void CalcKeyFOM(int idx){ int count=0,faSeen=0; float nOccs; SpotRec *p; nOccs = (float) keyOccs[idx]; p = spots[idx]; while (p->next != NULL && faSeen<fomN+1){ if (p->hit) ++count; else { ++faSeen; fomTab[idx][faSeen] = (nOccs>0.0) ? (float) count / nOccs : 0.0; } p = p->next; } while (faSeen<fomN+1) fomTab[idx][++faSeen] = (nOccs>0.0) ? (float) count / nOccs : 0.0;}/* CalcGlobalFOM: Calculate the global fomTab entries */void CalcGlobalFOM(void){ int kn1,i,k,tOcc; float sum; kn1 = nLabs+1; for (i=1; i<=fomN+1; i++){ sum = 0.0; tOcc = 0; for (k=1; k<kn1; k++) if (keyOccs[k]>0){ sum += fomTab[k][i] * keyOccs[k]; tOcc += keyOccs[k]; } if (tOcc==0) HError(3333,"CalcGlobalFOM: zero total occurrences for fa %d",i); fomTab[kn1][i] = sum/(float)tOcc; }}/* GetFOM: calculate FOM for given index */float GetFOM(int idx){ int i; float tenT,sum; tenT = totalDur / (1.0E6*faTimeUnit*3600.0); sum = 0.0; for (i=1; i<=fomN; i++) sum += fomTab[idx][i]; sum += fomTab[idx][fomN+1] * fomA; return (sum / tenT) * 100;}/* GetHitRate: calculate % hit rate at given FA/hour */float GetHitRate(int idx, int FAperHour){ float xN,a,y1,y2,hitr; int n1,n2; xN = ((float)FAperHour * totalDur) / (1.0E7*faTimeUnit*3600.0) + 0.5; n1 = (int) xN; n2 = n1 + 1; if (n2>fomN+1) HError(3333,"GetHitRate: n2 [%d] > fomN+1 [%d+1]",n2,fomN+1); a = xN - (float) n1; if (n1>0) y1 = fomTab[idx][n1]; else{ /* need to interpolate */ if (n2<fomN+1) y1 = fomTab[idx][n2]*2.0 - fomTab[idx][n2+1]; else y1 = fomTab[idx][n2]; } y2 = fomTab[idx][n2]; hitr = (y2*a + y1*(1.0-a)) * 100.0; return hitr>0.0?hitr:0.0;}/* CountHits: count hits/FAs for given word */void CountHits(int idx, int *nh, int *nf){ SpotRec *p; int h=0,f=0; p = spots[idx]; while (p->next != NULL) { if (p->hit) ++h; else ++f; p = p->next; } *nh = h; *nf = f;}/* ------------------ Word Spot Matching Routines ----------------- *//* MatchSpotFiles: record word spots in test using reference in ref */void MatchSpotFiles(void){ int i,j,nr,nt; Label t,*l; HTime t1,t2; test=GetLabelList(ans,1); NormaliseName(test,tlev); if (test->head->succ == test->tail) { HError(-3330,"MatchSpotFile: Test Output File %s is Empty",recfn); return; } /* increment total duration - note that this assumes that the end of the last ref label or test label whichever is greater, marks the end of the file */ t1 = t2 = 0.0; if (ref->tail->pred!=ref->head) t1=ref->tail->pred->end; if (test->tail->pred!=test->head) t2=test->tail->pred->end; if (t1<0.0 || t2<0.0) { HError(-3333,"MatchSpotFiles: Final times missing from label files"); return; } totalDur += (t1>t2)?t1:t2; /* increment key occ counts */ nr=CountAuxLabs(ref,rlev); for (i=1; i<=nr; i++) { l = GetAuxLabN(ref,i,rlev); j=Index((rlev==0)?l->labid:l->auxLab[rlev]); if (j!=0) ++keyOccs[j]; } /* record key spots */ nt=CountAuxLabs(test,tlev); for (i=1; i<=nt; i++) { l = GetAuxLabN(test,i,tlev); t = *l; t.end = AuxLabEndTime(l,tlev); AddSpot(l->labid,IsHit(&t),l->score); }}/* PrintROCInfo: print %hits as function of FA rate */ void PrintROCInfo(int kn){ int i,fa; float hr; if (!headerPrinted) PrintHeader(); PrintBar(0,spotWidth,'-',"ROC Information"); printf("\n%13s:","KeyWord"); for (fa=0;fa<=10;fa++) printf("%5d",fa); printf("\n"); for (i=1; i<=kn; i++){ printf("%13s:",names[i]->name); for (fa=0; fa<=10; fa++){ hr = GetHitRate(i,fa); if (hr<100.0) printf("%5.1f",hr); else printf(" 100."); } printf("\n"); } printf("%13s:","Overall"); for (fa=0; fa<=10; fa++){ hr = GetHitRate(kn+1,fa); if (hr<100.0) printf("%5.1f",hr); else printf(" 100."); } printf("\n");}/* OutputSpotStats: output the word spotting scores */void OutputSpotStats(void){ int i,kn; int totOcc=0,totHit=0,totFAs=0; int nHits, nFAs, nActual; float fom; if (trace&T_SPT) PrintKeySpots(); CreateFOMTab(); kn = nLabs; for (i=1; i<=kn; i++) CalcKeyFOM(i); CalcGlobalFOM(); if (fullResults) PrintROCInfo(kn); if (!headerPrinted) PrintHeader(); PrintBar(0,spotWidth,'-',"Figures of Merit"); printf("\n%13s: %8s %8s %8s %8s\n","KeyWord","#Hits","#FAs","#Actual","FOM"); for (i=1; i<=kn; i++){ CountHits(i,&nHits,&nFAs); totHit += nHits; totFAs += nFAs; nActual = keyOccs[i]; totOcc += nActual; fom = (nActual>0)?GetFOM(i):0.0; printf("%13s: %8d %8d %8d %8.2f\n",names[i]->name, nHits, nFAs, nActual, fom); } fom = (totOcc>0)?GetFOM(kn+1):0.0; printf("%13s: %8d %8d %8d %8.2f\n","Overall", totHit, totFAs, totOcc, fom); printf("\n"); if (nonKeys>0) printf(" %d non keywords found in test files",nonKeys); PrintBar(0,spotWidth,'-',""); fflush(stdout);}/* ---------------------- Top Level Control ------------------- *//* Initialise: load the given 'hmm' list and initialise the program */void Initialise(char * listfn){ CreateHeap(&tempHeap, "tempHeap", MSTAK, 1, 1.0, 8000, 40000); nulClass = GetLabId(nulName,TRUE); ReadHMMList(listfn); if (stripContexts) LTriStrip(TRUE); if (outPStats) InitConMat(); if (wSpot) InitSpotLists(); if (fullResults && !wSpot && !nistFormat) PrintBar(0,htkWidth,'-',"Sentence Scores"); if (!nistFormat && spkrMask!=NULL) htkWidth += 11;}/* MatchFiles: match recfn (test) against labfn (ref) */void MatchFiles(void){ Transcription *tr; ans = LOpen(&tempHeap,recfn,tff); MakeFN(recfn,labDir,labExt,labfn); tr = LOpen(&tempHeap,labfn,rff); ref = GetLabelList(tr,1); if (ref->head->succ == ref->tail) { HError(-3330,"MatchFiles: Reference Transcription File %s is Empty",recfn); return; } NormaliseName(ref,rlev); if (wSpot) MatchSpotFiles(); else MatchRecFiles(); Dispose(&tempHeap,ans);}/* OutputStats: output global statistics */void OutputStats(void){ if (wSpot) OutputSpotStats(); else PrintGlobalStats();}/* ------------------------------------------------------------ *//* END: HResults.c *//* ------------------------------------------------------------ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -