/* ************************************************************************* */ void runLargeExample() { Scheduler scheduler = largeExample(); scheduler.print(); // BUILD THE GRAPH ! size_t addMutex = 2; scheduler.buildGraph(addMutex); // Do brute force product and output that to file if (scheduler.nrStudents() == 1) { // otherwise too slow DecisionTreeFactor product = scheduler.product(); product.dot("scheduling-large", false); } // Do exact inference // SETDEBUG("timing-verbose", true); SETDEBUG("DiscreteConditional::DiscreteConditional", true); gttic(large); DiscreteFactor::sharedValues MPE = scheduler.optimalAssignment(); gttoc(large); tictoc_finishedIteration(); tictoc_print(); scheduler.printAssignment(MPE); }
/* ************************************************************************* */ std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> // EliminateDiscrete(const DiscreteFactorGraph& factors, const Ordering& frontalKeys) { // PRODUCT: multiply all factors gttic(product); DecisionTreeFactor product; BOOST_FOREACH(const DiscreteFactor::shared_ptr& factor, factors) product = (*factor) * product; gttoc(product); // sum out frontals, this is the factor on the separator gttic(sum); DecisionTreeFactor::shared_ptr sum = product.sum(frontalKeys); gttoc(sum); // Ordering keys for the conditional so that frontalKeys are really in front Ordering orderedKeys; orderedKeys.insert(orderedKeys.end(), frontalKeys.begin(), frontalKeys.end()); orderedKeys.insert(orderedKeys.end(), sum->keys().begin(), sum->keys().end()); // now divide product/sum to get conditional gttic(divide); DiscreteConditional::shared_ptr cond(new DiscreteConditional(product, *sum, orderedKeys)); gttoc(divide); return std::make_pair(cond, sum); }
/* ************************************************************************* */ void runLargeExample() { Scheduler scheduler = largeExample(); scheduler.print(); // BUILD THE GRAPH ! size_t addMutex = 3; // SETDEBUG("Scheduler::buildGraph", true); scheduler.buildGraph(addMutex); // Do brute force product and output that to file if (scheduler.nrStudents() == 1) { // otherwise too slow DecisionTreeFactor product = scheduler.product(); product.dot("scheduling-large", false); } // Do exact inference // SETDEBUG("timing-verbose", true); SETDEBUG("DiscreteConditional::DiscreteConditional", true); #define SAMPLE #ifdef SAMPLE tic(2, "large"); DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate(); toc(2, "large"); tictoc_finishedIteration(); tictoc_print(); for (size_t i=0;i<100;i++) { DiscreteFactor::sharedValues assignment = sample(*chordal); vector<size_t> stats(scheduler.nrFaculty()); scheduler.accumulateStats(assignment, stats); size_t max = *max_element(stats.begin(), stats.end()); size_t min = *min_element(stats.begin(), stats.end()); size_t nz = count_if(stats.begin(), stats.end(), NonZero); // cout << min << ", " << max << ", " << nz << endl; if (nz >= 13 && min >=1 && max <= 4) { cout << "======================================================\n"; scheduler.printAssignment(assignment); } } #else tic(2, "large"); DiscreteFactor::sharedValues MPE = scheduler.optimalAssignment(); toc(2, "large"); tictoc_finishedIteration(); tictoc_print(); scheduler.printAssignment(MPE); #endif }
/* ************************************************************************* */ std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> // EliminateDiscrete(const FactorGraph<DiscreteFactor>& factors, size_t num) { // PRODUCT: multiply all factors gttic(product); DecisionTreeFactor product; BOOST_FOREACH(const DiscreteFactor::shared_ptr& factor, factors) product = (*factor) * product; gttoc(product); // sum out frontals, this is the factor on the separator gttic(sum); DecisionTreeFactor::shared_ptr sum = product.sum(num); gttoc(sum); // now divide product/sum to get conditional gttic(divide); DiscreteConditional::shared_ptr cond(new DiscreteConditional(product, *sum)); gttoc(divide); return std::make_pair(cond, sum); }