1 #include "AveragePrecision.h" 6 float getAveragePrecision(
const vec_byte_t &predictions,
const vec_float_t &potentials,
const vec_byte_t >, byte state)
9 DGM_ASSERT(predictions.size() == potentials.size());
10 DGM_ASSERT(predictions.size() == gt.size());
12 std::vector<std::tuple<byte, float, byte>> container;
13 for (
size_t i = 0; i < predictions.size(); i++)
14 container.push_back(std::make_tuple(predictions[i], potentials[i], gt[i]));
16 std::sort(container.begin(), container.end(), [](
auto const &left,
auto const &right) {
return std::get<1>(left) > std::get<1>(right); });
20 int nCoincidences = 0;
22 for (
auto &c : container) {
24 if (std::get<2>(c) == state) {
26 if (std::get<0>(c) == state) {
28 res +=
static_cast<float>(nCoincidences) / i;
33 DGM_IF_WARNING(nRelevants == 0,
"There are no states <state> in <gt>");
35 if (nRelevants > 0) res /= nRelevants;
float getAveragePrecision(const vec_byte_t &predictions, const vec_float_t &potentials, const vec_byte_t >, byte state)
Returns Average Precision for the selected state (class) state.