xiaohy commited on
Commit
20ad3e0
·
verified ·
1 Parent(s): 1d28b21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -530,32 +530,48 @@ def fig_roc_curves():
530
  return fig
531
 
532
  def fig_tpr_at_low_fpr():
533
- fig, axes = plt.subplots(1, 2, figsize=(17, 7.2)); apply_academic_style(fig, axes); labels_all, tpr5_all, tpr1_all, clrs_all, hatches_all = [], [], [], [], []
534
  ls_h_list = [HATCH_BASELINE] + HATCH_LS
535
  ls_c_list = [CHART_C['baseline']] + CHART_C['ls_colors']
536
 
537
- for i, (k, l) in enumerate(zip(LS_KEYS, LS_LABELS_PLOT)):
538
  labels_all.append(l); tpr5_all.append(gm(k, 'tpr_at_5fpr')); tpr1_all.append(gm(k, 'tpr_at_1fpr'))
539
  clrs_all.append(ls_c_list[i]); hatches_all.append(ls_h_list[i])
540
- for i, (k, l) in enumerate(zip(OP_KEYS, OP_LABELS_PLOT)):
541
  labels_all.append(l); tpr5_all.append(gm(k, 'tpr_at_5fpr')); tpr1_all.append(gm(k, 'tpr_at_1fpr'))
542
  clrs_all.append(CHART_C['op_colors'][i]); hatches_all.append(HATCH_OP[i])
543
-
544
- x = range(len(labels_all)); ax = axes[0];
 
545
  bars = ax.bar(x, tpr5_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
546
  for bar, h in zip(bars, hatches_all):
547
- if h: bar.set_hatch(h)
548
- ax.set_ylim(0, max(tpr5_all) * 1.22)
549
- for b, v in zip(bars, tpr5_all): ax.text(b.get_x()+b.get_width()/2, v + max(tpr5_all) * 0.012, f'{v:.3f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
550
- ax.set_ylabel('TPR @ 5% FPR', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Attack Power at 5% FPR', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15); ax.set_xticks(x); ax.set_xticklabels(labels_all, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); ax.axhline(0.05, color='gray', ls='--', lw=2, label='Random (0.05)'); ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE)
 
 
 
 
 
 
 
551
 
552
- ax = axes[1];
553
  bars = ax.bar(x, tpr1_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
554
  for bar, h in zip(bars, hatches_all):
555
- if h: bar.set_hatch(h)
556
- ax.set_ylim(0, max(tpr1_all) * 1.24)
557
- for b, v in zip(bars, tpr1_all): ax.text(b.get_x()+b.get_width()/2, v + max(tpr1_all) * 0.012, f'{v:.3f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
558
- ax.set_ylabel('TPR @ 1% FPR', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Attack Power at 1% FPR (Strict)', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15); ax.set_xticks(x); ax.set_xticklabels(labels_all, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); ax.axhline(0.01, color='gray', ls='--', lw=2, label='Random (0.01)'); ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE); plt.tight_layout()
 
 
 
 
 
 
 
 
559
  return fig
560
 
561
  def fig_loss_gap_waterfall():
 
530
  return fig
531
 
532
  def fig_tpr_at_low_fpr():
533
+ fig, axes = plt.subplots(2, 1, figsize=(10.5, 12.5)); apply_academic_style(fig, axes); labels_all, tpr5_all, tpr1_all, clrs_all, hatches_all = [], [], [], [], []
534
  ls_h_list = [HATCH_BASELINE] + HATCH_LS
535
  ls_c_list = [CHART_C['baseline']] + CHART_C['ls_colors']
536
 
537
+ for i, (k, l) in enumerate(zip(LS_KEYS, LS_LABELS_PLOT)):
538
  labels_all.append(l); tpr5_all.append(gm(k, 'tpr_at_5fpr')); tpr1_all.append(gm(k, 'tpr_at_1fpr'))
539
  clrs_all.append(ls_c_list[i]); hatches_all.append(ls_h_list[i])
540
+ for i, (k, l) in enumerate(zip(OP_KEYS, OP_LABELS_PLOT)):
541
  labels_all.append(l); tpr5_all.append(gm(k, 'tpr_at_5fpr')); tpr1_all.append(gm(k, 'tpr_at_1fpr'))
542
  clrs_all.append(CHART_C['op_colors'][i]); hatches_all.append(HATCH_OP[i])
543
+
544
+ x = range(len(labels_all))
545
+ ax = axes[0]
546
  bars = ax.bar(x, tpr5_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
547
  for bar, h in zip(bars, hatches_all):
548
+ if h:
549
+ bar.set_hatch(h)
550
+ ax.set_ylim(0, max(tpr5_all) * 1.24)
551
+ for b, v in zip(bars, tpr5_all):
552
+ ax.text(b.get_x() + b.get_width() / 2, v + max(tpr5_all) * 0.012, f'{v:.3f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
553
+ ax.set_ylabel('TPR @ 5% FPR', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal')
554
+ ax.set_title('Attack Power at 5% FPR', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15)
555
+ ax.set_xticks(list(x))
556
+ ax.set_xticklabels(labels_all, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE)
557
+ ax.axhline(0.05, color='gray', ls='--', lw=2, label='Random (0.05)')
558
+ ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE)
559
 
560
+ ax = axes[1]
561
  bars = ax.bar(x, tpr1_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
562
  for bar, h in zip(bars, hatches_all):
563
+ if h:
564
+ bar.set_hatch(h)
565
+ ax.set_ylim(0, max(tpr1_all) * 1.28)
566
+ for b, v in zip(bars, tpr1_all):
567
+ ax.text(b.get_x() + b.get_width() / 2, v + max(tpr1_all) * 0.012, f'{v:.3f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
568
+ ax.set_ylabel('TPR @ 1% FPR', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal')
569
+ ax.set_title('Attack Power at 1% FPR (Strict)', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15)
570
+ ax.set_xticks(list(x))
571
+ ax.set_xticklabels(labels_all, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE)
572
+ ax.axhline(0.01, color='gray', ls='--', lw=2, label='Random (0.01)')
573
+ ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE)
574
+ plt.subplots_adjust(hspace=0.35, top=0.95, bottom=0.09, left=0.09, right=0.98)
575
  return fig
576
 
577
  def fig_loss_gap_waterfall():