void initialize() { // scan the matrix in bottom up order CYKTable< std::list<Pos> > ch(sz_); for (uint j=1; j!=sz_; ++j) { for (uint i=j-1; ; --i) { //std::cout << pf(i+1,j+1) << std::endl; if (bpm_(i+1,j+1)>=th_) { #if 0 std::back_insert_iterator< std::list<Pos> > ii(bp_(i,j)); std::copy(ch(i+1,j-1).begin(), ch(i+1,j-1).end(), ii); #else std::swap(bp_(i,j),ch(i+1,j-1)); #endif ch(i,j).push_back(Pos(i,j)); head_[i].push_back(Pos(i,j)); } else { std::back_insert_iterator< std::list<Pos> > ii(ch(i,j)); std::remove_copy_if(ch(i+1,j).begin(), ch(i+1,j).end(), ii, std::bind1st(is_child(), head_[i].back())); std::copy(head_[i].begin(), head_[i].end(), ii); } if (i==0) break; } } vt_.fill(static_cast<uint>(-1)); }
void FoldingEngine<SEQ>:: compute_expected_accuracy(const std::string& paren, double& sen, double& ppv, double& mcc) const { std::vector< std::pair<int, int> > BP; std::vector<int> st; for (uint n=0; n<paren.size(); ++n) { const char c = paren[n]; if (c == '(') { st.push_back (n); } else if (c == ')') { int left = st.back(); st.pop_back(); BP.push_back ( std::make_pair<int, int>(left, n) ); } } assert (st.size()==0); int L = paren.size (); int L2 = L*(L-1)/2; int N = BP.size(); double sump = 0.0; double etp = 0.0; if (bp_.size() != paren.size()) std::cerr << bp_.size() << "!=" << paren.size() << std::endl << paren << std::endl;; assert (bp_.size()==paren.size()); for (uint i=0; i<bp_.size(); ++i) { for (uint j = i+1; j<bp_.size(); ++j) { double p = bp_(i,j); sump += p; } } for (std::vector<std::pair<int, int> >::const_iterator it=BP.begin(); it != BP.end(); ++it) { etp += bp_(it->first, it->second); } double etn = L2 - N - sump + etp; double efp = N - etp; double efn = sump - etp; sen = ppv = mcc = 0; if (etp+efn!=0) sen = etp / (etp + efn); if (etp+efp!=0) ppv = etp / (etp + efp); if (etp+efp!=0 && etp+efn!=0 && etn+efp!=0 && etn+efn!=0) mcc = (etp*etn-efp*efn) / std::sqrt((etp+efp)*(etp+efn)*(etn+efp)*(etn+efn)); }
void operator()(uint i, uint j) { dp_(i,j).val = -1e100; // rule type E: X -> epsilon if (i==j) { dp_(i,j).update(0.0, Rule::E); } else { // rule type L: X -> a Y if (i+1<=j) { value_type v = dp_(i+1,j).val + q_[i]; dp_(i,j).update(v, Rule::L); } // rule type R: X -> Y a if (i<=j-1) { value_type v = dp_(i,j-1).val + q_[j-1]; dp_(i,j).update(v, Rule::R); } // rule type P: X -> a Y b if (min_loop_+i+1<=j-1) { value_type v = dp_(i+1,j-1).val + 2*gamma_*bp_(i,j-1); dp_(i,j).update(v, Rule::P); } // rule type B: X -> Y Z for (uint k=i+1; k<j; ++k) { value_type v = dp_(i,k).val + dp_(k,j).val; dp_(i,j).update(v, Rule::B, k); } } assert(dp_(i,j).type!=static_cast<Rule::type_t>(-1)); }
uint build_helper(std::vector<Node>& tree, const Pos& pos) { // parse nodes in the depth first order if (vt_(pos.first, pos.second)==static_cast<uint>(-1)) { if (pos.first==pos.second) { make_leaf(tree, pos); } else if (bp_(pos).empty()) { make_loop(tree, pos); } else { make_stem(tree, pos); } } return vt_(pos.first, pos.second); }
void make_stem(std::vector<Node>& tree, const Pos& pos) { const std::list<Pos>& cur = bp_(pos); std::list<DAG::bp_freq_t> bp_freq; bp_profile(pos.first, pos.second, bp_freq); float n_w = loop_profile(pos.first) * loop_profile(pos.second); Node node(pos, n_w, bp_freq, cur.size()); std::list<Pos>::const_iterator x; uint i; for (x=cur.begin(), i=0; x!=cur.end(); ++x, ++i) { uint ret = build_helper(tree, *x); float e_w = 1.0; //edge_score(pos, *x); node[i] = Edge(ret, pos, *x, e_w); } tree.push_back(node); vt_(pos)=tree.size()-1; }