Ejemplo n.º 1
0
 run_statistics(const mrf_graph_type& mrf) :
   nsamples(0), nchanges(0), loglik(0.0),
   min_samples(std::numeric_limits<size_t>::max()), max_samples(0){
   // Compute the unnormalized log likelihood
   loglik = unnormalized_loglikelihood(mrf);
   for(vertex_id_t vid = 0; vid < mrf.num_vertices(); ++vid) {
     const mrf_vertex_data& vdata = mrf.vertex_data(vid);
     nsamples += vdata.nsamples;
     nchanges += vdata.nchanges;
     min_samples = std::min(min_samples, vdata.nsamples);
     max_samples = std::max(max_samples, vdata.nsamples);
   } // end of for loop
 } // end of compute run statistics
Ejemplo n.º 2
0
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