Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-103
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-103
2021-103
Commits
ee81de62
Commit
ee81de62
authored
Nov 25, 2021
by
Karunathilake K. K. H. - IT18152456
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
acb45ba4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
FAMS/ROC/ROCBuilders/TPRVsFPR.cs
FAMS/ROC/ROCBuilders/TPRVsFPR.cs
+96
-0
No files found.
FAMS/ROC/ROCBuilders/TPRVsFPR.cs
0 → 100644
View file @
ee81de62
/*
* Created by: Miguel Angel Medina Prez (miguel.medina.perez@gmail.com)
* Created:
* Comments by: Miguel Angel Medina Prez (miguel.medina.perez@gmail.com)
*/
using
System.Collections.Generic
;
namespace
PatternRecognition.ROC
{
/// <summary>
/// Builds ROC curve of type True Positive Rate versus False Positive Rate ROC Builder.
/// </summary>
/// <remarks>
/// <para>
/// This implementation is based on the algorithm proposed in [1].
/// </para>
/// <para>
/// References:
/// </para>
/// <para>
/// <list type="number">
/// <item>
/// T. Fawcett, "An introduction to ROC analysis," Pattern Recognition Letters, vol. 27, pp. 861-874, 2006.
/// </item>
/// </list>
/// </para>
/// </remarks>
public
class
TPRvsFPR
:
IROCBuilder
{
/// <summary>
/// Build a ROC curve from the specified matching scores and score comparer.
/// </summary>
/// <param name="positiveMatching">
/// A collection containing the matching scores of objects in the same class.
/// </param>
/// <param name="negativeMatching">
/// A collection containing the matching scores of objects in different class.
/// </param>
/// <param name="scoreComparer">
/// A comparer for matching scores.
/// </param>
/// <returns>
/// The points that compose the ROC curve.
/// </returns>
public
List
<
ROCPoint
>
BuildROC
(
ICollection
<
double
>
positiveMatching
,
ICollection
<
double
>
negativeMatching
,
IComparer
<
double
>
scoreComparer
)
{
var
matchingResults
=
new
List
<
MatchingResult
>();
foreach
(
double
d
in
positiveMatching
)
matchingResults
.
Add
(
new
MatchingResult
(
MatchingType
.
Positive
,
d
));
foreach
(
double
d
in
negativeMatching
)
matchingResults
.
Add
(
new
MatchingResult
(
MatchingType
.
Negative
,
d
));
matchingResults
.
Sort
(
new
MatchingResultComparer
()
{
ValuesComparer
=
scoreComparer
});
return
BuildROC
(
matchingResults
,
negativeMatching
.
Count
,
positiveMatching
.
Count
);
}
private
List
<
ROCPoint
>
BuildROC
(
IList
<
MatchingResult
>
sortedResults
,
int
negativeCount
,
int
positiveCount
)
{
int
fp
=
0
;
int
tp
=
0
;
var
curve
=
new
List
<
ROCPoint
>();
double
latter
=
double
.
MinValue
;
for
(
int
i
=
0
;
i
<
sortedResults
.
Count
;
i
++)
{
MatchingResult
mr
=
sortedResults
[
i
];
if
(
mr
.
ComparissonValue
!=
latter
)
{
ROCPoint
rocPoint
=
new
ROCPoint
(
100.0
*
fp
/
negativeCount
,
100.0
*
tp
/
positiveCount
,
mr
.
ComparissonValue
);
if
(
curve
.
Count
>
1
)
{
if
(
curve
[
curve
.
Count
-
2
].
x
==
rocPoint
.
x
)
curve
[
curve
.
Count
-
1
]
=
rocPoint
;
else
if
(
curve
[
curve
.
Count
-
2
].
y
==
rocPoint
.
y
)
curve
[
curve
.
Count
-
1
]
=
rocPoint
;
else
curve
.
Add
(
rocPoint
);
}
else
curve
.
Add
(
rocPoint
);
latter
=
mr
.
ComparissonValue
;
}
if
(
mr
.
Type
==
MatchingType
.
Positive
)
tp
++;
else
fp
++;
}
curve
.
Add
(
new
ROCPoint
(
100
,
curve
[
curve
.
Count
-
1
].
y
,
curve
[
curve
.
Count
-
1
].
matchingValue
));
curve
.
Add
(
new
ROCPoint
(
100
,
100
,
curve
[
curve
.
Count
-
1
].
matchingValue
));
return
curve
;
}
}
}
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