float logLikely(FeatureTree* ft) { //cerr << "LL " << *ft << endl; int ftc = ft->count; assert(ftc > 0); FeatureTree* ftp = parentTree(ft); assert(ftp); int ftpc = ftp->count; assert(ftpc > 0); FeatMap::iterator fmi = ft->feats.begin(); float ans = 0; /* we compute the sum for each feature f on ft of |f|(log(p(f|ft))-log(p(f|ftb))) = logLcomp(fc, ftc, fpc, ftpc) */ for( ; fmi != ft->feats.end() ; fmi++) { Feat* f = &((*fmi).second); Feat* fp = parentFeat(f); assert(fp); int fc = f->cnt(); int fpc = fp->cnt(); float val = logLcomp(fc, ftc, fpc, ftpc); //cerr << "lcomp " << *f << " = " << val << endl; ans += val; } return ans; }
void initFeatVals() { FeatIter fi(features); int m, i; Feat* f; for( ; fi.alive() ; fi.next() ) { f = fi.curr; int fhij = f->cnt(); assert(fhij > 0); int hij = f->toTree()->count; assert(hij > 0); assert(hij >= fhij); Feat* fj = parentFeat(f); int hj, fhj; if(fj) { hj = fj->toTree()->count; fhj = fj->cnt(); } else { fhj = 1; hj = 1; // this sets val to fhij/hij; //hj=FeatureTree::totCaboveMin[whichInt][Feature::assumedFeatVal]+1; } assert(hj > 0); assert(fhj > 0); assert(hj >= fhj); //float val = (float)(fhij * hj)/(float)(fhj * hij); float val = ((float)fhij/(float)hij); fi.curr->g() = val; //cerr << *(f->toTree()) << " " << f->ind() // << " " << val << endl; if(!(val > 0)) { cerr << fhij << " " << hj << " " << fhj << " " << hij << endl; assert(val > 0); } } }