示例#1
0
文件: diag.cpp 项目: ramja/TDA-1
inline Rcpp::List
RipsDiagArbitDionysusPhat(const RealMatrix  & X
                        , const int           maxdimension
                        , const double        maxscale
                        , const std::string & library
                        , const bool          location
                        , const bool          printProgress
	) {
	std::vector< std::vector< std::vector< double > > > persDgm;
	std::vector< std::vector< std::vector< unsigned > > > persLoc;
	std::vector< std::vector< std::vector< std::vector< unsigned > > > > persCycle;

	PointContainer points = RcppToStl< PointContainer >(X, true);
	//read_points2(infilename, points);

	PairDistancesA           distances(points);
	GeneratorA               rips(distances);
	GeneratorA::Evaluator    size(distances);
	FltrRA                   f;

	// Generate 2-skeleton of the Rips complex for epsilon = 50
	rips.generate(maxdimension + 1, maxscale, make_push_back_functor(f));

	if (printProgress) {
		Rprintf("# Generated complex of size: %d \n", f.size());
	}

	// Sort the simplices with respect to distance 
	f.sort(GeneratorA::Comparison(distances));

	// Compute the persistence diagram of the complex
	if (library[0] == 'D') {
		computePersistenceDionysus< PersistenceR >(f, size, maxdimension,
				Rcpp::NumericVector(X.nrow()), location, printProgress,
				persDgm, persLoc, persCycle);
	}
	if (library[0] == 'P') {
		computePersistencePhat(f, size, maxdimension,
				Rcpp::NumericVector(X.nrow()), location, printProgress,
				persDgm, persLoc);
	}

	// Output persistent diagram
	return Rcpp::List::create(
			concatStlToRcpp< Rcpp::NumericMatrix >(persDgm, true, 3),
			concatStlToRcpp< Rcpp::NumericMatrix >(persLoc, false, 2),
			StlToRcppMatrixList< Rcpp::List, Rcpp::NumericMatrix >(persCycle));
}