rename terms

This commit is contained in:
falsycat 2022-10-05 11:42:07 +09:00
parent 662c86234f
commit e6e8a68c09
11 changed files with 118 additions and 188 deletions

View File

@ -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)

66
conv/aprob_fprob.cc Normal file
View 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: 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;
}

View File

@ -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<std::string> smap {
};
ValueFlag<uint32_t> first {
parser, "0", "first fcode", {"first"}, 0
parser, "0", "first feature", {"first"}, 0
};
ValueFlag<uint32_t> fcnum {
parser, "50", "number of fcode alphabet", {"fc-num"}, 50
ValueFlag<uint32_t> 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';
}
}

View File

@ -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<std::string> fcmap {
parser, "path", "feature code map", {"fc-map"},
ValueFlag<std::string> 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<uint32_t>(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<uint32_t>(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';

View File

@ -21,16 +21,16 @@ ValueFlag<std::string> smap {
parser, "path", "step map file path", {"smap"},
};
ValueFlag<uint32_t> fcnum {
parser, "50", "number of fcode alphabet", {"fc-num"}, 50
ValueFlag<uint32_t> 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;
}
}

View File

@ -1,66 +0,0 @@
#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;
}

View File

@ -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"},

View File

@ -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"},

View File

@ -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

View File

@ -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 - <<EOS
BEGIN {
type = 0; # 0: bidx, 1: fprob
nprob = 0;
nprob_max = 0;
pprob = 0;
pprob_max = 0;
}
{
if (type == 0) {
split("", feats);
for (i = 1; i <= NF; ++i) {
feats[i] = \$i;
}
type = 1;
} else if (type == 1) {
sum = 0;
for (i = 1; i <= NF; ++i) {
sum += \$i;
}
lprob = 0;
for (i = 1; i <= length(feats); ++i) {
lprob += \$(feats[i]+1);
}
nprob += sum-lprob;
pprob += lprob;
nprob_max += NF-length(feats)
pprob_max += length(feats)
type = 0;
}
}
END {
print pprob/pprob_max, nprob/nprob_max;
}
EOS
)
paste -d "\n" $bidx $fprob | head -n$((n*2)) | awk "$script"