Example #1
0
void run_persistence( Complex & complex, 
		      Cell_less & less, 
		      Barcode & barcode,
 		      Timer & timer,
		      const Tag tag){
   typedef ctl::Filtration< Complex, Cell_less > Filtration;
   //Boundary Operator
   //NOTE: This is not a general purpose boundary operator.
   //It works correctly only when successive 
   //boundaries are taken in a filtration order
   //typedef typename Filtration::iterator Filtration_iterator;
   typedef ctl::Filtration_boundary< Filtration> Filtration_boundary;
   typedef typename Filtration::Term Filtration_term;
   typedef typename Filtration_term::Coefficient Coefficient;

   typedef typename ctl::Sparse_matrix< Coefficient> Sparse_matrix;
   typedef typename ctl::Offset_map< typename Filtration::iterator> Offset_map;
   typedef typename ctl::Sparse_matrix_map< Coefficient, Offset_map> Chain_map;

   //produce a filtration
   timer.start();
   Filtration complex_filtration( complex);
   Filtration_boundary filtration_boundary( complex_filtration);
   timer.stop();
   double complex_filtration_time = timer.elapsed();
   //display some info
   std::cout << "time to compute complex filtration (secs): " 
             << complex_filtration_time << std::endl;
   
   //begin instantiate our vector of cascades homology
   Sparse_matrix R( complex.size());
   
   Offset_map offset_map( complex_filtration.begin());
   //we hand persistence a property map for genericity!                        
   Chain_map R_map( R.begin(), offset_map);
   timer.start();
   auto times = ctl::persistence( complex_filtration.begin(), 
				  complex_filtration.end(),
  		    		  filtration_boundary, 
				  R_map, false, offset_map);
   timer.stop();
   double boundary_map_build = times.first;
   double complex_persistence = times.second;
  std::cout << "initialize_cascade_data (complex): " 
            << boundary_map_build << std::endl;
  std::cout << "serial persistence (complex): " 
            << complex_persistence << std::endl;
  std::cout << "total time : " << timer.elapsed() << std::endl;

   ctl::compute_barcodes( complex_filtration, 
			  R_map, barcode, tag, true);
  std::vector< std::size_t> bti;
  compute_betti( complex_filtration, R_map, bti, true);
}
Example #2
0
int main( int argc, char *argv[]){
  po::variables_map vm;
  process_args( argc, argv, vm);

  //setup some variables
  std::string full_complex_name = vm[ "input-file"].as< std::string>();
  std::string complex_name( full_complex_name);
  std::string binary_name( argv[ 0]);
  std::string base_name( full_complex_name);
  std::string output_name;
  size_t found = complex_name.rfind( '/');
  if ( found != std::string::npos){
        complex_name.replace( 0, found+1, "");
  }
  found = full_complex_name.rfind('.');
   if ( found != std::string::npos){
        base_name.replace(found,full_complex_name.length(), "");
  	output_name = base_name + ".phat";
  }
  std::ofstream out(output_name.c_str());
  
  Complex complex;

  // Read the cell_set in
  ctl::read_complex( full_complex_name, complex);
 
  Complex_filtration complex_filtration( complex);


  typedef ctl::Filtration_boundary< Complex_filtration> 
				   Filtration_boundary;
  typedef Filtration_boundary::Term Filtration_term;
  typedef ctl::Chain< Filtration_term> Chain;
  std::cout << "Writing PHAT ASCII file To: " << output_name << std::endl;
  Filtration_boundary bd( complex_filtration);
  for (Complex_filtration_iterator sigma = complex_filtration.begin(); 
				   sigma != complex_filtration.end(); ++sigma){
       Chain cascade_boundary;
       cascade_boundary.reserve( bd.length( sigma));
       for( auto i = bd.begin( sigma); i != bd.end( sigma); ++i){
                  cascade_boundary.emplace( i->cell(), i->coefficient());
       }
       cascade_boundary.sort();
       out << (*sigma)->first.dimension();
       for( auto term : cascade_boundary){
       	out << " " << term.cell(); 
       }
       out << std::endl;
  }
  return 0;
}
Example #3
0
int main( int argc, char *argv[]){
  #ifdef ZOOM_PROFILE
  std::cout << "Connect" <<  ZMConnect() << std::endl;
  #endif
 
  po::variables_map vm;
  process_args( argc, argv, vm);
  size_t num_parts = atoi( vm[ "num-parts"].as< std::string>().c_str());

  //setup some variables
  std::string full_complex_name = vm[ "input-file"].as< std::string>();
  std::string complex_name( full_complex_name);
  std::string binary_name( argv[ 0]);

  size_t found = complex_name.rfind( '/');
  if ( found != std::string::npos){
        complex_name.replace( 0, found+1, "");
  }
  tbb::task_scheduler_init init;
  
  Complex complex;
  Nerve nerve;
  tbb::concurrent_vector< Complex_iterator> nearly_pure;
  Stats stats;

  // Read the cell_set in
  //read_complex( full_complex_name, complex);
  stats.timer.start();
  Complex_filtration complex_filtration( complex);
  stats.timer.stop();
  double orig_filtration_time = stats.timer.elapsed();
  std::cout << "filtered complex " << orig_filtration_time << std::endl;
  stats.timer.start();
  ctl::parallel::init_cover_complex( nerve, num_parts);
  ctl::parallel::graph_partition_open_cover( complex_filtration, nerve, nearly_pure);
  stats.timer.stop();
  double cover_time = stats.timer.elapsed();
  std::cout << "built cover." << std::endl;
  #ifdef ZOOM_PROFILE
  std::cout << "Profiling Begin";
  ZMError start_error = ZMStartSession();
  std::cout << start_error << std::endl;
  #endif 
 
  ctl::parallel::compute_homology( complex, nerve, num_parts, stats);
  #ifdef ZOOM_PROFILE
  ZMError end_error = ZMStopSession();
  std::cout << "Profiling End" << end_error << std::endl;
  #endif
  #ifdef ZOOM_PROFILE
   std::cout << "Disconnect" <<  ZMDisconnect() << std::endl;
  #endif
  double total_time = cover_time + stats.filtration_time + stats.get_iterators +
         	     stats.parallel_persistence + stats.initialize_cascade_boundary;
                  
  std::cout << std::setprecision( 2) << std::fixed;
                                                                                
  std::cout << "build cover: " << cover_time 
            << " (" << (cover_time/total_time)*100 << "%)" << std::endl;
                                                                                
  std::cout << "re-filter complex: " << stats.filtration_time 
            << " (" << (stats.filtration_time/total_time)*100 << "%)" 
            << std::endl;
  std::cout << "compute parallel ranges: " << stats.get_iterators
            << " (" << (stats.get_iterators/total_time)*100 << "%)" 
	    << std::endl;
  std::cout << "initialize_cascade_boundary: " 
            << stats.initialize_cascade_boundary << " (" 
            << (stats.initialize_cascade_boundary/total_time)*100 << "%)" << std::endl;
  std::cout << "parallel_homology: " 
            << stats.parallel_persistence << " (" 
            << (stats.parallel_persistence/total_time)*100 << "%)" << std::endl;
  std::cout << "total time: " << total_time << " (100%)" << std::endl;

#ifdef TESTS_ON
  ctl::run_tests( complex, blowup_complex, nerve);
#endif
  init.terminate();
  return 0;
}