30 namespace Clustering {
34 write_fes(std::string fname, std::vector<float> fes) {
35 std::ofstream ofs(fname);
37 std::cerr <<
"error: cannot open file '" << fname <<
"'" << std::endl;
40 ofs << std::scientific;
48 write_pops(std::string fname, std::vector<std::size_t> pops) {
53 std::vector<std::size_t>
55 std::vector<std::size_t> traj;
56 std::ifstream ifs(filename);
58 std::cerr <<
"error: cannot open file '" << filename <<
"'" << std::endl;
74 std::ofstream ofs(filename);
76 std::cerr <<
"error: cannot open file '" << filename <<
"'" << std::endl;
79 for (std::size_t c: traj) {
96 unsigned int size = 256;
98 char* buf = (
char*) malloc(size *
sizeof(
char));
100 while (size <= (
unsigned int) vsnprintf(buf, size, str.c_str(), args)) {
102 buf = (
char*) realloc(buf, size *
sizeof(
char));
105 std::string result(buf);
112 return read_single_column<float>(filename);
115 std::pair<Neighborhood, Neighborhood>
119 std::ifstream ifs(fname);
121 std::cerr <<
"error: cannot open file '" << fname <<
"' for reading." << std::endl;
135 nh[i] = std::pair<std::size_t, float>(buf1, buf2);
136 nh_high_dens[i] = std::pair<std::size_t, float>(buf3, buf4);
141 return {nh, nh_high_dens};
148 std::ofstream ofs(fname);
150 auto p_hd = nh_high_dens.begin();
151 while (p != nh.end() && p_hd != nh_high_dens.end()) {
155 ofs << p->second.first <<
" " << p->second.second <<
" "
156 << p_hd->second.first <<
" " << p_hd->second.second <<
"\n";
162 std::map<std::size_t, std::size_t>
164 std::map<std::size_t, std::size_t> populations;
165 for (std::size_t state: traj) {
166 if (populations.count(state) == 0) {
167 populations[state] = 1;
169 ++populations[state];