Skip to content

Commit

Permalink
Working on #18 : add print out of latex table of anomaly effs
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-may committed Feb 4, 2022
1 parent b209e9a commit fab15a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
32 changes: 32 additions & 0 deletions autodqm_ml/evaluation/roc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ def calc_roc_and_unc(y, pred, sample_weight = None, n_bootstrap = 100, interp =
return results


def print_eff_table(name, results):
logger.debug("[roc_tools.py : print_eff_table] Printing anomaly detection efficiencies LaTeX table for histogram '%s'." % name)

anom_effs = [0.5, 0.9, 0.99]
effs = {}
for algorithm, res in results.items():
tprs = []
fprs = []

for eff in anom_effs:
sig_eff, idx = find_nearest(res["tpr"], eff)
tprs.append(res["tpr"][idx])
fprs.append(res["fpr"][idx])

effs[algorithm] = {
"fpr" : fprs,
"tpr" : tprs,
"auc" : res["auc"],
"auc_unc" : res["auc_unc"]
}

print("\\begin{center} \\scriptsize")
print("\\begin{tabular}{r|c|l|l|l}")
print("\\multicolumn{5}{c}{%s} \\\\ \\hline \\hline" % name)
print("\\multirow{3}{*}{Algorithm} & \\multicolumn{4}{c}{Metric (\\%)} \\\\ \\cline{2-5}")
print(" & \\multirow{2}{*}{AUC} & \\multicolumn{3}{c}{False Alarm Rate ($\\alpha_{\\text{far}}$) at fixed $\\epsilon_{\\text{anom}}$} \\\\ \\cline{3-5}")
print(" & & $\\alpha_{\\text{far}} (\\epsilon_{\\text{anom}} = %d\\%%)$ & $\\alpha_{\\text{far}} (\\epsilon_{\\text{anom}} = %d\\%%)$ & $\\alpha_{\\text{far}} (\\epsilon_{\\text{anom}} = %d\\%%)$ \\\\ \\hline" % (int(anom_effs[0] * 100.), int(anom_effs[1] * 100.), int(anom_effs[2] * 100.)))
for algo, eff in effs.items():
print("%s & %.3f $\\pm$ %.3f & %.1f\\%% & %.1f\\%% & %.1f\\%% \\\\ \\hline" % (algo, eff["auc"], eff["auc_unc"], eff["fpr"][0] * 100., eff["fpr"][1] * 100., eff["fpr"][2] * 100.))
print("\\end{tabular} \\end{center}")


def find_nearest(array,value):
val = numpy.ones_like(array)*value
idx = (numpy.abs(array-val)).argmin()
Expand Down
5 changes: 3 additions & 2 deletions scripts/assess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from autodqm_ml.utils import setup_logger
from autodqm_ml.utils import expand_path
from autodqm_ml.plotting.plot_tools import make_original_vs_reconstructed_plot, make_sse_plot, plot_roc_curve
from autodqm_ml.evaluation.roc_tools import calc_roc_and_unc
from autodqm_ml.evaluation.roc_tools import calc_roc_and_unc, print_eff_table
from autodqm_ml.constants import kANOMALOUS, kGOOD

def parse_arguments():
Expand Down Expand Up @@ -179,7 +179,8 @@ def main(args):
save_name = args.output_dir + "/" + h_name + "_roc.pdf"
plot_roc_curve(h_name, roc_results[h], save_name)
plot_roc_curve(h_name, roc_results[h], save_name.replace(".pdf", "_log.pdf"), log = True)

print_eff_table(h_name, roc_results[h])


# Plots of original/reconstructed histograms
if args.runs is None:
Expand Down

0 comments on commit fab15a5

Please sign in to comment.