DeCLIP-TPAMI / tools /plot_radar_yulin_iclrv2.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
c50dde6 verified
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
# =========================
# 数据与预处理
# =========================
labels = [
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
'MATH-500', 'AIME24', 'AIME25', 'GSM8K', 'AMC23', 'Olympiad',
]
# ! 原始版本
# baseline=[79.6, 23.3, 16.7, 76.0, 55.0, 32.6,
# 89.8, 40.0, 26.7, 89.2, 75.0, 46.9,
# 93.8, 66.7, 56.7, 95.1, 95.0, 60.6,
# 94.8, 66.7, 46.7, 96.3, 87.5, 66.7]
# ReBalance_value = [83.0, 36.7, 30.0, 78.3, 80.0, 43.9,
# 92.6, 56.7, 40.0, 91.6, 95.0, 57.0,
# 94.0, 73.3, 56.7, 96.3, 100.0, 66.3,
# 95.2, 70.0, 63.3, 96.8, 95.0, 68.6]
# SEAL_value = [78.6, 23.3, 26.7, 76.4, 53.8, 32.7,
# 90.6, 43.3, 26.7, 88.4, 77.5, 53.9,
# 93.4, 63.3, 50.0, 95.7, 90.0, 62.3,
# 92.6, 63.3, 56.7, 96.2, 95.0, 67.5]
# ! 为了对称,第一组和第四组调换位置
# 94.8, 66.7, 46.7, 96.3, 87.5, 66.7
baseline=[94.8, 66.7, 46.7, 96.3, 87.5, 66.7,
89.8, 40.0, 26.7, 89.2, 75.0, 46.9,
93.8, 66.7, 56.7, 95.1, 95.0, 60.6,
79.6, 23.3, 16.7, 76.0, 55.0, 32.6]
# 95.2, 70.0, 63.3, 96.8, 95.0, 68.6
ReBalance_value = [95.2, 70.0, 63.3, 96.8, 95.0, 68.6,
92.6, 56.7, 40.0, 91.6, 95.0, 57.0,
94.0, 73.3, 56.7, 96.3, 100.0, 66.3,
83.0, 36.7, 30.0, 78.3, 80.0, 43.9]
# 92.6, 63.3, 56.7, 96.2, 95.0, 67.5
SEAL_value = [92.6, 63.3, 56.7, 96.2, 95.0, 67.5,
90.6, 43.3, 26.7, 88.4, 77.5, 53.9,
93.4, 63.3, 50.0, 95.7, 90.0, 62.3,
78.6, 23.3, 26.7, 76.4, 53.8, 32.7]
# =========================
# 归一化和增强对比度
# =========================
def normalize_values(target, base_values, method_values):
normalized = []
for base, value in zip(base_values, method_values):
if base == 0 or value == 0:
normalized.append(0)
else:
normalized.append((value / base) * target)
return normalized
def enhance_contrast(values, power=2.0, target_max=40):
arr = np.array(values, dtype=float)
arr_scaled = arr ** power
return (arr_scaled / arr_scaled.max()) * target_max
target = 40
Baseline = normalize_values(target, ReBalance_value, baseline)
ReBalance = normalize_values(target, ReBalance_value, ReBalance_value)
SEAL = normalize_values(target, ReBalance_value, SEAL_value)
Baseline = enhance_contrast(Baseline, power=2.0, target_max=target)
ReBalance = enhance_contrast(ReBalance, power=2.0, target_max=target)
SEAL = enhance_contrast(SEAL, power=2.0, target_max=target)
# =========================
# 设置角度
# =========================
num_groups = 4
tasks_per_group = 6
gap_deg = 16
group_arc = (360 - num_groups * gap_deg) / num_groups
point_arc = group_arc / tasks_per_group
angles = []
current_angle = 0
for g in range(num_groups):
for t in range(tasks_per_group):
angles.append(np.deg2rad(current_angle))
current_angle += point_arc
current_angle += gap_deg
# 首尾相连
angles += [angles[0]]
Baseline = np.concatenate((Baseline, [Baseline[0]]))
ReBalance = np.concatenate((ReBalance, [ReBalance[0]]))
SEAL = np.concatenate((SEAL, [SEAL[0]]))
# =========================
# 绘图 (CVPR/NIPS 风格)
# =========================
colors = {
"Baseline": "#00B0FF", # 亮青蓝
"ReBalance": "#00E676", # 荧光绿
"SEAL": "#FFB300", # 亮橙黄
}
markers = {
"Baseline": "s",
"ReBalance": "o",
"SEAL": "D",
}
linestyles = {
"Baseline": "--",
"ReBalance": "-",
"SEAL": "-.",
}
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
# 半径=40的参考圆
theta = np.linspace(0, 2*np.pi, 500)
ax.plot(theta, np.full_like(theta, 40),
color="black", linewidth=1.2, linestyle="-", zorder=0.5)
ax.set_ylim(0, 44)
# 背景与网格
ax.set_facecolor("white")
ax.grid(True, color="gray", linestyle="--", linewidth=0.6, alpha=0.6)
ax.spines["polar"].set_visible(False)
ax.set_yticks([])
ax.set_yticklabels([])
# 通用绘图函数
def plot_method(values, angles, label):
ax.fill(angles, values, color=colors[label], alpha=0.1, zorder=1)
ax.plot(angles, values, color=colors[label],
linewidth=2.2, linestyle=linestyles[label],
label=label, zorder=2)
ax.scatter(angles, values,
facecolors="white", edgecolors=colors[label],
linewidths=1.5, marker=markers[label],
s=55, zorder=3)
plot_method(Baseline, angles, "Baseline")
plot_method(ReBalance, angles, "ReBalance")
plot_method(SEAL, angles, "SEAL")
# 中心灰点
ax.scatter(0, 0, c="gray", edgecolors="black",
s=120, zorder=5, linewidths=1.0)
# 标签
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12, color="black")
for label in ax.get_xticklabels():
label.set_horizontalalignment("center")
# 图例
legend_elements = [
Patch(facecolor=colors["Baseline"], edgecolor=colors["Baseline"], label="Baseline"),
Patch(facecolor=colors["SEAL"], edgecolor=colors["SEAL"], label="SEAL"),
Patch(facecolor=colors["ReBalance"], edgecolor=colors["ReBalance"], label="ReBalance (Ours)"),
]
ax.legend(
handles=legend_elements,
frameon=False,
fontsize=14,
loc="upper center",
bbox_to_anchor=(0.68, 1.21),
)
plt.tight_layout()
plt.savefig("radar_chart_cvpr_with_baseline.png", dpi=300, transparent=True)
plt.close()