Skip to content

Commit

Permalink
Modified ROCPlot to take Automatic ROC Parameter argument. Extended t…
Browse files Browse the repository at this point in the history
…he signatures of ROCPlot and changed the usage message the accordingly.
  • Loading branch information
antononcube committed Mar 17, 2018
1 parent 0b88940 commit 35d7555
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions ROCFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ two labels lists (actual and predicted) into an Association that can be used as
ROCPlot takes all options of Graphics and additional options for \
ROC points size, color, callouts, tooltips, and joining. \
The allowed signatures are: \
\nROCPlot[ parVals:{_?NumericQ..}, aROCs:{_?ROCAssociationQ..}, opts]
\nROCPlot[ xFuncName_String, yFuncName_String, parVals:{_?NumericQ..}, aROCs:{_?ROCAssociationQ..}, opts]"
\nROCPlot[ aROCs:{_?ROCAssociationQ..}, opts] \
\nROCPlot[ parVals:({_?NumericQ..}|Automatic), aROCs:{_?ROCAssociationQ..}, opts] \
\nROCPlot[ xFuncName_String, yFuncName_String, aROCs:{_?ROCAssociationQ..}, opts] \
\nROCPlot[ xFuncName_String, yFuncName_String, parVals:({_?NumericQ..}|Automatic), aROCs:{_?ROCAssociationQ..}, opts]"

Begin["`Private`"]

Expand Down Expand Up @@ -289,25 +291,44 @@ two labels lists (actual and predicted) into an Association that can be used as

Clear[ROCPlot]

ROCPlot::apv = "The parameter values are specified as Automatic, but extracting \"ROCParameter\" from the ROC data\
did not produce a numerical vector."

Options[ROCPlot] =
Join[ {"ROCPointSize"-> 0.02, "ROCColor"-> Lighter[Blue], "ROCPointColorFunction" -> Automatic,
"ROCPointTooltips"->True, "ROCPointCallouts"->True, "PlotJoined" -> False }, Options[Graphics]];

ROCPlot[ aROCs:{_?ROCAssociationQ..}, opts:OptionsPattern[]] :=
ROCPlot[ "FPR", "TPR", Automatic, aROCs, opts];

ROCPlot[ parVals:{_?NumericQ..}, aROCs:{_?ROCAssociationQ..}, opts:OptionsPattern[]] :=
ROCPlot[ "FPR", "TPR", parVals, aROCs, opts];

ROCPlot[ xFuncName_String, yFuncName_String, aROCs:{_?ROCAssociationQ..}, opts:OptionsPattern[]] :=
ROCPlot[ "FPR", "TPR", Automatic, aROCs, opts];

ROCPlot[
xFuncName_String, yFuncName_String,
parVals:{_?NumericQ..},
aROCs:{_?ROCAssociationQ..}, opts:OptionsPattern[]] :=
Block[{xFunc, yFunc, psize, rocc, pt, pc, pj, pja, rocpcf, points},
parValsArg : (Automatic | {_?NumericQ..}),
aROCs : {_?ROCAssociationQ..}, opts : OptionsPattern[]] :=
Block[{xFunc, yFunc, psize, rocc, pt, pc, pj, pja, rocpcf, points, parVals=parValsArg},

psize = OptionValue["ROCPointSize"];
rocc = OptionValue["ROCColor"];
rocpcf = OptionValue["ROCPointColorFunction"];
{pt, pc, pj} = TrueQ[OptionValue[#]] & /@ { "ROCPointTooltips", "ROCPointCallouts", "PlotJoined" };
pja = TrueQ[OptionValue["PlotJoined"]===Automatic];

{xFunc, yFunc} = ROCFunctions[{xFuncName, yFuncName}];

points = Map[Through[{xFunc,yFunc}[#1]] &, aROCs];

If[TrueQ[parVals===Automatic], parVals = Map[#["ROCParameter"]&,aROCs] ];
If[ !VectorQ[parVals,NumericQ],
Message[ROCPlot::apv];
Return[$Failed]
];

Graphics[{
If[pja, {Lighter[rocc],Line[points]},{}],
PointSize[psize], rocc,
Expand Down Expand Up @@ -341,7 +362,8 @@ two labels lists (actual and predicted) into an Association that can be used as
( "ROCPointSize" | "ROCColor" | "ROCPointColorFunction" |
"ROCPointTooltips" | "ROCPointCallouts" | "PlotJoined") -> _ ]
]
]/; Length[parVals] == Length[aROCs];
] /; Length[parValsArg] == Length[aROCs] || TrueQ[parValsArg===Automatic];


End[] (* `Private` *)

Expand Down

0 comments on commit 35d7555

Please sign in to comment.