improve a calculation of feature probability
This commit is contained in:
@@ -17,9 +17,6 @@ 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"},
|
||||
};
|
||||
@@ -41,13 +38,30 @@ static void Exec() {
|
||||
|
||||
for (size_t t = 0; t < aprobs.size(); ++t) {
|
||||
const auto tidx = t % fmap.size();
|
||||
const auto bnum = aprobs[t].size();
|
||||
for (size_t c = 0; c < fmap[tidx].size(); ++c) {
|
||||
double sum = 0;
|
||||
for (auto i : fmap[tidx][c]) {
|
||||
Enforce(i < aprobs[t].size(), "aprob has no enough columns");
|
||||
sum += aprobs[t][i];
|
||||
const auto& blocks = fmap[tidx][c];
|
||||
|
||||
double positive = 0, negative = 0;
|
||||
for (uint32_t b = 0; b < aprobs[t].size(); ++b) {
|
||||
if (blocks.end() != std::find(blocks.begin(), blocks.end(), b)) {
|
||||
positive += aprobs[t][b];
|
||||
} else {
|
||||
negative += aprobs[t][b];
|
||||
}
|
||||
}
|
||||
std::cout << sum / fmap[tidx][c].size() << ' ';
|
||||
if (blocks.size() > 0) {
|
||||
positive /= blocks.size();
|
||||
} else {
|
||||
positive = 1;
|
||||
}
|
||||
if (bnum > blocks.size()) {
|
||||
negative /= bnum - blocks.size();
|
||||
} else {
|
||||
negative = 0;
|
||||
}
|
||||
const auto prob = positive * (1-negative);
|
||||
std::cout << prob << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ auto ReadTensor3(std::istream& st) noexcept {
|
||||
std::istream_iterator<T> {});
|
||||
}
|
||||
}
|
||||
if (ret.back().empty()) ret.pop_back();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ ValueFlag<uint32_t> fnum {
|
||||
|
||||
static void Exec() {
|
||||
const auto fnum = args::get(param::fnum);
|
||||
Enforce(fnum > 0, "fc-num must be greater than 0");
|
||||
Enforce(fnum > 0, "fnum must be greater than 0");
|
||||
|
||||
std::ifstream smap_st {args::get(param::smap)};
|
||||
Enforce(!!smap_st, "smap path is invalid");
|
||||
|
Reference in New Issue
Block a user