DomainSet consensusDomains(WeightedDomainEnsemble& dEnsemble) { using PersistenceMap = map<Domain, double>; PersistenceMap pmap; for (auto dSetIdx : boost::irange(size_t{0}, dEnsemble.domainSets.size())) { auto& dSet = dEnsemble.domainSets[dSetIdx]; auto weight = dEnsemble.weights[dSetIdx]; for (auto& domain : dSet) { if ( pmap.find(domain) == pmap.end() ) pmap[domain] = 0; pmap[domain] += weight; } } Intervals ivals; for (auto domainPersistence : pmap) { auto domain = domainPersistence.first; auto persistence = domainPersistence.second; ivals.push_back(WeightedInterval(domain.start, domain.end, persistence)); } IntervalScheduler scheduler(ivals); scheduler.computeSchedule(); DomainSet dSet; for (auto ival : scheduler.extractIntervals()) { dSet.push_back(Domain(ival.start, ival.end)); } sort(dSet.begin(), dSet.end()); return dSet; }
IntervalScheduler::IntervalScheduler(Intervals &inputIntervals) : n(inputIntervals.size()), bestGeneScore(vector<double>(n+1, 0)), p(vector<size_t>(n+1, 0)) { sort(inputIntervals.begin(), inputIntervals.end()); // We want the gene list to start at index 1 ivals.push_back(WeightedInterval(-1,-1,-1)); for (auto i : inputIntervals) ivals.push_back(i); for (size_t j = 1; j < n+1; j++) { p[j] = previousDisjointInterval(j); } }