add new converter: fcode <-> fidx
This commit is contained in:
parent
0f8134edf5
commit
8239d6edc9
@ -1,12 +1,18 @@
|
||||
add_executable(dcode_fcode common.hh dcode_fcode.cc)
|
||||
target_link_libraries(dcode_fcode PRIVATE args)
|
||||
|
||||
add_executable(fcode_fidx common.hh fcode_fidx.cc)
|
||||
target_link_libraries(fcode_fidx PRIVATE args)
|
||||
|
||||
add_executable(fidx_stego common.hh fidx_stego.cc)
|
||||
target_link_libraries(fidx_stego PRIVATE args minimp4 openh264)
|
||||
|
||||
add_executable(stego_fprob common.hh stego_fprob.cc)
|
||||
target_link_libraries(stego_fprob PRIVATE args minimp4 openh264)
|
||||
|
||||
add_executable(fprob_fcprob common.hh fprob_fcprob.cc)
|
||||
target_link_libraries(fprob_fcprob PRIVATE args)
|
||||
|
||||
add_executable(fcprob_fcode common.hh fcprob_fcode.cc)
|
||||
target_link_libraries(fcprob_fcode PRIVATE args)
|
||||
|
||||
|
58
conv/fcode_fidx.cc
Normal file
58
conv/fcode_fidx.cc
Normal file
@ -0,0 +1,58 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <args.hxx>
|
||||
|
||||
#include "common.hh"
|
||||
|
||||
|
||||
namespace param {
|
||||
using namespace ::args;
|
||||
|
||||
ArgumentParser parser {
|
||||
"converter: feature codes -> feature indices"
|
||||
};
|
||||
HelpFlag help {
|
||||
parser, "help", "display this menu", {'h', "help"},
|
||||
};
|
||||
|
||||
ValueFlag<std::string> fcmap {
|
||||
parser, "path", "feature code map", {"fc-map"},
|
||||
};
|
||||
|
||||
} // namespace param
|
||||
|
||||
|
||||
static void Exec() {
|
||||
std::ifstream fcmap_st {args::get(param::fcmap)};
|
||||
Enforce(!!fcmap_st, "fcmap path is invalid");
|
||||
const auto fcmap = ReadMatrix<uint32_t>(fcmap_st);
|
||||
Enforce(fcmap.size() > 0, "empty fcmap");
|
||||
for (auto& idxs : fcmap) {
|
||||
Enforce(idxs.size() > 0, "fcmap has empty item");
|
||||
}
|
||||
|
||||
size_t fcode;
|
||||
while (std::cin >> fcode) {
|
||||
Enforce(fcode < fcmap.size(), "fcode overflow");
|
||||
|
||||
for (const auto idx : fcmap[fcode]) {
|
||||
std::cout << idx << ' ';
|
||||
}
|
||||
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;
|
||||
}
|
@ -36,11 +36,11 @@ Flag output_prob {
|
||||
|
||||
|
||||
static void Exec() {
|
||||
const auto cprobs = ReadMatrix<double>(std::cin);
|
||||
Enforce(cprobs.size() > 0 && cprobs[0].size() > 0, "empty matrix");
|
||||
const auto fprobs = ReadMatrix<double>(std::cin);
|
||||
Enforce(fprobs.size() > 0 && fprobs[0].size() > 0, "empty matrix");
|
||||
|
||||
const auto dur = cprobs.size();
|
||||
const auto n = cprobs[0].size();
|
||||
const auto dur = fprobs.size();
|
||||
const auto n = fprobs[0].size();
|
||||
|
||||
std::ifstream smap_st {args::get(param::smap)};
|
||||
Enforce(!!smap_st, "smap path is invalid");
|
||||
@ -53,16 +53,16 @@ static void Exec() {
|
||||
};
|
||||
std::vector<Step> steps((dur+1)*n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
steps[i].prob = cprobs[0][i];
|
||||
steps[i].prob = fprobs[0][i];
|
||||
}
|
||||
for (size_t t = 1; t < dur; ++t) {
|
||||
Enforce(cprobs[t].size() == n, "ill-formed matrix");
|
||||
Enforce(fprobs[t].size() == n, "ill-formed matrix");
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
const auto& cur = steps[(t-1)*n + i];
|
||||
for (auto j : smap[(t-1)*n+i]) {
|
||||
auto& next = steps[t*n + j];
|
||||
|
||||
const auto sum = cur.prob + cprobs[t][j];
|
||||
const auto sum = cur.prob + fprobs[t][j];
|
||||
if (next.prob < sum) {
|
||||
next.prob = sum;
|
||||
next.from = i;
|
||||
|
66
conv/fprob_fcprob.cc
Normal file
66
conv/fprob_fcprob.cc
Normal file
@ -0,0 +1,66 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <args.hxx>
|
||||
|
||||
#include "common.hh"
|
||||
|
||||
|
||||
namespace param {
|
||||
using namespace ::args;
|
||||
|
||||
ArgumentParser parser {
|
||||
"converter: feature codes -> feature indices"
|
||||
};
|
||||
HelpFlag help {
|
||||
parser, "help", "display this menu", {'h', "help"},
|
||||
};
|
||||
|
||||
ValueFlag<std::string> smap {
|
||||
parser, "path", "step map file path", {"smap"},
|
||||
};
|
||||
ValueFlag<std::string> fcmap {
|
||||
parser, "path", "feature code map", {"fc-map"},
|
||||
};
|
||||
|
||||
} // namespace param
|
||||
|
||||
|
||||
static void Exec() {
|
||||
const auto fprobs = ReadMatrix<double>(std::cin);
|
||||
Enforce(fprobs.size() > 0 && fprobs[0].size() > 0, "empty matrix");
|
||||
|
||||
std::ifstream fcmap_st {args::get(param::fcmap)};
|
||||
Enforce(!!fcmap_st, "fcmap path is invalid");
|
||||
const auto fcmap = ReadMatrix<uint32_t>(fcmap_st);
|
||||
Enforce(fcmap.size() > 0, "empty fcmap");
|
||||
for (auto& idxs : fcmap) {
|
||||
Enforce(idxs.size() > 0, "fcmap has empty item");
|
||||
}
|
||||
|
||||
for (size_t t = 0; t < fprobs.size(); ++t) {
|
||||
Enforce(fprobs[t].size() <= fcmap.size(), "unmatched fprobs and fcmap");
|
||||
for (size_t c = 0; c < fcmap.size(); ++c) {
|
||||
double sum = 0;
|
||||
for (auto i : fcmap[c]) {
|
||||
sum += fprobs[t][i];
|
||||
}
|
||||
std::cout << sum / fcmap[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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user