MCPcopy Create free account
hub / github.com/davisking/dlib / average_precision

Function average_precision

dlib/statistics/average_precision.h:25–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24 template <typename T, typename alloc>
25 double average_precision (
26 const std::vector<T,alloc>& items,
27 unsigned long missing_relevant_items = 0
28 )
29 {
30 using namespace dlib::impl;
31 double relevant_count = 0;
32 // find the precision values
33 std::vector<double> precision;
34 for (unsigned long i = 0; i < items.size(); ++i)
35 {
36 if (get_bool_part(items[i]))
37 {
38 ++relevant_count;
39 precision.push_back(relevant_count / (i+1));
40 }
41 }
42
43 double precision_sum = 0;
44 double max_val = 0;
45 // now sum over the interpolated precision values
46 for (std::vector<double>::reverse_iterator i = precision.rbegin(); i != precision.rend(); ++i)
47 {
48 max_val = std::max(max_val, *i);
49 precision_sum += max_val;
50 }
51
52
53 relevant_count += missing_relevant_items;
54
55 if (relevant_count != 0)
56 return precision_sum/relevant_count;
57 else
58 return 1;
59 }
60
61// ----------------------------------------------------------------------------------------
62

Callers 7

test_ranking_functionFunction · 0.85
mainFunction · 0.85

Calls 6

get_bool_partFunction · 0.85
rbeginMethod · 0.80
rendMethod · 0.80
maxFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by 4

test_ranking_functionFunction · 0.68