67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include <args.hxx>
|
|
|
|
#include "common.hh"
|
|
|
|
|
|
namespace param {
|
|
using namespace ::args;
|
|
|
|
ArgumentParser parser {
|
|
"converter: alter-probability matrix -> feature probability matrix"
|
|
};
|
|
HelpFlag help {
|
|
parser, "help", "display this menu", {'h', "help"},
|
|
};
|
|
|
|
ValueFlag<std::string> smap {
|
|
parser, "path", "step map file path", {"smap"},
|
|
};
|
|
ValueFlag<std::string> fmap {
|
|
parser, "path", "feature map file path", {"fmap"},
|
|
};
|
|
|
|
} // namespace param
|
|
|
|
|
|
static void Exec() {
|
|
const auto aprobs = ReadMatrix<double>(std::cin);
|
|
Enforce(aprobs.size() > 0 && aprobs[0].size() > 0, "empty matrix");
|
|
|
|
std::ifstream fmap_st {args::get(param::fmap)};
|
|
Enforce(!!fmap_st, "fmap path is invalid");
|
|
const auto fmap = ReadMatrix<uint32_t>(fmap_st);
|
|
Enforce(fmap.size() > 0, "empty fmap");
|
|
for (auto& idxs : fmap) {
|
|
Enforce(idxs.size() > 0, "fmap has empty item");
|
|
}
|
|
|
|
for (size_t t = 0; t < aprobs.size(); ++t) {
|
|
Enforce(aprobs[t].size() <= fmap.size(), "unmatched aprobs and fmap");
|
|
for (size_t c = 0; c < fmap.size(); ++c) {
|
|
double sum = 0;
|
|
for (auto i : fmap[c]) {
|
|
sum += aprobs[t][i];
|
|
}
|
|
std::cout << sum / fmap[c].size() << ' ';
|
|
}
|
|
std::cout << '\n';
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
try {
|
|
param::parser.ParseCLI(argc, argv);
|
|
Exec();
|
|
return EXIT_SUCCESS;
|
|
} catch (const args::Help&) {
|
|
std::cout << param::parser << std::endl;
|
|
return EXIT_SUCCESS;
|
|
} catch (const std::exception& e) {
|
|
std::cerr << e.what() << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|