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
439888e9
Commit
439888e9
authored
Feb 17, 2013
by
Davis King
Browse files
Made average_precision() a little more generalized.
parent
f5fe20c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
4 deletions
+45
-4
dlib/statistics/average_precision.h
dlib/statistics/average_precision.h
+19
-3
dlib/statistics/average_precision_abstract.h
dlib/statistics/average_precision_abstract.h
+26
-1
No files found.
dlib/statistics/average_precision.h
View file @
439888e9
...
...
@@ -9,16 +9,30 @@
namespace
dlib
{
inline
double
average_precision
(
const
std
::
vector
<
bool
>&
items
,
namespace
impl
{
inline
bool
get_bool_part
(
const
bool
&
b
)
{
return
b
;
}
template
<
typename
T
>
bool
get_bool_part
(
const
std
::
pair
<
T
,
bool
>&
item
)
{
return
item
.
second
;
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
alloc
>
double
average_precision
(
const
std
::
vector
<
T
,
alloc
>&
items
,
unsigned
long
missing_relevant_items
=
0
)
{
using
namespace
dlib
::
impl
;
double
precision_sum
=
0
;
double
relevant_count
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
items
.
size
();
++
i
)
{
if
(
items
[
i
])
if
(
get_bool_part
(
items
[
i
])
)
{
++
relevant_count
;
precision_sum
+=
relevant_count
/
(
i
+
1
);
...
...
@@ -33,6 +47,8 @@ namespace dlib
return
1
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_AVERAGE_PREcISION_H__
...
...
dlib/statistics/average_precision_abstract.h
View file @
439888e9
...
...
@@ -7,8 +7,14 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
alloc
>
double
average_precision
(
const
std
::
vector
<
bool
>&
items
,
const
std
::
vector
<
bool
,
alloc
>&
items
,
unsigned
long
missing_relevant_items
=
0
);
/*!
...
...
@@ -29,6 +35,25 @@ namespace dlib
is 0.5.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
alloc
>
double
average_precision
(
const
std
::
vector
<
std
::
pair
<
T
,
bool
>
,
alloc
>&
items
,
unsigned
long
missing_relevant_items
=
0
);
/*!
ensures
- this function is equivalent to copying the bool values from items into a
std::vector<bool> and then calling the above average_precision() routine on
it and returning the result.
!*/
// ----------------------------------------------------------------------------------------
}
#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