From e6e8a68c09d9dce5547ddd2401aca5db705b96ca Mon Sep 17 00:00:00 2001 From: falsycat Date: Wed, 5 Oct 2022 11:42:07 +0900 Subject: [PATCH] rename terms --- conv/CMakeLists.txt | 28 +++++------ conv/aprob_fprob.cc | 66 +++++++++++++++++++++++++ conv/{bidx_stego.cc => block_stego.cc} | 0 conv/{dcode_fcode.cc => dcode_feat.cc} | 22 ++++----- conv/{fcode_bidx.cc => feat_block.cc} | 26 +++++----- conv/{fcode_dcode.cc => feat_dcode.cc} | 24 ++++----- conv/fprob_fcprob.cc | 66 ------------------------- conv/{fcprob_fcode.cc => fprob_feat.cc} | 2 +- conv/{stego_fprob.cc => stego_aprob.cc} | 2 +- sh/fidx_random.sh | 15 ------ sh/fprob_calc.sh | 55 --------------------- 11 files changed, 118 insertions(+), 188 deletions(-) create mode 100644 conv/aprob_fprob.cc rename conv/{bidx_stego.cc => block_stego.cc} (100%) rename conv/{dcode_fcode.cc => dcode_feat.cc} (70%) rename conv/{fcode_bidx.cc => feat_block.cc} (55%) rename conv/{fcode_dcode.cc => feat_dcode.cc} (70%) delete mode 100644 conv/fprob_fcprob.cc rename conv/{fcprob_fcode.cc => fprob_feat.cc} (97%) rename conv/{stego_fprob.cc => stego_aprob.cc} (99%) delete mode 100755 sh/fidx_random.sh delete mode 100755 sh/fprob_calc.sh diff --git a/conv/CMakeLists.txt b/conv/CMakeLists.txt index 8833b49..9168c6d 100644 --- a/conv/CMakeLists.txt +++ b/conv/CMakeLists.txt @@ -1,20 +1,20 @@ -add_executable(dcode_fcode common.hh dcode_fcode.cc) -target_link_libraries(dcode_fcode PRIVATE args) +add_executable(dcode_feat common.hh dcode_feat.cc) +target_link_libraries(dcode_feat PRIVATE args) -add_executable(fcode_bidx common.hh fcode_bidx.cc) -target_link_libraries(fcode_bidx PRIVATE args) +add_executable(feat_block common.hh feat_block.cc) +target_link_libraries(feat_block PRIVATE args) -add_executable(bidx_stego common.hh bidx_stego.cc) -target_link_libraries(bidx_stego PRIVATE args minimp4 openh264) +add_executable(block_stego common.hh block_stego.cc) +target_link_libraries(block_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(stego_aprob common.hh stego_aprob.cc) +target_link_libraries(stego_aprob PRIVATE args minimp4 openh264) -add_executable(fprob_fcprob common.hh fprob_fcprob.cc) -target_link_libraries(fprob_fcprob PRIVATE args) +add_executable(aprob_fprob common.hh aprob_fprob.cc) +target_link_libraries(aprob_fprob PRIVATE args) -add_executable(fcprob_fcode common.hh fcprob_fcode.cc) -target_link_libraries(fcprob_fcode PRIVATE args) +add_executable(fprob_feat common.hh fprob_feat.cc) +target_link_libraries(fprob_feat PRIVATE args) -add_executable(fcode_dcode common.hh fcode_dcode.cc) -target_link_libraries(fcode_dcode PRIVATE args) +add_executable(feat_dcode common.hh feat_dcode.cc) +target_link_libraries(feat_dcode PRIVATE args) diff --git a/conv/aprob_fprob.cc b/conv/aprob_fprob.cc new file mode 100644 index 0000000..d30b627 --- /dev/null +++ b/conv/aprob_fprob.cc @@ -0,0 +1,66 @@ +#include +#include +#include + +#include + +#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 smap { + parser, "path", "step map file path", {"smap"}, +}; +ValueFlag fmap { + parser, "path", "feature map file path", {"fmap"}, +}; + +} // namespace param + + +static void Exec() { + const auto aprobs = ReadMatrix(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(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; +} diff --git a/conv/bidx_stego.cc b/conv/block_stego.cc similarity index 100% rename from conv/bidx_stego.cc rename to conv/block_stego.cc diff --git a/conv/dcode_fcode.cc b/conv/dcode_feat.cc similarity index 70% rename from conv/dcode_fcode.cc rename to conv/dcode_feat.cc index 35eff0a..bb9430c 100644 --- a/conv/dcode_fcode.cc +++ b/conv/dcode_feat.cc @@ -11,7 +11,7 @@ namespace param { using namespace ::args; ArgumentParser parser { - "converter: feature code probability matrix -> feature code" + "converter: data code -> feature" }; HelpFlag help { parser, "help", "display this menu", {'h', "help"}, @@ -22,18 +22,18 @@ ValueFlag smap { }; ValueFlag first { - parser, "0", "first fcode", {"first"}, 0 + parser, "0", "first feature", {"first"}, 0 }; -ValueFlag fcnum { - parser, "50", "number of fcode alphabet", {"fc-num"}, 50 +ValueFlag fnum { + parser, "50", "number of feature kinds", {"fnum"}, 50 }; } // namespace param static void Exec() { - const auto fcnum = args::get(param::fcnum); - Enforce(fcnum > 0, "fc-num must be greater than 0"); + const auto fnum = args::get(param::fnum); + Enforce(fnum > 0, "fnum must be greater than 0"); std::ifstream smap_st {args::get(param::smap)}; Enforce(!!smap_st, "smap path is invalid"); @@ -45,14 +45,14 @@ static void Exec() { Enforce(br.size() == bn, "all node should have the same number of branch"); } - uint32_t fcode = args::get(param::first); - std::cout << fcode << '\n'; + uint32_t feat = args::get(param::first); + std::cout << feat << '\n'; for (uint32_t dcode, t = 0; std::cin >> dcode; ++t) { Enforce(dcode < bn, "dcode must be lower than number of branch"); - Enforce(fcnum*(t+1) <= smap.size(), "smap row shortage"); - fcode = smap[t*fcnum + fcode][dcode]; - std::cout << fcode << '\n'; + Enforce(fnum*(t+1) <= smap.size(), "smap row shortage"); + feat = smap[t*fnum + feat][dcode]; + std::cout << feat << '\n'; } } diff --git a/conv/fcode_bidx.cc b/conv/feat_block.cc similarity index 55% rename from conv/fcode_bidx.cc rename to conv/feat_block.cc index b9fb03c..60af16d 100644 --- a/conv/fcode_bidx.cc +++ b/conv/feat_block.cc @@ -11,33 +11,33 @@ namespace param { using namespace ::args; ArgumentParser parser { - "converter: feature codes -> block indices" + "converter: feature -> block" }; HelpFlag help { parser, "help", "display this menu", {'h', "help"}, }; -ValueFlag fcmap { - parser, "path", "feature code map", {"fc-map"}, +ValueFlag fmap { + parser, "path", "path to feature map", {"fmap"}, }; } // namespace param static void Exec() { - std::ifstream fcmap_st {args::get(param::fcmap)}; - Enforce(!!fcmap_st, "fcmap path is invalid"); - const auto fcmap = ReadMatrix(fcmap_st); - Enforce(fcmap.size() > 0, "empty fcmap"); - for (auto& idxs : fcmap) { - Enforce(idxs.size() > 0, "fcmap has empty item"); + std::ifstream fmap_st {args::get(param::fmap)}; + Enforce(!!fmap_st, "fmap path is invalid"); + const auto fmap = ReadMatrix(fmap_st); + Enforce(fmap.size() > 0, "empty fmap"); + for (auto& idxs : fmap) { + Enforce(idxs.size() > 0, "fmap has empty item"); } - size_t fcode; - while (std::cin >> fcode) { - Enforce(fcode < fcmap.size(), "fcode overflow"); + size_t feat; + while (std::cin >> feat) { + Enforce(feat < fmap.size(), "feat overflow"); - for (const auto idx : fcmap[fcode]) { + for (const auto idx : fmap[feat]) { std::cout << idx << ' '; } std::cout << '\n'; diff --git a/conv/fcode_dcode.cc b/conv/feat_dcode.cc similarity index 70% rename from conv/fcode_dcode.cc rename to conv/feat_dcode.cc index 86aa3cd..354bec6 100644 --- a/conv/fcode_dcode.cc +++ b/conv/feat_dcode.cc @@ -21,16 +21,16 @@ ValueFlag smap { parser, "path", "step map file path", {"smap"}, }; -ValueFlag fcnum { - parser, "50", "number of fcode alphabet", {"fc-num"}, 50 +ValueFlag fnum { + parser, "50", "number of feature kinds", {"fnum"}, 50 }; } // namespace param static void Exec() { - const auto fcnum = args::get(param::fcnum); - Enforce(fcnum > 0, "fc-num must be greater than 0"); + const auto fnum = args::get(param::fnum); + Enforce(fnum > 0, "fc-num must be greater than 0"); std::ifstream smap_st {args::get(param::smap)}; Enforce(!!smap_st, "smap path is invalid"); @@ -42,17 +42,17 @@ static void Exec() { Enforce(br.size() == bn, "all node should have the same number of branch"); } - size_t fcode_p; - std::cin >> fcode_p; - for (uint32_t fcode, t = 0; std::cin >> fcode; ++t) { - Enforce(fcode < fcnum, "fcode overflow"); - Enforce(fcnum*(t+1) <= smap.size(), "smap row shortage"); + size_t feat_p; + std::cin >> feat_p; + for (uint32_t feat, t = 0; std::cin >> feat; ++t) { + Enforce(feat < fnum, "feat overflow"); + Enforce(fnum*(t+1) <= smap.size(), "smap row shortage"); - const auto& row = smap[t*fcnum + fcode_p]; - auto itr = std::find(row.begin(), row.end(), fcode); + const auto& row = smap[t*fnum + feat_p]; + auto itr = std::find(row.begin(), row.end(), feat); Enforce(itr != row.end(), "invalid step detected"); std::cout << std::distance(row.begin(), itr) << '\n'; - fcode_p = fcode; + feat_p = feat; } } diff --git a/conv/fprob_fcprob.cc b/conv/fprob_fcprob.cc deleted file mode 100644 index 3e4320a..0000000 --- a/conv/fprob_fcprob.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include - -#include - -#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 smap { - parser, "path", "step map file path", {"smap"}, -}; -ValueFlag fcmap { - parser, "path", "feature code map", {"fc-map"}, -}; - -} // namespace param - - -static void Exec() { - const auto fprobs = ReadMatrix(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(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; -} diff --git a/conv/fcprob_fcode.cc b/conv/fprob_feat.cc similarity index 97% rename from conv/fcprob_fcode.cc rename to conv/fprob_feat.cc index 49c839a..8c1f936 100644 --- a/conv/fcprob_fcode.cc +++ b/conv/fprob_feat.cc @@ -18,7 +18,7 @@ namespace param { using namespace ::args; ArgumentParser parser { - "converter: feature code probability matrix -> feature code" + "converter: feature probability matrix -> feature series" }; HelpFlag help { parser, "help", "display this menu", {'h', "help"}, diff --git a/conv/stego_fprob.cc b/conv/stego_aprob.cc similarity index 99% rename from conv/stego_fprob.cc rename to conv/stego_aprob.cc index 413e736..0cfbe3f 100644 --- a/conv/stego_fprob.cc +++ b/conv/stego_aprob.cc @@ -20,7 +20,7 @@ namespace param { using namespace ::args; ArgumentParser parser { - "converter: stego -> feature probability matrix" + "converter: stego -> alter-probability matrix" }; HelpFlag help { parser, "help", "display this menu", {'h', "help"}, diff --git a/sh/fidx_random.sh b/sh/fidx_random.sh deleted file mode 100755 index bcdc131..0000000 --- a/sh/fidx_random.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# generate random feature indices - -row=$1 -col=$2 -max=$3 - -for ((y = 0; y < row; ++y)); do - n=$((RANDOM%col + 1)) - for ((x = 0; x < n; ++x)); do - printf "$((RANDOM%max)) " - done - printf "\n" -done diff --git a/sh/fprob_calc.sh b/sh/fprob_calc.sh deleted file mode 100755 index 35a2e2f..0000000 --- a/sh/fprob_calc.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# calculate fprob from indices and fprob matrix -# output: average feature's feature probability and average non-feature's feature probability - -bidx=$1 -fprob=$2 -n=$3 - -script=$(cat - <