Пример #1
0
	//default constructor	
	Filtration( Complex & c): filtration_( c.size()), complex_( c){
		std::size_t pos = 0;
		for( auto i= c.begin(); i != c.end(); ++i, ++pos){ 
			 filtration_[ pos] = i;
		}
		std::sort( filtration_.begin(), filtration_.end(), Less());
	}
Пример #2
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);
}
Пример #3
0
int main (int argc, char* argv[]) {
    if( argc != 5){ 	
	std::cerr << "Usage: " << argv[ 0] 
		  << " filename.dat epsilon dimension option" << std::endl;
	return 0;
    } 
    ctl::Timer clock;
    double epsilon = atof( argv[ 2]);
    std::size_t dimension = atoi( argv[ 3]);
    std::size_t option = atoi( argv[ 4]);
    if( option >= 2){
	std::cerr << "Usage: please enter a valid option:" << std::endl
		  << "0 for incremental construction," << std:: endl
		  << "1 for inductive construstion." << std::endl;
	return 0;
    }
    Points points; 
    std::ifstream in;
    ctl::open_file( in, argv[ 1]);
 
    Point point;
    double coordinate;
    std::size_t line_num = 0;
    while( true){
	std::string line;
	ctl::get_line( in, line, line_num);
	if( in.eof() ) break;
	std::stringstream ss( line);
	while( ss.good()){ 
		ss >> coordinate;
		point.push_back( coordinate);
	}
	points.push_back( point); 
	point.clear();
    }
    clock.start();
    Graph graph;
    ctl::all_pairs::construct_graph(points, epsilon, graph);
    clock.stop();
    std::cerr << "Graph: " <<  boost::num_vertices( graph) << ", "
	      << boost:: num_edges( graph) << std::endl;
    std::cerr << "Graph construction: " << clock.elapsed() << std::endl;
    clock.start();
    Complex complex; 
    if( option == 0) { ctl::incremental_vr(graph, complex, dimension);}
    else if( option == 1) { ctl::inductive_vr(graph, complex, dimension);}
    clock.stop();
    std::cerr << "Complex construction: " << clock.elapsed() << std::endl;
    std::cerr << "Number of simplices: " << complex.size() << std::endl;
    std::cerr << "dimension of complex: " << complex.dimension() << std::endl;
    return 0;	
}
Пример #4
0
int main(int argc, char *argv[]){
  std::string full_complex_name, filtration_file;
  process_args(argc, argv, full_complex_name, filtration_file);
  
  std::string barcode_file_name( full_complex_name); 
  std::size_t pos = barcode_file_name.rfind( '.');
  if( pos != std::string::npos){
	barcode_file_name.replace(pos, barcode_file_name.length(), ".bcs");
  }
  std::ofstream out; 
  ctl::open_file( out, barcode_file_name.c_str());
  //Create some data structures 
  Timer timer;
  timer.start();
  if( can_read_weights( filtration_file)){
 	ctl::Weight_data_functor< Weighted_complex> weight_functor;
	typedef typename ctl::Barcodes< double> Barcodes;
	Barcodes barcodes;
  	Weighted_complex complex;
  	ctl::read_complex_and_data( full_complex_name, filtration_file, 
				    complex, weight_functor); 
  	timer.stop();
  	std::cout << "I/O Time: " << timer.elapsed() << std::endl;
  	std::cout << "complex size: " << complex.size() << std::endl; 
  	std::cout << "complex dimension: " << complex.dimension() << std::endl;
	Complex_weight_less less;
	run_persistence( complex, less, barcodes, timer, 
			 ctl::detail::weighted_tag());
	out << barcodes << std::endl;

  }else{
	typedef typename ctl::Barcodes< double> Barcodes;
	Barcodes barcodes;
  	Complex complex;
  	ctl::read_complex( full_complex_name, complex);
  	timer.stop();
  	std::cout << "I/O Time: " << timer.elapsed() << std::endl;
	std::cout << "complex size: " << complex.size() << std::endl; 
  	std::cout << "complex dimension: " << complex.dimension() << std::endl;
	Complex_cell_less less;
  	run_persistence( complex, less, barcodes, timer, 
			 ctl::detail::non_weighted_tag());   
	out << barcodes << std::endl;
  } 
  return 0;
}
Пример #5
0
	//create a noncorrect filtration first.
	//useful if we are going to create a filtration inside another
	//algorithm
	Filtration( Complex & c, bool flag): filtration_( c.size()), 
					     complex_( c) {}