void print(const dynamic_bitset<>& items, ostream& out) { out << "{ "; for(dynamic_bitset<>::size_type i = items.find_first(); i != items.npos; i = items.find_next(i)){ out << i << " "; } out << "} -- " << items.count() << endl; }
static std::string dumpStates(const dynamic_bitset<> &s) { std::ostringstream oss; for (size_t i = s.find_first(); i != s.npos; i = s.find_next(i)) { oss << i << " "; } return oss.str(); }
static flat_set<NFAVertex> getVertices(const dynamic_bitset<> &in, const vector<StateInfo> &info) { flat_set<NFAVertex> out; for (size_t i = in.find_first(); i != in.npos; i = in.find_next(i)) { out.insert(info[i].vertex); } return out; }
static void step(const NGHolder &g, const vector<StateInfo> &info, const dynamic_bitset<> &in, dynamic_bitset<> *out) { out->reset(); for (size_t i = in.find_first(); i != in.npos; i = in.find_next(i)) { NFAVertex u = info[i].vertex; for (auto v : adjacent_vertices_range(u, g)) { out->set(g[v].index); } } }
vector<pair<partition,unsigned> > get_Ml_partitions_and_counts(const tree_sample& sample,double l,const dynamic_bitset<>& mask) { // find the first bit int first = mask.find_first(); assert(first >= 0); if (l <= 0.0) throw myexception()<<"Consensus level must be > 0.0"; if (l > 1.0) throw myexception()<<"Consensus level must be <= 1.0"; // use a sorted list of <partition,count>, sorted by partition. typedef map<dynamic_bitset<>,p_count> container_t; container_t counts; // use a linked list of pointers to <partition,count> records. list<container_t::iterator> majority; vector<string> names = sample.names(); unsigned count = 0; for(int i=0;i<sample.trees.size();i++) { const vector<dynamic_bitset<> >& T = sample.trees[i].partitions; unsigned min_old = std::min(1+(unsigned)(l*count),count); count ++; unsigned min_new = std::min(1+(unsigned)(l*count),count); // for each partition in the next tree dynamic_bitset<> partition(names.size()); for(int b=0;b<T.size();b++) { partition = T[b]; if (not partition[first]) partition.flip(); partition &= mask; // Look up record for this partition container_t::iterator record = counts.find(partition); if (record == counts.end()) { counts.insert(container_t::value_type(partition,p_count())); record = counts.find(partition); assert(record != counts.end()); } // FIXME - we are doing the lookup twice p_count& pc = record->second; int& C2 = pc.count; int C1 = C2; if (pc.last_tree != i) { pc.last_tree=i; C2 ++; } // add the partition if it wasn't good before, but is now if ((C1==0 or C1<min_old) and C2 >= min_new) majority.push_back(record); } // for partition in the majority tree typedef list<container_t::iterator>::iterator iterator_t; for(iterator_t p = majority.begin();p != majority.end();) { if ((*p)->second.count < min_new) { iterator_t old = p; p++; majority.erase(old); } else p++; } } vector<pair<partition,unsigned> > partitions; partitions.reserve( 2*names.size() ); for(auto p : majority) { partition pi(p->first, mask); unsigned p_count = p->second.count; if (valid(pi)) partitions.push_back(pair<partition,unsigned>(pi,p_count)); } return partitions; }