Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
34cce6da
Commit
34cce6da
authored
Feb 11, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added roc_point and compute_roc_curve().
parent
ee0576de
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
lda.h
dlib/statistics/lda.h
+49
-0
lda_abstract.h
dlib/statistics/lda_abstract.h
+35
-0
No files found.
dlib/statistics/lda.h
View file @
34cce6da
...
...
@@ -180,6 +180,55 @@ namespace dlib
return
std
::
make_pair
((
low_error
+
high_error
)
/
2
,
thresh
);
}
// ----------------------------------------------------------------------------------------
struct
roc_point
{
double
true_positive_rate
;
double
false_positive_rate
;
double
detection_threshold
;
};
inline
std
::
vector
<
roc_point
>
compute_roc_curve
(
const
std
::
vector
<
double
>&
true_detections
,
const
std
::
vector
<
double
>&
false_detections
)
{
DLIB_CASSERT
(
true_detections
.
size
()
!=
0
);
DLIB_CASSERT
(
false_detections
.
size
()
!=
0
);
std
::
vector
<
std
::
pair
<
double
,
int
>
>
temp
;
temp
.
reserve
(
true_detections
.
size
()
+
false_detections
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
true_detections
.
size
();
++
i
)
temp
.
push_back
(
std
::
make_pair
(
true_detections
[
i
],
+
1
));
for
(
unsigned
long
i
=
0
;
i
<
false_detections
.
size
();
++
i
)
temp
.
push_back
(
std
::
make_pair
(
false_detections
[
i
],
-
1
));
std
::
sort
(
temp
.
rbegin
(),
temp
.
rend
());
std
::
vector
<
roc_point
>
roc_curve
;
roc_curve
.
reserve
(
temp
.
size
());
double
num_false_included
=
0
;
double
num_true_included
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
temp
.
size
();
++
i
)
{
if
(
temp
[
i
].
second
>
0
)
num_true_included
++
;
else
num_false_included
++
;
roc_point
p
;
p
.
true_positive_rate
=
num_true_included
/
true_detections
.
size
();
p
.
false_positive_rate
=
num_false_included
/
false_detections
.
size
();
p
.
detection_threshold
=
temp
[
i
].
first
;
roc_curve
.
push_back
(
p
);
}
return
roc_curve
;
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/statistics/lda_abstract.h
View file @
34cce6da
...
...
@@ -74,6 +74,41 @@ namespace dlib
- returns make_pair(ERR,T)
!*/
// ----------------------------------------------------------------------------------------
struct
roc_point
{
double
true_positive_rate
;
double
false_positive_rate
;
double
detection_threshold
;
};
std
::
vector
<
roc_point
>
compute_roc_curve
(
const
std
::
vector
<
double
>&
true_detections
,
const
std
::
vector
<
double
>&
false_detections
);
/*!
requires
- true_detections.size() != 0
- false_detections.size() != 0
ensures
- This function computes the ROC curve (receiver operating characteristic)
curve of the given data. Therefore, we interpret true_detections as
containing detection scores for a bunch of true detections and
false_detections as detection scores from a bunch of false detections. A
perfect detector would always give higher scores to true detections than to
false detections, resulting in a true positive rate of 1 and a false positive
rate of 0, for some appropriate detection threshold.
- Returns an array, ROC, such that:
- ROC.size() == true_detections.size()+false_detections.size()
- for all valid i:
- If you were to accept all detections with a score >= ROC[i].detection_threshold
then you would obtain a true positive rate of ROC[i].true_positive_rate and a
false positive rate of ROC[i].false_positive_rate.
- ROC is ordered such that low detection rates come first. That is, the
curve is swept from a high detection threshold to a low threshold.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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