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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -14
app.py CHANGED
@@ -635,23 +635,82 @@ def fig_tradeoff():
635
  return fig
636
 
637
  def fig_auc_trend():
638
- fig, axes = plt.subplots(1, 2, figsize=(17, 7.2)); apply_academic_style(fig, axes); ax = axes[0]; eps_vals = [0.0, 0.02, 0.05, 0.1, 0.2]; auc_vals = [gm(k, 'auc') for k in LS_KEYS]; acc_vals = [gu(k) for k in LS_KEYS]
639
- ax2 = ax.twinx();
640
- line1 = ax.plot(eps_vals, auc_vals, marker='o', ls='-', color='black', lw=3, ms=9, label='MIA AUC (Risk)', zorder=5);
641
- line2 = ax2.plot(eps_vals, acc_vals, marker='s', ls='--', color='black', lw=3, ms=9, label='Utility % (right)', zorder=5);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
  ax.axhline(0.5, color='gray', ls=':')
643
  ax.fill_between(eps_vals, auc_vals, 0.5, alpha=0.2, color='gray', hatch='//')
644
- ax.set_xlabel('Label Smoothing ε', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_ylabel('MIA AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black'); ax2.set_ylabel('Utility (%)', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black'); ax.set_title('Label Smoothing Trends', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15); ax.tick_params(axis='y', labelcolor='black'); ax2.tick_params(axis='y', labelcolor='black'); ax2.spines['right'].set_color('black'); ax2.spines['left'].set_color('black'); lines = line1 + line2; labels = [l.get_label() for l in lines]
 
 
 
 
 
 
 
 
 
 
 
 
645
  ax.legend(lines, labels, fontsize=THESIS_LEGEND_SIZE, facecolor='white', edgecolor='black', loc='lower right')
646
-
647
- ax = axes[1]; sig_vals = OP_SIGMAS; auc_op = [gm(k, 'auc') for k in OP_KEYS];
648
- ax.plot(sig_vals, auc_op, marker='^', ls='-', color='black', lw=3, ms=9, zorder=5, label='MIA AUC');
649
- ax.axhline(bl_auc, color='black', ls='--', lw=2, label=f'Baseline ({bl_auc:.4f})');
650
- ax.axhline(0.5, color='gray', ls=':', label='Random (0.5)');
651
- ax.fill_between(sig_vals, auc_op, bl_auc, alpha=0.2, color='gray', hatch='\\\\', label='AUC Reduction')
652
- ax2r = ax.twinx(); ax2r.axhline(bl_acc, color='black', ls='-', lw=2.5); ax2r.set_ylabel(f'Utility = {bl_acc:.1f}% (unchanged)', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black'); ax2r.set_ylim(0,100); ax2r.tick_params(axis='y', labelcolor='black'); ax2r.spines['right'].set_color('black')
653
- ax.set_xlabel('Perturbation σ', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_ylabel('MIA AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Output Perturbation Trends', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15)
654
- ax.legend(fontsize=THESIS_LEGEND_SIZE, facecolor='white', edgecolor='black', loc='lower left'); plt.tight_layout()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  return fig
656
 
657
  # ================================================================
 
635
  return fig
636
 
637
  def fig_auc_trend():
638
+ # 改为上下排版:上图为标签平滑趋势,下图为输出扰动趋势
639
+ # 这样插入论文时每个子图宽度更大,可读性更好。
640
+ fig, axes = plt.subplots(2, 1, figsize=(10.5, 12.5))
641
+ apply_academic_style(fig, axes)
642
+
643
+ # -------------------------------
644
+ # 上图:标签平滑趋势
645
+ # -------------------------------
646
+ ax = axes[0]
647
+ eps_vals = [0.0, 0.02, 0.05, 0.1, 0.2]
648
+ auc_vals = [gm(k, 'auc') for k in LS_KEYS]
649
+ acc_vals = [gu(k) for k in LS_KEYS]
650
+
651
+ ax2 = ax.twinx()
652
+ line1 = ax.plot(
653
+ eps_vals, auc_vals,
654
+ marker='o', ls='-', color='black',
655
+ lw=3, ms=9, label='MIA AUC (Risk)', zorder=5
656
+ )
657
+ line2 = ax2.plot(
658
+ eps_vals, acc_vals,
659
+ marker='s', ls='--', color='black',
660
+ lw=3, ms=9, label='Utility % (right)', zorder=5
661
+ )
662
+
663
  ax.axhline(0.5, color='gray', ls=':')
664
  ax.fill_between(eps_vals, auc_vals, 0.5, alpha=0.2, color='gray', hatch='//')
665
+
666
+ ax.set_xlabel('Label Smoothing ε', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal')
667
+ ax.set_ylabel('MIA AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black')
668
+ ax2.set_ylabel('Utility (%)', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black')
669
+ ax.set_title('Label Smoothing Trends', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15)
670
+
671
+ ax.tick_params(axis='y', labelcolor='black')
672
+ ax2.tick_params(axis='y', labelcolor='black')
673
+ ax2.spines['right'].set_color('black')
674
+ ax2.spines['left'].set_color('black')
675
+
676
+ lines = line1 + line2
677
+ labels = [l.get_label() for l in lines]
678
  ax.legend(lines, labels, fontsize=THESIS_LEGEND_SIZE, facecolor='white', edgecolor='black', loc='lower right')
679
+
680
+ # -------------------------------
681
+ # 下图:输出扰动趋势
682
+ # -------------------------------
683
+ ax = axes[1]
684
+ sig_vals = OP_SIGMAS
685
+ auc_op = [gm(k, 'auc') for k in OP_KEYS]
686
+
687
+ ax.plot(
688
+ sig_vals, auc_op,
689
+ marker='^', ls='-', color='black',
690
+ lw=3, ms=9, zorder=5, label='MIA AUC'
691
+ )
692
+ ax.axhline(bl_auc, color='black', ls='--', lw=2, label=f'Baseline ({bl_auc:.4f})')
693
+ ax.axhline(0.5, color='gray', ls=':', label='Random (0.5)')
694
+ ax.fill_between(sig_vals, auc_op, bl_auc, alpha=0.2, color='gray', hatch='\\', label='AUC Reduction')
695
+
696
+ ax2r = ax.twinx()
697
+ ax2r.axhline(bl_acc, color='black', ls='-', lw=2.5)
698
+ ax2r.set_ylabel(
699
+ f'Utility = {bl_acc:.1f}% (unchanged)',
700
+ fontsize=THESIS_AXIS_LABEL_SIZE,
701
+ fontweight='normal',
702
+ color='black'
703
+ )
704
+ ax2r.set_ylim(0, 100)
705
+ ax2r.tick_params(axis='y', labelcolor='black')
706
+ ax2r.spines['right'].set_color('black')
707
+
708
+ ax.set_xlabel('Perturbation σ', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal')
709
+ ax.set_ylabel('MIA AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal')
710
+ ax.set_title('Output Perturbation Trends', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=15)
711
+ ax.legend(fontsize=THESIS_LEGEND_SIZE, facecolor='white', edgecolor='black', loc='lower left')
712
+
713
+ plt.subplots_adjust(hspace=0.40, top=0.95, bottom=0.08, left=0.10, right=0.90)
714
  return fig
715
 
716
  # ================================================================