void run_chromatic_sampler(graphlab::core<mrf_graph_type, gibbs_update>& core, const std::string& chromatic_results_fn, const std::vector<double>& runtimes, const bool draw_images) { // Initialize scheduler core.set_scheduler_type("chromatic"); core.set_scope_type("null"); const size_t ncpus = core.get_options().get_ncpus(); // Use fixed update function gibbs_update ufun; core.schedule_all( ufun ); double total_runtime = 0; double actual_total_runtime = 0; foreach(const double experiment_runtime, runtimes) { total_runtime += experiment_runtime; // get the experiment id size_t experiment_id = file_line_count(chromatic_results_fn); std::cout << "Running chromatic sampler experiment " << experiment_id << " for " << experiment_runtime << " seconds." << std::endl; // set the termination time core.engine().set_timeout(experiment_runtime); // Run the engine graphlab::timer timer; timer.start(); core.start(); double actual_experiment_runtime = timer.current_time(); actual_total_runtime += actual_experiment_runtime; /// ================================================================== // Compute final statistics of the mode run_statistics stats(core.graph()); stats.print(); // Save the beliefs save_beliefs(core.graph(), make_filename("chromatic_blfs_", ".tsv", experiment_id)); // // Save the current assignments save_asg(core.graph(), make_filename("chromatic_asg_", ".asg", experiment_id)); // Save the experiment std::ofstream fout(chromatic_results_fn.c_str(), std::ios::app); fout.precision(16); fout << experiment_id << '\t' << total_runtime << '\t' << actual_total_runtime << '\t' << ncpus << '\t' << stats.nsamples << '\t' << stats.nchanges << '\t' << stats.loglik << '\t' << stats.min_samples << '\t' << stats.max_samples << std::endl; fout.close(); // Plot images if desired if(draw_images) draw_mrf(experiment_id, "chromatic", core.graph()); }
void run_jtsplash_sampler(mrf_graph_type& mrf_graph, const std::string& jtsplash_results_fn, const std::vector<double>& runtimes, const bool draw_images, const splash_settings& settings) { // size_t ncpus = core.engine().get_ncpus(); // bool affinities = // core.get_engine_options().get_cpu_affinities(); // Initialize the jtsplash sampler jt_splash_sampler jtsplash_sampler(mrf_graph, settings); double total_runtime = 0; double actual_total_runtime = 0; foreach(const double experiment_runtime, runtimes) { total_runtime += experiment_runtime; // get the experiment id size_t experiment_id = file_line_count(jtsplash_results_fn); std::cout << "Running JTSplash sampler experiment " << experiment_id << " for " << experiment_runtime << " seconds." << std::endl; std::cout << "Settings: ======================" << std::endl << "Experiment: " << experiment_id << std::endl << "runtime: " << experiment_runtime << std::endl << "treesize: " << settings.max_tree_size << std::endl << "treewidth: " << settings.max_tree_width << std::endl << "treeheight: " << settings.max_tree_height << std::endl << "factorsize: " << settings.max_factor_size << std::endl << "subthreads: " << settings.subthreads << std::endl << "priorities: " << settings.priorities << std::endl << "vanish: " << settings.vanish_updates << std::endl; graphlab::timer timer; timer.start(); // run the sampler once jtsplash_sampler.sample_seconds(experiment_runtime); double actual_experiment_runtime = timer.current_time(); std::cout << "Actual Experiment Runtime:" << actual_experiment_runtime << std::endl; actual_total_runtime += actual_experiment_runtime; std::cout << "Total Experiment Runtime (actual): " << total_runtime << "(" << actual_total_runtime << ")" << std::endl; // check mrf graph for(size_t i = 0; i < mrf_graph.num_vertices(); ++i) { ASSERT_EQ(mrf_graph.vertex_data(i).tree_info.tree_id, NULL_VID); } /// ================================================================== // Compute final statistics of the mode run_statistics stats(mrf_graph); stats.print(); // Save the beliefs save_beliefs(mrf_graph, make_filename("jtsplash_blfs_", ".tsv", experiment_id)); // // Save the current assignments save_asg(mrf_graph, make_filename("jtsplash_asg_", ".asg", experiment_id)); // Save the experiment std::ofstream fout(jtsplash_results_fn.c_str(), std::ios::app); fout.precision(8); fout << experiment_id << '\t' << total_runtime << '\t' << actual_total_runtime << '\t' << settings.ntrees << '\t' << stats.nsamples << '\t' << stats.nchanges << '\t' << stats.loglik << '\t' << stats.min_samples << '\t' << stats.max_samples << '\t' << settings.max_tree_size << '\t' << settings.max_tree_width << '\t' << settings.max_factor_size << '\t' << settings.max_tree_height << '\t' << settings.subthreads << '\t' << settings.priorities << '\t' << jtsplash_sampler.total_trees() << '\t' << jtsplash_sampler.total_collisions() << '\t' << std::endl; fout.close(); // Plot images if desired if(draw_images) draw_mrf(experiment_id, "jtsplash", mrf_graph); } // end of for loop over runtimes