Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -183,6 +183,9 @@ def apply_academic_style(fig, ax_or_axes):
|
|
| 183 |
)
|
| 184 |
ax.set_axisbelow(True)
|
| 185 |
|
|
|
|
|
|
|
|
|
|
| 186 |
# ================================================================
|
| 187 |
# 使用标准 Unicode ε 和 σ
|
| 188 |
# ================================================================
|
|
@@ -291,11 +294,11 @@ def fig_auc_bar():
|
|
| 291 |
for bar, h in zip(bars, hatches):
|
| 292 |
if h: bar.set_hatch(h)
|
| 293 |
|
| 294 |
-
for b,v in zip(bars, vals): ax.text(b.get_x()+b.get_width()/2, v+0.
|
| 295 |
ax.axhline(0.5, color='black', ls='--', lw=1.5, label='Random Guess (0.5)', zorder=2)
|
| 296 |
ax.axhline(bl_auc, color='black', ls=':', lw=2, label=f'Baseline ({bl_auc:.4f})', zorder=2)
|
| 297 |
ax.set_ylabel('MIA Attack AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Defense Effectiveness: MIA AUC Comparison', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20)
|
| 298 |
-
ax.set_ylim(0.45, max(vals)+0.
|
| 299 |
ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE, loc='upper right'); plt.tight_layout()
|
| 300 |
return fig
|
| 301 |
|
|
@@ -542,14 +545,16 @@ def fig_tpr_at_low_fpr():
|
|
| 542 |
bars = ax.bar(x, tpr5_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 543 |
for bar, h in zip(bars, hatches_all):
|
| 544 |
if h: bar.set_hatch(h)
|
| 545 |
-
|
|
|
|
| 546 |
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)
|
| 547 |
|
| 548 |
ax = axes[1];
|
| 549 |
bars = ax.bar(x, tpr1_all, color=clrs_all, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 550 |
for bar, h in zip(bars, hatches_all):
|
| 551 |
if h: bar.set_hatch(h)
|
| 552 |
-
|
|
|
|
| 553 |
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()
|
| 554 |
return fig
|
| 555 |
|
|
@@ -567,7 +572,8 @@ def fig_loss_gap_waterfall():
|
|
| 567 |
bars = ax.bar(range(len(names)), gaps, color=clrs, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 568 |
for bar, h in zip(bars, hatches):
|
| 569 |
if h: bar.set_hatch(h)
|
| 570 |
-
|
|
|
|
| 571 |
ax.set_ylabel('Loss Gap', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Member vs Non-Member Loss Gap', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20); ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); ax.annotate('Smaller gap = Better Privacy', xy=(8, gaps[0]*0.4), fontsize=THESIS_AXIS_LABEL_SIZE, color='black', fontstyle='italic', ha='center', backgroundcolor='white', bbox=dict(boxstyle='round,pad=0.4', facecolor='white', edgecolor='black', alpha=1.0)); plt.tight_layout()
|
| 572 |
return fig
|
| 573 |
|
|
@@ -588,7 +594,7 @@ def fig_acc_bar():
|
|
| 588 |
bars = ax.bar(range(len(names)), vals, color=clrs, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 589 |
for bar, h in zip(bars, hatches):
|
| 590 |
if h: bar.set_hatch(h)
|
| 591 |
-
for b, v in zip(bars, vals): ax.text(b.get_x()+b.get_width()/2, v+
|
| 592 |
ax.set_ylabel('Test Accuracy (%)', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Model Utility: Test Accuracy', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20)
|
| 593 |
ax.set_ylim(0, 105); ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); plt.tight_layout()
|
| 594 |
return fig
|
|
|
|
| 183 |
)
|
| 184 |
ax.set_axisbelow(True)
|
| 185 |
|
| 186 |
+
# 为柱状图顶部数值标注预留上边距,避免数字贴到图框
|
| 187 |
+
ax.margins(y=0.18)
|
| 188 |
+
|
| 189 |
# ================================================================
|
| 190 |
# 使用标准 Unicode ε 和 σ
|
| 191 |
# ================================================================
|
|
|
|
| 294 |
for bar, h in zip(bars, hatches):
|
| 295 |
if h: bar.set_hatch(h)
|
| 296 |
|
| 297 |
+
for b,v in zip(bars, vals): ax.text(b.get_x()+b.get_width()/2, v+0.006, f'{v:.4f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
|
| 298 |
ax.axhline(0.5, color='black', ls='--', lw=1.5, label='Random Guess (0.5)', zorder=2)
|
| 299 |
ax.axhline(bl_auc, color='black', ls=':', lw=2, label=f'Baseline ({bl_auc:.4f})', zorder=2)
|
| 300 |
ax.set_ylabel('MIA Attack AUC', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Defense Effectiveness: MIA AUC Comparison', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20)
|
| 301 |
+
ax.set_ylim(0.45, max(vals)+0.08); ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE)
|
| 302 |
ax.legend(facecolor='white', edgecolor='black', labelcolor='black', fontsize=THESIS_LEGEND_SIZE, loc='upper right'); plt.tight_layout()
|
| 303 |
return fig
|
| 304 |
|
|
|
|
| 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 |
|
|
|
|
| 572 |
bars = ax.bar(range(len(names)), gaps, color=clrs, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 573 |
for bar, h in zip(bars, hatches):
|
| 574 |
if h: bar.set_hatch(h)
|
| 575 |
+
ax.set_ylim(0, max(gaps) * 1.20)
|
| 576 |
+
for b, v in zip(bars, gaps): ax.text(b.get_x()+b.get_width()/2, v + max(gaps) * 0.012, f'{v:.4f}', ha='center', fontsize=THESIS_LEGEND_SIZE, fontweight='normal', color='black')
|
| 577 |
ax.set_ylabel('Loss Gap', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Member vs Non-Member Loss Gap', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20); ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); ax.annotate('Smaller gap = Better Privacy', xy=(8, gaps[0]*0.4), fontsize=THESIS_AXIS_LABEL_SIZE, color='black', fontstyle='italic', ha='center', backgroundcolor='white', bbox=dict(boxstyle='round,pad=0.4', facecolor='white', edgecolor='black', alpha=1.0)); plt.tight_layout()
|
| 578 |
return fig
|
| 579 |
|
|
|
|
| 594 |
bars = ax.bar(range(len(names)), vals, color=clrs, width=0.65, edgecolor='black', linewidth=1.5, zorder=3)
|
| 595 |
for bar, h in zip(bars, hatches):
|
| 596 |
if h: bar.set_hatch(h)
|
| 597 |
+
for b, v in zip(bars, vals): ax.text(b.get_x()+b.get_width()/2, v+0.8, f'{v:.1f}%', ha='center', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal', color='black')
|
| 598 |
ax.set_ylabel('Test Accuracy (%)', fontsize=THESIS_AXIS_LABEL_SIZE, fontweight='normal'); ax.set_title('Model Utility: Test Accuracy', fontsize=THESIS_SUPTITLE_SIZE, fontweight='normal', pad=20)
|
| 599 |
ax.set_ylim(0, 105); ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=25, ha='right', fontsize=THESIS_AXIS_LABEL_SIZE); plt.tight_layout()
|
| 600 |
return fig
|