float Bchart:: meFHProb(const Term* trm, FullHist& fh, int whichInt) { Edge* edge = fh.e; int pos = 0; /* the left to right position we are working on is either the far left (0) or the far right */ if(!globalGi) {} //else if(edge->item() != globalGi->index(0)) ; else if(whichInt == RUCALC || whichInt == RMCALC || whichInt == RCALC) pos = globalGi->size()-1; fh.pos = pos; int cVal = trm->toInt(); if(printDebug() > 138) { cerr << "meP " << *trm << " " << cVal << " " << whichInt << " "; if(edge) cerr << *edge << endl; else cerr << fh.preTerm << endl; } //int subfVals[MAXNUMFS]; FeatureTree* ginfo[MAXNUMFS]; ginfo[0] = FeatureTree::roots(whichInt); assert(ginfo[0]); float smoothedPs[MAXNUMFS]; float ans = 1; for(int i = 1 ; i <= Feature::total[whichInt] ; i++) { ginfo[i] = NULL; Feature* feat = Feature::fromInt(i, whichInt); /* e.g., g(rtlu) starts from where g(rtl) left off (after tl)*/ int searchStartInd = feat->startPos; FeatureTree* strt = ginfo[searchStartInd]; if(!strt) { continue; } SubFeature* sf = SubFeature::fromInt(feat->subFeat, whichInt); int usf = sf->usf; int nfeatV = (edgeFnsArray[usf])(&fh); FeatureTree* histPt = strt->follow(nfeatV, feat->auxCnt); ginfo[i] = histPt; if(i == 1) { smoothedPs[0] = 1; assert(histPt); Feat* f =histPt->feats.find(cVal); if(!f) { return 0.0; } smoothedPs[1] = f->g(); if(printDebug() > 238) { cerr << i << " " << nfeatV << " " << smoothedPs[1] << endl; } for(int j = 2; j <= Feature::total[whichInt] ; j++) smoothedPs[j] = 0; ans = smoothedPs[1]; continue; } if(nfeatV < -1) { if(printDebug() > 128) { cerr<<"p"<<whichInt<< "(" << cVal << "|"; if(edge) cerr << *edge; else cerr << fh.preTerm; cerr << ") = " << ans << endl; } return ans; } if(!histPt) { continue; } int b; if(Feature::isLM) { /*new bucketing */ float sz = (float)histPt->feats.size(); float estm = (float)histPt->count / sz; assert(i >= 2); b = bucket(estm, whichInt,i); } else { /* old bucketing*/ float estm; //estm = histPt->count * smoothedPs[1]; estm = histPt->count * 0.1; b = bucket(estm); } Feat* ft = histPt->feats.find(cVal); float unsmoothedVal; if(!ft) unsmoothedVal = 0; else unsmoothedVal = ft->g(); float lam = Feature::getLambda(whichInt, i, b); float uspathprob = lam*unsmoothedVal; float osmoothedVal = smoothedPs[searchStartInd]; //float osmoothedVal = smoothedPs[i-1]; //for deleted interp. float smpathprob = (1-lam)*osmoothedVal; float nsmoothedVal = uspathprob+smpathprob; if(printDebug() > 238) { cerr << i << " " << nfeatV << " " << usf << " " << b <<" "<<unsmoothedVal << " " << lam << " " << nsmoothedVal << endl; } smoothedPs[i] = nsmoothedVal; ans *= (nsmoothedVal/osmoothedVal); } if(printDebug() > 128) { cerr<<"p"<<whichInt<< "(" << cVal << "|"; if(edge) cerr << *edge; else cerr << fh.preTerm; cerr << ") = " << ans << endl; } return ans; }
float MeChart:: meProb(int cVal, FullHist* h, int whichInt) { if(printDebug() > 68) { prDp(); cerr << "meP" << whichInt << "(" << cVal << " | " << *h << ")" <<endl; } FeatureTree* ginfo[MAXNUMFS]; ginfo[0] = FeatureTree::roots(whichInt); float smoothedPs[MAXNUMFS]; Feature::whichInt = whichInt; float ans = 1; for(int i = 1 ; i <= Feature::total[whichInt] ; i++) { int knp = useKn(i,whichInt); ginfo[i] = NULL; Feature* feat = Feature::fromInt(i, whichInt); /* e.g., g(rtlu) starts from where g(rtl) left off (after tl)*/ int searchStartInd = feat->startPos; if(i > 1) smoothedPs[i] = smoothedPs[i-1]; FeatureTree* strt = ginfo[searchStartInd]; if(!strt) { continue; } SubFeature* sf = SubFeature::fromInt(feat->subFeat, whichInt); int nfeatV = (*(sf->fun))(h); FeatureTree* histPt = strt->follow(nfeatV, feat->auxCnt); ginfo[i] = histPt; if(i == 1) { smoothedPs[0] = 1; if(!histPt) { cerr << cVal << " " << whichInt << " " << nfeatV << " " << searchStartInd <<" " << feat->auxCnt << endl; assert(histPt); } Feat* f =histPt->feats.find(cVal); if(!f) { if(printDebug() > 60) { prDp(); cerr << "Zero p" << feat->name << " " << nfeatV << endl; } if(whichInt == HCALC) return 0.001; return 0.0; } smoothedPs[1] = f->g(); if(printDebug() > 68) { prDp(); cerr << i << " " << nfeatV << " " << smoothedPs[1] << endl; } for(int j = 2; j <= Feature::total[whichInt] ; j++) smoothedPs[j] = 0; ans = smoothedPs[1]; continue; } if(!histPt) { continue; } int b; if(Feature::isLM) { /* this section for new bucketing */ float sz = (float)histPt->feats.size(); float estm = (float)histPt->count / sz; b = bucket(estm, whichInt,i); } else { /* this section for old bucketing */ float estm = histPt->count * smoothedPs[1]; b = bucket(estm); } Feat* ft = histPt->feats.find(cVal); float unsmoothedVal; if(!ft) unsmoothedVal = 0; else unsmoothedVal = ft->g(); float lam = 1; if(!knp) lam = Feature::getLambda(whichInt, i, b); float uspathprob = lam*unsmoothedVal; float osmoothedVal; /* First version is for parsing, second for language modeling */ if(Feature::isLM) osmoothedVal = smoothedPs[i-1]; //for deleted interp. else osmoothedVal = smoothedPs[searchStartInd]; float oneMlam = (1-lam); if(knp) { oneMlam = histPt->count/1000.0; } float smpathprob = oneMlam*osmoothedVal; float nsmoothedVal = uspathprob+smpathprob; smoothedPs[i] = nsmoothedVal; ans *= (nsmoothedVal/osmoothedVal); if(printDebug() > 68) { prDp(); cerr << i << " " << nfeatV << " " << b <<" "<<unsmoothedVal << " " << lam << " " << nsmoothedVal << endl; } } if(whichInt == HCALC) ans *= 600; if(printDebug() > 30) { prDp(); cerr<<"p"<<whichInt<< "(" << cVal << "|" << *h << ") = " << ans << endl; } return ans; }