Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
d102f69a
Commit
d102f69a
authored
Feb 14, 2013
by
Davis King
Browse files
Added average_precision()
parent
8b5b6fb0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
dlib/statistics.h
dlib/statistics.h
+1
-0
dlib/statistics/average_precision.h
dlib/statistics/average_precision.h
+39
-0
dlib/statistics/average_precision_abstract.h
dlib/statistics/average_precision_abstract.h
+36
-0
No files found.
dlib/statistics.h
View file @
d102f69a
...
...
@@ -9,6 +9,7 @@
#include "statistics/image_feature_sampling.h"
#include "statistics/sammon.h"
#include "statistics/cca.h"
#include "statistics/average_precision.h"
#endif // DLIB_STATISTICs_H_
...
...
dlib/statistics/average_precision.h
0 → 100644
View file @
d102f69a
// Copyright (C) 2013 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_AVERAGE_PREcISION_H__
#define DLIB_AVERAGE_PREcISION_H__
#include "average_precision_abstract.h"
#include <vector>
namespace
dlib
{
inline
double
average_precision
(
const
std
::
vector
<
bool
>&
items
,
unsigned
long
missing_relevant_items
=
0
)
{
double
precision_sum
=
0
;
double
relevant_count
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
items
.
size
();
++
i
)
{
if
(
items
[
i
])
{
++
relevant_count
;
precision_sum
+=
relevant_count
/
(
i
+
1
);
}
}
relevant_count
+=
missing_relevant_items
;
if
(
relevant_count
!=
0
)
return
precision_sum
/
relevant_count
;
else
return
1
;
}
}
#endif // DLIB_AVERAGE_PREcISION_H__
dlib/statistics/average_precision_abstract.h
0 → 100644
View file @
d102f69a
// Copyright (C) 2013 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_AVERAGE_PREcISION_ABSTRACT_H__
#ifdef DLIB_AVERAGE_PREcISION_ABSTRACT_H__
#include <vector>
namespace
dlib
{
double
average_precision
(
const
std
::
vector
<
bool
>&
items
,
unsigned
long
missing_relevant_items
=
0
);
/*!
ensures
- Interprets items as a list of relevant and non-relevant items in a response
from an information retrieval system. In particular, items with a true value
are relevant and false items are non-relevant. This function then returns
the average precision of the ranking of the given items. For, example, the
ranking [true, true, true, true, false] would have an average precision of 1.
On the other hand, the ranking of [true false false true] would have an
average precision of 0.75 (because the first true has a precision of 1 and
the second true has a precision of 0.5, giving an average of 0.75).
- As a special case, if item contains no true elements then the average
precision is considered to be 1.
- This function will add in missing_relevant_items number of items with a
precision of zero into the average value returned. For example, the average
precision of the ranking [true, true] if there are 2 missing relevant items
is 0.5.
!*/
}
#endif // DLIB_AVERAGE_PREcISION_H__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment