AI4M
AI for Materials Science 材料人工智能实战课程 · 研究生课程门户

Module 04 · Lecture 04b · 贝叶斯自驱动实验

04b — 贝叶斯优化、多目标帕累托寻优与自动驾驶实验室(Bayesian Optimization & Self-Driving Labs)

04b_bayesian_optimization_and_sdl.ipynb1.2 MB

Open In Colab

04b — 贝叶斯优化、多目标帕累托寻优与自动驾驶实验室(Bayesian Optimization & Self-Driving Labs)

在 04a 中,我们掌握了用高斯过程回归(GPR)同时输出候选配方的预测均值 \(\mu(\mathbf{x})\) 和预测不确定性 \(\sigma(\mathbf{x})\)。现在我们来解决实验材料人与合成化学家最核心的决策问题:

面前有 3,955 种可能的催化反应配方(或者同时要求高电导率与宽光学带隙的多维薄膜工艺窗口),每次进实验室合成与表征都十分昂贵。如何仅用不到 1% 的实验次数就锁定全局最优配方或完整帕累托前沿?

这就是**贝叶斯优化(Bayesian Optimization, BO)与自动驾驶实验室(Self-Driving Labs, SDL)**的主动决策大脑。

本节内容(对齐 LiU Lecture 08)

  1. 贝叶斯优化的四步主动学习闭环:利用(Exploitation)与探索(Exploration)的动态权衡;
  2. 从零手写三大经典采集函数(PI / EI / UCB):提升概率(PI)、期望提升(EI)与置信上界(UCB)正面对比;
  3. 1D 与 2D 材料合成工艺窗口寻优:直观追踪跳出局部最优陷阱,优化退火温度 \(T\) 与前驱体摩尔比 \(c\);
  4. 高通量催化反应寻优实战:Buchwald–Hartwig 碳氮偶联(3,955 反应):对比 One-Hot 编码与无标签物化组成描述符编码,25 次实验(<0.7% 空间)命中 >95% 产率;
  5. 机器学习超参数的贝叶斯优化(Bayesian HPO vs Random Search):18 次评估高效调优 XGBRegressor;
  6. 多目标帕累托贝叶斯优化(Multi-Objective Pareto BO)与闭环自动驾驶实验室(SDL):同时权衡薄膜电导率 \(\sigma\) 与光学带隙 \(E_g\),并用 Kriging Believer 假想观测驱动 4 通道并行机器人孔板推荐!
In [1] · Python
# colab-setup (本地运行时自动跳过)
import os, sys

if "google.colab" in sys.modules:
    _repo_dir = "/content/ai-for-materials"
    if not os.path.exists(_repo_dir):
        os.system("git clone --depth 1 https://github.com/Zeshengliu213/ai-for-materials.git " + _repo_dir)
    os.chdir(os.path.join(_repo_dir, "04 - Bayesian Optimization"))

0. 环境准备与数据读取辅助函数

In [2] · Python
import os
os.environ["MKL_NUM_THREADS"] = "1"

import re, pathlib, sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import norm

from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.model_selection import KFold, cross_val_score
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, Matern, WhiteKernel, ConstantKernel
from xgboost import XGBRegressor

def find_file(name):
    for path in (f"data/{name}", f"../data/{name}", name):
        if os.path.exists(path):
            return path
    raise FileNotFoundError(f"找不到 {name},请确保它位于 data/ 文件夹或当前目录下")

📘 课程统一绘图风格:下面这格加载课程自带的 ai4m.mplstyle(配色与课程网站同源,无上右边框,仅横向浅网格,保存默认 300 dpi)。C 是课程配色,手动指定颜色时写 color=C.crimson。

In [3] · Python
# ai4m-style:课程统一绘图风格(本地与 Colab 通用)
for _p in [pathlib.Path.cwd().parent, pathlib.Path.cwd().parent.parent]:
    if (_p / "ai4m_style.py").exists() and str(_p) not in sys.path:
        sys.path.insert(0, str(_p))
import ai4m_style as ai4m

C = ai4m.use()        # 应用 ai4m.mplstyle,返回课程配色

1. 贝叶斯优化的四步闭环与三大采集函数(PI / EI / UCB — LiU L08)

📘 1.1 四步序贯主动学习闭环

贝叶斯优化将传统“一次性铺网格做完实验”改造成了**“代理建模 \(\to\) 采集打分 \(\to\) 实验测量 \(\to\) 数据集扩充”**的智能闭环:

  1. 初始铺点(Initialization):用少量随机或聚类代表点完成首批实验 \(\mathcal{D}_0 = \{(\mathbf{x}_i, y_i)\}\);
  2. 代理模型(Surrogate Model):拟合 GPR,对所有未测候选点给出后验均值 \(\mu(\mathbf{x})\) 与标准差 \(\sigma(\mathbf{x})\);
  3. 最大化采集函数(Acquisition Function, \(\alpha(\mathbf{x})\)):权衡利用(Exploitation,去 \(\mu\) 高的已知峰值微调)与探索(Exploration,去 \(\sigma\) 大的未知盲区探路),选出 \(\mathbf{x}_{t+1} = \arg\max_{\mathbf{x}} \alpha(\mathbf{x})\);
  4. 实验测量与模型更新:实测 \(y_{t+1}\),并入 \(\mathcal{D}_{t+1}\) 进入下一轮循环。

📘 1.2 从零手写三大经典采集函数(PI / EI / UCB)

记当前已测到的最高性能记录为 \(y_{\text{best}} = \max_i y_i\),定义标准化提升裕度 \(Z(\mathbf{x}) = \frac{\mu(\mathbf{x}) - y_{\text{best}} - \xi}{\sigma(\mathbf{x})}\)(其中 \(\xi \ge 0\) 为微小探索偏置),LiU Lecture 08 系统介绍了三大采集函数:

  1. 提升概率(Probability of Improvement, PI):
    \[\alpha_{\text{PI}}(\mathbf{x}) = P\!\left(f(\mathbf{x}) \ge y_{\text{best}} + \xi\right) = \Phi(Z)\]
    只关心“超越当前记录的概率有多大”,不关心“能超越多少幅度”。当 \(\xi = 0\) 时,PI 往往过度保守地紧贴在已知最高点旁边微调(纯利用倾向较重)。
  2. 期望提升(Expected Improvement, EI):
    \[\alpha_{\text{EI}}(\mathbf{x}) = \mathbb{E}\!\left[\max(0, f(\mathbf{x}) - y_{\text{best}} - \xi)\right] = (\mu(\mathbf{x}) - y_{\text{best}} - \xi)\,\Phi(Z) + \sigma(\mathbf{x})\,\phi(Z)\]
    同时兼顾超越概率与超越幅度:第一项奖励高均值(利用),第二项 \(\sigma(\mathbf{x})\phi(Z)\) 奖励高不确定性(探索),是工程实践中最稳健的默认采集函数。
  3. 置信上界(Upper Confidence Bound, UCB):
    \[\alpha_{\text{UCB}}(\mathbf{x}) = \mu(\mathbf{x}) + \kappa \cdot \sigma(\mathbf{x})\]
    按乐观主义原则直接用置信上界打分,通过参数 \(\kappa\)(常取 1.5 ~ 2.5)显式控制探索力度。

▶️ 运行看看:在双峰材料工艺曲线上(初始 3 个实验不幸全落在左侧次优小峰附近),对比 Greedy、PI、EI 与 UCB 各自推荐去哪里做第 4 个实验!

In [4] · Python
def hidden_process(x):
    '''双峰材料工艺曲线:x=2.3 为局部次优小峰 (0.60),x=7.8 为未知的全局主峰 (1.00)'''
    return 0.60 * np.exp(-0.5 * ((x - 2.3) / 0.8) ** 2) + 1.00 * np.exp(-0.5 * ((x - 7.8) / 0.9) ** 2)

def acq_pi(mu, std, y_best, xi=0.01):
    z = np.divide(mu - y_best - xi, std, out=np.zeros_like(mu), where=std > 1e-9)
    return np.where(std > 1e-9, norm.cdf(z), 0.0)

def acq_ei(mu, std, y_best, xi=0.01):
    imp = mu - y_best - xi
    z = np.divide(imp, std, out=np.zeros_like(mu), where=std > 1e-9)
    return np.where(std > 1e-9, imp * norm.cdf(z) + std * norm.pdf(z), 0.0)

def acq_ucb(mu, std, kappa=2.0):
    return mu + kappa * std

X_grid = np.linspace(0, 10, 300).reshape(-1, 1)
X_init = np.array([[1.2], [2.2], [3.6]])
y_init = hidden_process(X_init).ravel()

gp0 = GaussianProcessRegressor(kernel=ConstantKernel(1.0) * RBF(1.0), alpha=1e-5, random_state=0).fit(X_init, y_init)
mu0, std0 = gp0.predict(X_grid, return_std=True)

pi_vals  = acq_pi(mu0, std0, y_init.max(), xi=0.01)
ei_vals  = acq_ei(mu0, std0, y_init.max(), xi=0.01)
ucb_vals = acq_ucb(mu0, std0, kappa=2.0)

fig, axes = plt.subplots(2, 1, figsize=(9.2, 5.8), sharex=True, gridspec_kw={"height_ratios": [1.8, 1.25]})
axes[0].plot(X_grid, hidden_process(X_grid), "k--", alpha=0.5, label="Hidden True Process")
axes[0].plot(X_grid, mu0, color=C.navy, lw=2.0, label="GP Posterior Mean")
axes[0].fill_between(X_grid.ravel(), mu0 - 1.96 * std0, mu0 + 1.96 * std0, color=C.navy, alpha=0.15, label="95% CI")
axes[0].scatter(X_init, y_init, color=C.crimson, s=60, zorder=5, label="Initial 3 Experiments (Trapped Left)")
axes[0].set_ylabel("Device Performance")
axes[0].set_title("GP Surrogate vs PI, EI, UCB & Greedy Acquisition Functions")
axes[0].legend(fontsize=8.3, loc="upper left")

for name, vals, col, ls in [
    ("PI (xi=0.01)",  pi_vals,  C.gold,    "--"),
    ("EI (xi=0.01)",  ei_vals,  C.teal,    "-"),
    ("UCB (kappa=2)", ucb_vals, C.crimson, "-."),
    ("Greedy (mu)",   mu0,      C.slate,   ":"),
]:
    norm_v = (vals - vals.min()) / (vals.max() - vals.min() + 1e-12)
    best_x = X_grid[int(np.argmax(vals)), 0]
    axes[1].plot(X_grid.ravel(), norm_v, color=col, ls=ls, lw=2.0, label=f"{name} -> next x = {best_x:.2f}")

axes[1].set_xlabel("Process Parameter x (Normalized Annealing Temperature)")
axes[1].set_ylabel("Normalized Acquisition")
axes[1].legend(fontsize=8.2, loc="upper right", ncol=2)
plt.tight_layout()
plt.show()
Out:
Notebook 输出图像

2. 1D 与 2D 合成工艺窗口寻优(退火温度 \(T\) + 前驱体配比 \(c\))

📘 2.1 一维 6 步闭环追踪与二维工艺平面寻优

先看一维双峰曲线上 EI 连续运行 6 步如何跳出左侧局部峰登顶右侧全局主峰(\(x=7.8\)),再将其直接推广到真实的二维薄膜沉积工艺窗口——同时优化退火温度 \(T \in [80, 220]\ ^\circ\text{C}\) 与前驱体摩尔配比 \(c \in [0.6, 2.2]\)(共 \(30 \times 30 = 900\) 个网格工艺点,仅用 3 初始点 + 15 步 BO = 18 次实验 锁定最优工艺窗口!):

In [5] · Python
# --- (A) 1D 6-Step EI Trajectory ---
X_obs, y_obs = X_init.copy(), y_init.copy()
fig, axes = plt.subplots(2, 3, figsize=(12.8, 5.8), sharex=True, sharey=True)

for step, ax in enumerate(axes.ravel(), start=1):
    gp_s = GaussianProcessRegressor(kernel=ConstantKernel(1.0) * RBF(1.0), alpha=1e-5, random_state=0).fit(X_obs, y_obs)
    mu_s, std_s = gp_s.predict(X_grid, return_std=True)
    ei_s = acq_ei(mu_s, std_s, y_obs.max(), xi=0.01)
    nx = X_grid[int(np.argmax(ei_s))]
    ny = float(hidden_process(nx).item())

    ax.plot(X_grid, hidden_process(X_grid), "k--", alpha=0.45)
    ax.plot(X_grid, mu_s, color=C.navy, lw=1.6)
    ax.fill_between(X_grid.ravel(), mu_s - 1.96 * std_s, mu_s + 1.96 * std_s, color=C.navy, alpha=0.14)
    ax.scatter(X_obs, y_obs, color=C.crimson, s=34, zorder=5)
    ax.scatter([nx[0]], [ny], color=C.gold, edgecolors="black", s=110, marker="*", zorder=6, label=f"Next x={nx[0]:.2f}")
    ax.set_title(f"Step {step} | Best y = {max(y_obs.max(), ny):.3f}", fontsize=9.5)
    ax.legend(loc="upper left", fontsize=7.8)

    X_obs = np.vstack([X_obs, nx.reshape(1, 1)])
    y_obs = np.append(y_obs, ny)

plt.suptitle("1D Bayesian Optimization (EI) Escaping Local Optimum in 6 Steps", fontsize=11.5, y=1.01)
plt.tight_layout()
plt.show()
Out:
Notebook 输出图像
In [6] · Python
# --- (B) 2D Synthesis Process Window Optimization: Annealing Temp T (°C) & Precursor Ratio c ---
def synth_window_2d(TC):
    T, c = TC[:, 0], TC[:, 1]
    local_peak  = 0.62 * np.exp(-0.5 * (((T - 115.0) / 18.0) ** 2 + ((c - 1.00) / 0.22) ** 2))
    global_peak = 0.98 * np.exp(-0.5 * (((T - 182.0) / 16.0) ** 2 + ((c - 1.68) / 0.20) ** 2))
    ridge       = 0.15 * np.exp(-0.5 * (((T - 150.0) / 35.0) ** 2 + ((c - 1.35) / 0.45) ** 2))
    return local_peak + global_peak + ridge

T_lin = np.linspace(80.0, 220.0, 30)
c_lin = np.linspace(0.60, 2.20, 30)
TT, CC = np.meshgrid(T_lin, c_lin)
X_2d_raw = np.column_stack([TT.ravel(), CC.ravel()])
X_2d_norm = (X_2d_raw - X_2d_raw.min(0)) / (X_2d_raw.max(0) - X_2d_raw.min(0))
y_2d_true = synth_window_2d(X_2d_raw)

rng_2d = np.random.default_rng(11)
obs_2d = list(rng_2d.choice(len(X_2d_raw), size=3, replace=False))

for _ in range(15):
    gp2 = GaussianProcessRegressor(
        kernel=ConstantKernel(1.0) * Matern(length_scale=0.25, nu=2.5), alpha=1e-5, random_state=0
    ).fit(X_2d_norm[obs_2d], y_2d_true[obs_2d])
    rem = [i for i in range(len(X_2d_raw)) if i not in obs_2d]
    m2, s2 = gp2.predict(X_2d_norm[rem], return_std=True)
    nxt = rem[int(np.argmax(acq_ei(m2, s2, y_2d_true[obs_2d].max(), xi=0.01)))]
    obs_2d.append(nxt)

mu_full, std_full = gp2.predict(X_2d_norm, return_std=True)
rand_18_best = np.mean([y_2d_true[np.random.default_rng(s).choice(len(X_2d_raw), 18, replace=False)].max() for s in range(30)])

fig, axes = plt.subplots(1, 3, figsize=(13.8, 3.9), sharey=True)
c0 = axes[0].contourf(TT, CC, y_2d_true.reshape(30, 30), levels=18, cmap="viridis")
plt.colorbar(c0, ax=axes[0], label="True Film Efficiency")
axes[0].scatter(X_2d_raw[obs_2d[:3], 0], X_2d_raw[obs_2d[:3], 1], c="white", edgecolors="black", s=60, label="Init (3)")
axes[0].scatter(X_2d_raw[obs_2d[3:], 0], X_2d_raw[obs_2d[3:], 1], c=C.crimson, edgecolors="white", s=85, marker="*", label="BO Steps (15)")
axes[0].set_title("True 2D Process Landscape & Trajectory", fontsize=9.5)
axes[0].set_xlabel("Annealing Temperature T (°C)")
axes[0].set_ylabel("Precursor Molar Ratio c")
axes[0].legend(fontsize=8.0, loc="lower right")

c1 = axes[1].contourf(TT, CC, mu_full.reshape(30, 30), levels=18, cmap="viridis")
plt.colorbar(c1, ax=axes[1], label="GP Mean mu(T, c)")
axes[1].set_title("GP Surrogate Posterior Mean", fontsize=9.5)
axes[1].set_xlabel("Annealing Temperature T (°C)")

c2 = axes[2].contourf(TT, CC, std_full.reshape(30, 30), levels=18, cmap=ai4m.cmap("ai4m_heat"))
plt.colorbar(c2, ax=axes[2], label="GP Uncertainty std(T, c)")
axes[2].scatter(X_2d_raw[obs_2d, 0], X_2d_raw[obs_2d, 1], c=C.navy, s=20)
axes[2].set_title("GP Posterior Uncertainty Map", fontsize=9.5)
axes[2].set_xlabel("Annealing Temperature T (°C)")

plt.tight_layout()
plt.show()

print(f"900 网格工艺点中仅做 18 次实验:2D GP-BO 最高性能 = {y_2d_true[obs_2d].max():.4f} (全局真值 {y_2d_true.max():.4f}) | 同预算随机搜索均值 = {rand_18_best:.4f}")
Out:
Notebook 输出图像
900 网格工艺点中仅做 18 次实验:2D GP-BO 最高性能 = 1.0476 (全局真值 1.0476) | 同预算随机搜索均值 = 0.7483

🏋️ 练习 04b-1:对比 PI、EI 与不同 \(\kappa\) 的 UCB 跳出局部最优的能力

在一维双峰工艺 hidden_process(x) 上(从相同的左侧初始 3 点 X_init 出发运行 6 步),分别对比以下 4 种采集策略在 6 步后的最优值 y_obs.max() 及采样点位置:

  1. 纯利用倾向的 PI(xi = 0.0) vs 带探索裕度的 PI(xi = 0.08);
  2. 标准 EI(xi = 0.01);
  3. 保守 UCB(kappa = 0.2) vs 探索平衡 UCB(kappa = 2.0)。
In [7] · Python
# 在下方填写你的代码:

3. 真实高通量催化合成寻优:Buchwald–Hartwig 偶联反应(3,955 个反应)

📘 3.1 离散反应组分的两种无外部依赖特征工程:One-Hot vs 物化组成描述符

data/bh-reactions.csv 收录了 Ahneman et al. (Science 360, 186–190, 2018) 的 3,955 个真实钯催化碳氮偶联反应(由 4 种膦配体 ligand \(\times\) 22 种异噁唑添加剂 additive \(\times\) 3 种有机强碱 base \(\times\) 15 种芳基卤代物 aryl halide 组合而成,平均产率仅 33.1%,最高 99.9%)。

在完全不借助任何外部化学工具包的前提下,我们可以为每个反应构建两套无目标泄漏的特征表示:

  1. One-Hot 独热编码(44 维):只标记“用了几号配体、几号添加剂、几号碱、几号底物”;
  2. 化学式与官能团统计物化特征 + PCA(18 维):直接从四组分的分子线式字符串统计原子组成(C, N, O, P, S, F 计数)、芳环比例、环数标记、支化度 (、双键/氰基/羰基特征,以及芳基卤代物离去基团活性(I > Br > Cl),经标准化与 PCA(18) 压缩后,使模型在尚未测过某底物或添加剂时也能凭组成相似性跨分子泛化!

▶️ 运行看看:仅做 25 次实验(不到全空间 3,955 种组合的 0.65%!),对比随机盲试、One-Hot BO 与物化描述符 BO 在 5 个随机种子上的寻优收敛曲线!

In [8] · Python
bh = pd.read_csv(find_file("bh-reactions.csv"))
y_yield = bh["yield"].values
comp_cols = ["ligand", "additive", "base", "aryl halide"]

# 编码 1: 44 维 One-Hot 组分指示向量
X_bh_oh = pd.get_dummies(bh[comp_cols], dtype=float).values

# 编码 2: 纯 Python 分子式/官能团统计物理化学特征(零外部化学包依赖!)
def string_physchem_features(smi: str) -> np.ndarray:
    n_Cl = smi.count("Cl")
    n_Br = smi.count("Br")
    n_I  = smi.count("I")
    clean = smi.replace("Cl", "").replace("Br", "").replace("Si", "")
    n_c_arom = clean.count("c") + clean.count("n") + clean.count("o") + clean.count("s")
    n_C_aliph = clean.count("C")
    n_N = clean.count("N") + clean.count("n")
    n_O = clean.count("O") + clean.count("o")
    n_P = clean.count("P")
    n_S = clean.count("S") + clean.count("s")
    n_F = clean.count("F")
    n_heavy = n_c_arom + n_C_aliph + n_N + n_O + n_P + n_S + n_F + n_Cl + n_Br + n_I
    n_rings = len(re.findall(r"[1-9]", clean)) / 2.0
    n_branch = clean.count("(")
    n_double = clean.count("=")
    n_triple = clean.count("#")
    halide_score = 3.0 * (n_I > 0) + 2.0 * (n_Br > 0) + 1.0 * (n_Cl > 0)
    arom_ratio = n_c_arom / max(n_heavy, 1)
    return np.array([
        n_heavy, n_c_arom, n_C_aliph, n_N, n_O, n_P, n_S, n_F,
        n_Cl, n_Br, n_I, n_rings, n_branch, n_double, n_triple, halide_score, arom_ratio,
    ], dtype=float)

feat_blocks = []
for col in comp_cols:
    uniq_map = {s: string_physchem_features(s) for s in bh[col].unique()}
    feat_blocks.append(np.vstack([uniq_map[s] for s in bh[col]]))

X_bh_chem_raw = np.hstack(feat_blocks)
# 去除零方差列后标准化并降维至 18 维紧凑物化反应坐标
non_const = X_bh_chem_raw.std(axis=0) > 1e-8
X_bh_chem = PCA(n_components=18, random_state=0).fit_transform(
    StandardScaler().fit_transform(X_bh_chem_raw[:, non_const])
)
print(f"反应总数: {len(bh):,} | One-Hot 维度: {X_bh_oh.shape[1]} | 物化组成 PCA 维度: {X_bh_chem.shape[1]}")

def run_bh_campaign(X_mat, y_vec, n_init=5, n_steps=20, seed=0, strategy="ei"):
    rng = np.random.default_rng(seed)
    n_tot = len(y_vec)
    obs = list(rng.choice(n_tot, size=n_init, replace=False))
    hist = [float(y_vec[obs].max())]

    for _ in range(n_steps):
        unseen = np.setdiff1d(np.arange(n_tot), obs)
        if strategy == "random":
            nxt = int(rng.choice(unseen))
        else:
            kern = ConstantKernel(1.0) * Matern(length_scale=2.0, nu=1.5) + WhiteKernel(noise_level=0.5)
            gp = GaussianProcessRegressor(kernel=kern, normalize_y=True, random_state=seed)
            gp.fit(X_mat[obs], y_vec[obs])
            mu_u, std_u = gp.predict(X_mat[unseen], return_std=True)
            if strategy == "ei":
                sc = acq_ei(mu_u, std_u, y_vec[obs].max(), xi=0.5)
            elif strategy == "ucb":
                sc = acq_ucb(mu_u, std_u, kappa=2.0)
            elif strategy == "pi":
                sc = acq_pi(mu_u, std_u, y_vec[obs].max(), xi=1.0)
            nxt = int(unseen[int(np.argmax(sc))])
        obs.append(nxt)
        hist.append(float(y_vec[obs].max()))
    return np.array(hist)

seeds = [0, 1, 2, 3, 4]
curves_rand    = np.array([run_bh_campaign(X_bh_oh,   y_yield, seed=s, strategy="random") for s in seeds])
curves_oh_ei   = np.array([run_bh_campaign(X_bh_oh,   y_yield, seed=s, strategy="ei")     for s in seeds])
curves_chem_ei = np.array([run_bh_campaign(X_bh_chem, y_yield, seed=s, strategy="ei")     for s in seeds])
curves_chem_ucb= np.array([run_bh_campaign(X_bh_chem, y_yield, seed=s, strategy="ucb")    for s in seeds])

steps_x = np.arange(5, 26)
fig, ax = plt.subplots(figsize=(8.0, 4.4))
for label, mat, col, ls in [
    ("Random Search",                         curves_rand,     C.slate,   "--"),
    ("BO-EI (One-Hot Component IDs)",         curves_oh_ei,    C.gold,    "-."),
    ("BO-UCB (PhysChem Formula Descriptors)", curves_chem_ucb, C.teal,    "-"),
    ("BO-EI (PhysChem Formula Descriptors)",  curves_chem_ei,  C.navy,    "-"),
]:
    m_c, s_c = mat.mean(0), mat.std(0)
    ax.plot(steps_x, m_c, color=col, ls=ls, lw=2.2, label=f"{label} (25-exp: {m_c[-1]:.1f}%)")
    ax.fill_between(steps_x, m_c - 0.5 * s_c, m_c + 0.5 * s_c, color=col, alpha=0.12)

ax.axhline(y_yield.max(), color=C.crimson, ls=":", lw=1.4, label=f"Library Global Max ({y_yield.max():.1f}%)")
ax.set_xlabel("Total Number of Experiments Conducted (Out of 3,955)")
ax.set_ylabel("Best Reaction Yield Found So Far (%)")
ax.set_title("Buchwald-Hartwig High-Throughput Coupling Optimization (<0.7% Budget)")
ax.legend(fontsize=8.2, loc="lower right")
plt.tight_layout()
plt.show()
Out:
反应总数: 3,955 | One-Hot 维度: 44 | 物化组成 PCA 维度: 18
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
Notebook 输出图像

🏋️ 练习 04b-2:在 Buchwald–Hartwig 偶联反应上对比 PI、EI 与 UCB

使用上面构建好的 18 维无标签物化组成特征 X_bh_chem,在 seeds = [0, 1, 2] 上对比 strategy = "pi"、strategy = "ei" 与 strategy = "ucb" 在第 15 次实验和第 25 次实验时找到的平均最高产率。

In [9] · Python
# 在下方填写你的代码:

4. 贝叶斯超参数优化(Bayesian HPO vs Random Search 调优 XGBRegressor)

把“一组机器学习超参数配置 \(\boldsymbol{\theta}\)”看作配方,把“交叉验证负误差 \(-\text{RMSE}(\boldsymbol{\theta})\)”看作产率——调参本身就是一个典型的贝叶斯优化任务!下面我们在 AqSolDB 单组分分子子集(1,500 分子)上构建四维 XGBRegressor 超参数空间(learning_rate \(\times\) max_depth \(\times\) subsample \(\times\) colsample_bytree = 270 种配置),仅用 18 次评估对比 GP-EI 贝叶斯调参与随机搜索:

In [10] · Python
raw_sol = pd.read_csv(find_file("solubility.csv"))
fcols_17 = [
    "MolWt", "MolLogP", "MolMR", "HeavyAtomCount", "NumHAcceptors", "NumHDonors",
    "NumHeteroatoms", "NumRotatableBonds", "NumValenceElectrons", "NumAromaticRings",
    "NumSaturatedRings", "NumAliphaticRings", "RingCount", "TPSA", "LabuteASA",
    "BalabanJ", "BertzCT",
]
sol_clean = raw_sol[~raw_sol["SMILES"].str.contains(r"\.", na=False)].dropna(subset=fcols_17 + ["Solubility"]).reset_index(drop=True)
X_hpo_data = sol_clean[fcols_17].values[:1500]
y_hpo_data = sol_clean["Solubility"].values[:1500]
kf3 = KFold(n_splits=3, shuffle=True, random_state=42)

lrs = np.logspace(-2.6, -0.02, 10)
depths = [1, 2, 3, 5, 8, 12]
subs = [0.4, 0.7, 1.0]
reg_lams = [1e-2, 1.0, 20.0]
hpo_grid = np.array([[np.log10(lr), d, s, np.log10(lam)] for lr in lrs for d in depths for s in subs for lam in reg_lams])
X_hpo_norm = (hpo_grid - hpo_grid.min(0)) / (hpo_grid.max(0) - hpo_grid.min(0))

_xgb_cache = {}
def eval_xgb_cv(idx: int) -> float:
    if idx not in _xgb_cache:
        log_lr, d, s, log_lam = hpo_grid[idx]
        model = XGBRegressor(
            n_estimators=95, learning_rate=float(10 ** log_lr), max_depth=int(d),
            subsample=float(s), reg_lambda=float(10 ** log_lam), random_state=42, n_jobs=2, verbosity=0,
        )
        sc = cross_val_score(model, X_hpo_data, y_hpo_data, cv=kf3, scoring="neg_root_mean_squared_error")
        _xgb_cache[idx] = float(-sc.mean())
    return _xgb_cache[idx]

n_budget, n_init_h = 22, 5
bo_hpo, rnd_hpo = [], []
for seed_h in range(6):
    rng_h = np.random.default_rng(seed_h + 10)
    r_picks = rng_h.choice(len(hpo_grid), size=n_budget, replace=False)
    rnd_hpo.append(np.minimum.accumulate([eval_xgb_cv(int(i)) for i in r_picks]))

    vis = [int(i) for i in r_picks[:n_init_h]]
    y_neg_rmse = [-eval_xgb_cv(i) for i in vis]
    for _ in range(n_budget - n_init_h):
        gp_h = GaussianProcessRegressor(
            kernel=ConstantKernel(1.0, (0.1, 10.0)) * Matern(length_scale=0.45, length_scale_bounds=(0.18, 2.0), nu=2.5) + WhiteKernel(1e-3, (1e-5, 0.2)),
            normalize_y=True, random_state=42,
        ).fit(X_hpo_norm[vis], y_neg_rmse)
        cand = [i for i in range(len(hpo_grid)) if i not in vis]
        mc, sc = gp_h.predict(X_hpo_norm[cand], return_std=True)
        nxt = cand[int(np.argmax(acq_ei(mc, sc, max(y_neg_rmse), xi=0.005)))]
        vis.append(nxt)
        y_neg_rmse.append(-eval_xgb_cv(nxt))
    bo_hpo.append(np.minimum.accumulate([-v for v in y_neg_rmse]))

bo_arr, rnd_arr = np.array(bo_hpo), np.array(rnd_hpo)
ev_x = np.arange(1, n_budget + 1)

fig, ax = plt.subplots(figsize=(6.8, 3.8))
ax.plot(ev_x, rnd_arr.mean(0), "o--", color=C.slate, label="Random Search (5 seeds)")
ax.fill_between(ev_x, rnd_arr.mean(0) - rnd_arr.std(0), rnd_arr.mean(0) + rnd_arr.std(0), color=C.slate, alpha=0.14)
ax.plot(ev_x, bo_arr.mean(0), "s-", color=C.navy, lw=2.2, label="Bayesian HPO (GP-EI tuning XGBoost)")
ax.fill_between(ev_x, bo_arr.mean(0) - bo_arr.std(0), bo_arr.mean(0) + bo_arr.std(0), color=C.navy, alpha=0.16)
ax.axvline(n_init_h + 0.5, color=C.gold, ls=":", lw=1.4, label=f"End of Random Init (n={n_init_h})")
ax.set_xlabel("Number of XGBoost Hyperparameter Evaluations")
ax.set_ylabel("Best 3-Fold CV RMSE Found So Far (logS)")
ax.set_title(f"Bayesian Hyperparameter Optimization vs Random Search ({len(hpo_grid)} Grid)")
ax.legend(fontsize=8.3)
plt.tight_layout()
plt.show()

best_cfg_idx = min(_xgb_cache, key=_xgb_cache.get)
b_lr, b_d, b_s, b_lam = hpo_grid[best_cfg_idx]
print(f"仅评估 {n_budget}/{len(hpo_grid)} ({n_budget/len(hpo_grid):.1%}) 配置:Bayesian HPO 平均最佳 RMSE = {bo_arr[:,-1].mean():.3f} vs 随机搜索 = {rnd_arr[:,-1].mean():.3f}")
print(f"最佳 XGBoost 超参数示例: lr={10**b_lr:.3f}, max_depth={int(b_d)}, subsample={b_s:.1f}, reg_lambda={10**b_lam:.2f}")
Out:
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:450: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified upper bound 0.2. Increasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:450: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified upper bound 0.2. Increasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k2__length_scale is close to the specified lower bound 0.18. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k2__length_scale is close to the specified lower bound 0.18. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:450: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified upper bound 0.2. Increasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
Notebook 输出图像
仅评估 22/540 (4.1%) 配置:Bayesian HPO 平均最佳 RMSE = 1.102 vs 随机搜索 = 1.107
最佳 XGBoost 超参数示例: lr=0.068, max_depth=8, subsample=0.4, reg_lambda=20.00

5. 多目标帕累托贝叶斯优化与自动驾驶实验室(Multi-Objective Pareto BO & Self-Driving Labs — LiU L08)

📘 5.1 现实材料从不只看单一指标:帕累托前沿(Pareto Front)与超体积(Hypervolume)

真实的工程材料几乎总是**多目标相互掣肘(Conflicting Trade-offs)**的(对齐 LiU Lecture 08 P55–61):

  • 高强钢既想要高抗拉强度,又想要高断裂韧性;
  • 透明导电氧化物(TCO,如掺锡氧化铟/氧化锌薄膜)既想要高电导率 \(\log_{10}\sigma\)(需要高载流子浓度与高温退火结晶),又想要宽光学带隙/高可见光透光率 \(E_g\)(过量掺杂与高温氧空位会诱发带尾吸收导致透光下降)!

当两个目标 \(y_1, y_2\)(均希望越大越好)冲突时,不存在唯一的“单点冠军”,而是存在一条帕累托非支配前沿(Pareto Non-Dominated Front):

  • 若配方 \(A\) 在所有目标上都不差于 \(B\),且至少在一个目标上严格优于 \(B\),则称 \(A\) 支配(Dominates)\(B\);
  • 没有任何其他配方能够支配的全体最优折中解集合,即为帕累托前沿(Pareto Front);前沿与参考底线点 \(\mathbf{r}_{\text{ref}}\) 围成的面积称为超体积(Hypervolume, HV,越大代表前沿整体推进得越远)!

下面我们模拟三维溅射/退火工艺空间 \((T_{\text{anneal}},\; f_{\text{dopant}},\; P_{\text{O}_2})\) 上的 600 种薄膜工艺,为电导率 \(\log_{10}\sigma\) 和光学带隙 \(E_g\) 分别建立独立高斯过程 \(\text{GP}_1, \text{GP}_2\),通过**随机化切比雪夫标量化置信上界(ParEGO / Scalarized UCB)**每步切换不同的权衡方向探索整条帕累托前沿:

In [11] · Python
def is_pareto_efficient(Y: np.ndarray) -> np.ndarray:
    '''给定 (N, M) 目标矩阵(均以越大越好为准),返回布尔掩码标记非支配帕累托前沿点'''
    is_eff = np.ones(len(Y), dtype=bool)
    for i, y_i in enumerate(Y):
        if is_eff[i]:
            # 保留没有被任何其他点严格支配的样本
            dominated = np.all(Y >= y_i, axis=1) & np.any(Y > y_i, axis=1)
            if np.any(dominated):
                is_eff[i] = False
    return is_eff

def compute_hv_2d(Y_obs: np.ndarray, ref_pt: np.ndarray) -> float:
    '''计算二维最大化目标集合相对于参考底线点 ref_pt 的精确帕累托超体积 (Hypervolume)'''
    valid = Y_obs[(Y_obs[:, 0] > ref_pt[0]) & (Y_obs[:, 1] > ref_pt[1])]
    if len(valid) == 0:
        return 0.0
    front = valid[is_pareto_efficient(valid)]
    front = front[np.argsort(front[:, 0])]   # 按目标 1 升序排列,此时目标 2 单调递减
    hv = 0.0
    prev_x = ref_pt[0]
    for x_val, y_val in front:
        hv += (x_val - prev_x) * (y_val - ref_pt[1])
        prev_x = x_val
    return float(hv)

# 构造 600 个三维薄膜沉积工艺候选点:(T_anneal in [150, 450] °C, f_dopant in [0, 0.15], log10_PO2 in [-1, 1])
rng_mo = np.random.default_rng(42)
X_tco = rng_mo.uniform(0.0, 1.0, size=(600, 3))
T_n, f_n, P_n = X_tco[:, 0], X_tco[:, 1], X_tco[:, 2]

# 目标 1: 电导率 log10(sigma) [S/cm] —— 随适度掺杂 (f_n~0.65)、高温退火 (T_n~0.85) 和低氧压升高
cond_log = 1.2 + 2.6 * np.exp(-((f_n - 0.68) / 0.32) ** 2) * (0.4 + 0.6 * T_n) - 0.9 * P_n - 0.25 * (T_n - 0.85) ** 2
# 目标 2: 光学带隙 Eg [eV] —— 高氧压抑制氧空位、温和退火温度与低缺陷散射保持宽带隙,但与高电导率形成天然帕累托折中!
bandgap_eg = 3.05 + 0.55 * P_n - 0.48 * (T_n ** 1.4) + 0.22 * f_n - 0.55 * (f_n ** 2.2)
Y_tco = np.column_stack([cond_log, bandgap_eg])

true_pareto_mask = is_pareto_efficient(Y_tco)
ref_point = np.array([1.50, 2.75])
true_max_hv = compute_hv_2d(Y_tco, ref_point)

def run_mobo_tco(n_init=6, n_steps=18, seed=0, mode="mobo"):
    rng = np.random.default_rng(seed)
    obs = list(rng.choice(len(X_tco), size=n_init, replace=False))
    hv_trace = [compute_hv_2d(Y_tco[obs], ref_point)]

    for step in range(n_steps):
        unseen = np.setdiff1d(np.arange(len(X_tco)), obs)
        if mode == "random":
            nxt = int(rng.choice(unseen))
        else:
            gp1 = GaussianProcessRegressor(ConstantKernel(1.0) * Matern(0.4, nu=2.5), alpha=1e-4, normalize_y=True).fit(X_tco[obs], Y_tco[obs, 0])
            gp2 = GaussianProcessRegressor(ConstantKernel(1.0) * Matern(0.4, nu=2.5), alpha=1e-4, normalize_y=True).fit(X_tco[obs], Y_tco[obs, 1])
            m1, s1 = gp1.predict(X_tco[unseen], return_std=True)
            m2, s2 = gp2.predict(X_tco[unseen], return_std=True)
            # 归一化两个目标的 UCB 上界,并用随机权重扫过整条凸/非凸帕累托前沿 (ParEGO 思想)
            u1 = (m1 + 1.8 * s1 - Y_tco[obs, 0].min()) / (np.ptp(Y_tco[obs, 0]) + 1e-6)
            u2 = (m2 + 1.8 * s2 - Y_tco[obs, 1].min()) / (np.ptp(Y_tco[obs, 1]) + 1e-6)
            w = rng.uniform(0.05, 0.95)
            chebyshev = np.minimum(w * u1, (1 - w) * u2) + 0.15 * (w * u1 + (1 - w) * u2)
            nxt = int(unseen[int(np.argmax(chebyshev))])
        obs.append(nxt)
        hv_trace.append(compute_hv_2d(Y_tco[obs], ref_point))
    return obs, np.array(hv_trace)

obs_mo, hv_mo = run_mobo_tco(seed=3, mode="mobo")
hv_mo_seeds   = np.array([run_mobo_tco(seed=s, mode="mobo")[1]   for s in range(6)])
hv_rnd_seeds  = np.array([run_mobo_tco(seed=s, mode="random")[1] for s in range(6)])

found_front_mask = is_pareto_efficient(Y_tco[obs_mo])
Y_found_front = Y_tco[obs_mo][found_front_mask]
Y_found_front = Y_found_front[np.argsort(Y_found_front[:, 0])]
Y_true_front  = Y_tco[true_pareto_mask]
Y_true_front  = Y_true_front[np.argsort(Y_true_front[:, 0])]

fig, axes = plt.subplots(1, 2, figsize=(12.2, 4.3))

axes[0].scatter(Y_tco[:, 0], Y_tco[:, 1], s=14, color="#cbd5e1", alpha=0.65, label="600 Candidate TCO Recipes")
axes[0].plot(Y_true_front[:, 0], Y_true_front[:, 1], "k--", lw=1.6, label="True Global Pareto Front")
axes[0].scatter(Y_tco[obs_mo, 0], Y_tco[obs_mo, 1], s=36, color=C.steel, alpha=0.8, label="MOBO Sampled (24 exps)")
axes[0].plot(Y_found_front[:, 0], Y_found_front[:, 1], "o-", color=C.crimson, lw=2.2, markersize=6.5, label="Discovered Pareto Front")
axes[0].set_xlabel(r"Electrical Conductivity $\log_{10}\sigma$ (S/cm) [Maximize ->]")
axes[0].set_ylabel("Optical Bandgap E_g (eV) [Maximize ->]")
axes[0].set_title("2-Objective Pareto Optimization: Conductivity vs Bandgap")
axes[0].legend(fontsize=8.0, loc="lower left")

st_mo = np.arange(6, 25)
axes[1].plot(st_mo, hv_rnd_seeds.mean(0), "o--", color=C.slate, label="Random Search (6 seeds)")
axes[1].fill_between(st_mo, hv_rnd_seeds.mean(0) - hv_rnd_seeds.std(0), hv_rnd_seeds.mean(0) + hv_rnd_seeds.std(0), color=C.slate, alpha=0.14)
axes[1].plot(st_mo, hv_mo_seeds.mean(0), "s-", color=C.navy, lw=2.2, label="Multi-Objective BO (ParEGO-UCB)")
axes[1].fill_between(st_mo, hv_mo_seeds.mean(0) - hv_mo_seeds.std(0), hv_mo_seeds.mean(0) + hv_mo_seeds.std(0), color=C.navy, alpha=0.16)
axes[1].axhline(true_max_hv, color=C.crimson, ls=":", lw=1.4, label=f"Max Possible HV ({true_max_hv:.3f})")
axes[1].set_xlabel("Total Thin-Film Experiments Conducted")
axes[1].set_ylabel("Dominated Hypervolume (HV)")
axes[1].set_title("Pareto Hypervolume Convergence")
axes[1].legend(fontsize=8.2, loc="lower right")

plt.tight_layout()
plt.show()

print(f"24 次实验覆盖的帕累托超体积占比:Multi-Objective BO = {hv_mo_seeds[:,-1].mean()/true_max_hv:.1%}  vs.  随机搜索 = {hv_rnd_seeds[:,-1].mean()/true_max_hv:.1%}")
Out:
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\_gpr.py:670: ConvergenceWarning: lbfgs failed to converge after 12 iteration(s) (status=2):
ABNORMAL: 

You might also want to scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html
  _check_optimize_result("lbfgs", opt_res)
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\_gpr.py:670: ConvergenceWarning: lbfgs failed to converge after 10 iteration(s) (status=2):
ABNORMAL: 

You might also want to scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html
  _check_optimize_result("lbfgs", opt_res)
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\_gpr.py:670: ConvergenceWarning: lbfgs failed to converge after 11 iteration(s) (status=2):
ABNORMAL: 

You might also want to scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html
  _check_optimize_result("lbfgs", opt_res)
Notebook 输出图像
24 次实验覆盖的帕累托超体积占比:Multi-Objective BO = 84.6%  vs.  随机搜索 = 68.2%

📘 5.2 闭环自动驾驶实验室(Self-Driving Labs, SDL)与并行批次推荐(Kriging Believer)

在现代自动化材料实验室(Self-Driving Lab)中,液体处理工作站、旋涂机械臂与在线光谱/电学表征组成了 24 小时不间断运转的物理闭环。这里有一个非常关键的工程并行瓶颈:

  • 机器人反应架一次往往能同时平行合成 \(q = 4\) 个(或 8/24 孔板)样品;
  • 🤔 先猜一猜:如果直接从单步 EI 排名里硬取前 4 名(Naive Top-4 EI)交给机器人同时做,会发生什么灾难? 答案是:这 4 个实验会全部挤在同一个采集函数尖峰的毫米级邻域内,相当于把同一个实验重复做了 4 遍,白白浪费了 3 个机器人通道!

工业界自动驾驶实验室最常用的解决方案是 克里金假想观测策略(Kriging Believer Batch BO):

  1. 选出当前 EI 最高的第 1 个配方 \(\mathbf{x}^{(1)}\);
  2. 虽然真实产率要等几小时反应结束才知道,但我们先暂时相信 GP 自己的均值预测 \(\hat{y}^{(1)} = \mu(\mathbf{x}^{(1)})\),将假想点 \((\mathbf{x}^{(1)}, \hat{y}^{(1)})\) 塞进训练集更新 GP——这会立刻把 \(\mathbf{x}^{(1)}\) 附近的后验不确定性 \(\sigma\) 压扁归零!
  3. 在更新后的采集函数上选出自动避开第 1 点的第 2 个配方 \(\mathbf{x}^{(2)}\),依此循环凑齐一整块 4 通道高多样性推荐孔板!

▶️ 运行看看:先直观看到单轮 4 通道孔板上 Naive Top-4 与 Kriging Believer 的空间分散差异,再在 Buchwald–Hartwig 偶联库上运行 5 轮机器人 4 孔板闭环实验(仅耗时 5 轮物理实验周期 = 20 个反应)!

In [12] · Python
# (1) 1D 直观对比:Naive Top-4 EI (扎堆浪费通道) vs Kriging Believer Batch-4 (自动分散覆盖双峰)
gp_demo = GaussianProcessRegressor(ConstantKernel(1.0) * RBF(1.0), alpha=1e-5).fit(X_init, y_init)
mu_d, std_d = gp_demo.predict(X_grid, return_std=True)
ei_d = acq_ei(mu_d, std_d, y_init.max(), xi=0.01)

# Naive Top-4 (在离散候选点上直接取前 4 名)
cand_idx_demo = np.linspace(0, len(X_grid) - 1, 60, dtype=int)
X_cand_1d = X_grid[cand_idx_demo]
mu_c1, std_c1 = gp_demo.predict(X_cand_1d, return_std=True)
naive_top4 = X_cand_1d[np.argsort(acq_ei(mu_c1, std_c1, y_init.max(), xi=0.01))[::-1][:4]]

# Kriging Believer Batch-4
X_fan, y_fan = X_init.copy(), y_init.copy()
kb_batch4 = []
for _ in range(4):
    gp_f = GaussianProcessRegressor(ConstantKernel(1.0) * RBF(1.0), alpha=1e-5).fit(X_fan, y_fan)
    mf, sf = gp_f.predict(X_cand_1d, return_std=True)
    eif = acq_ei(mf, sf, y_init.max(), xi=0.01)
    pick_i = int(np.argmax(eif))
    x_pick = X_cand_1d[pick_i]
    kb_batch4.append(x_pick[0])
    # 将 GP 当前预测均值作为“假想观测值 (Fantasy Observation)”压低该处方差!
    X_fan = np.vstack([X_fan, x_pick.reshape(1, 1)])
    y_fan = np.append(y_fan, mf[pick_i])

# (2) 真实 Buchwald-Hartwig 自驾驶实验室模拟:4 初始点 + 5 轮 × 4 孔板并行实验 (共 24 个反应,仅需 5 轮实验时间!)
def run_sdl_plate_campaign(X_mat, y_vec, batch_q=4, n_rounds=5, seed=0, mode="kriging_believer"):
    rng = np.random.default_rng(seed)
    obs = list(rng.choice(len(y_vec), size=4, replace=False))
    round_best = [float(y_vec[obs].max())]

    for _ in range(n_rounds):
        unseen = list(np.setdiff1d(np.arange(len(y_vec)), obs))
        if mode == "random":
            plate = list(rng.choice(unseen, size=batch_q, replace=False))
        elif mode == "naive_top_q":
            kern = ConstantKernel(1.0) * Matern(2.0, nu=1.5) + WhiteKernel(0.5)
            gp = GaussianProcessRegressor(kern, normalize_y=True, random_state=seed).fit(X_mat[obs], y_vec[obs])
            m_u, s_u = gp.predict(X_mat[unseen], return_std=True)
            top_q_pos = np.argsort(acq_ei(m_u, s_u, y_vec[obs].max(), xi=0.5))[::-1][:batch_q]
            plate = [unseen[int(i)] for i in top_q_pos]
        elif mode == "kriging_believer":
            X_f, y_f = X_mat[obs].copy(), y_vec[obs].copy()
            y_real_best = float(y_vec[obs].max())
            rem_pool = list(unseen)
            plate = []
            for _w in range(batch_q):
                kern = ConstantKernel(1.0) * Matern(2.0, nu=1.5) + WhiteKernel(0.5)
                gp_w = GaussianProcessRegressor(kern, normalize_y=True, random_state=seed).fit(X_f, y_f)
                m_w, s_w = gp_w.predict(X_mat[rem_pool], return_std=True)
                best_pos = int(np.argmax(acq_ei(m_w, s_w, y_real_best, xi=0.5)))
                chosen_id = rem_pool.pop(best_pos)
                plate.append(chosen_id)
                X_f = np.vstack([X_f, X_mat[chosen_id]])
                y_f = np.append(y_f, m_w[best_pos])   # Kriging Believer 假想均值占位

        obs.extend(plate)   # 机器人并行跑完一整块 4 孔板后,一次性回传真实实验产率!
        round_best.append(float(y_vec[obs].max()))
    return np.array(round_best)

sdl_seeds = [0, 1, 2, 3, 4]
sdl_rnd   = np.array([run_sdl_plate_campaign(X_bh_chem, y_yield, seed=s, mode="random")           for s in sdl_seeds])
sdl_naive = np.array([run_sdl_plate_campaign(X_bh_chem, y_yield, seed=s, mode="naive_top_q")      for s in sdl_seeds])
sdl_kb    = np.array([run_sdl_plate_campaign(X_bh_chem, y_yield, seed=s, mode="kriging_believer") for s in sdl_seeds])

fig, axes = plt.subplots(1, 2, figsize=(12.4, 4.1))

axes[0].plot(X_grid.ravel(), ei_d / (ei_d.max() + 1e-9), color=C.teal, lw=2.0, label="Single-Point EI Curve")
for i, xv in enumerate(naive_top4.ravel()):
    axes[0].axvline(xv, color=C.crimson, ls="--", lw=1.6, alpha=0.8, label="Naive Top-4 (Clumped!)" if i == 0 else None)
for i, xv in enumerate(kb_batch4):
    axes[0].scatter([xv], [0.08], color=C.navy, s=110, marker="v", zorder=6, label="Kriging Believer 4-Well Plate" if i == 0 else None)
axes[0].set_xlabel("Process Parameter x")
axes[0].set_ylabel("Normalized EI")
axes[0].set_title("Parallel 4-Well Selection: Clumping vs Kriging Believer")
axes[0].legend(fontsize=8.2, loc="upper left")

rounds_x = np.arange(0, 6)
for name, mat, col, ls in [
    ("Random 4-Well Plates",           sdl_rnd,   C.slate,   "--"),
    ("Naive Top-4 EI Plates",          sdl_naive, C.gold,    "-."),
    ("Kriging Believer Batch-4 SDL",   sdl_kb,    C.navy,    "-"),
]:
    axes[1].plot(rounds_x, mat.mean(0), "o", ls=ls, color=col, lw=2.1, label=f"{name} (Round 5: {mat[:,-1].mean():.1f}%)")
axes[1].set_xlabel("Robotic 4-Well Plate Round (4 Reactions in Parallel / Round)")
axes[1].set_ylabel("Best Yield Found (%)")
axes[1].set_title("Self-Driving Lab Campaign on Buchwald-Hartwig (5 Rounds)")
axes[1].legend(fontsize=8.2, loc="lower right")

plt.tight_layout()
plt.show()

print("Naive Top-4 推荐的 4 个平行温度点       :", np.round(naive_top4.ravel(), 2))
print("Kriging Believer 推荐的 4 个平行温度点 :", np.round(kb_batch4, 2))
Out:
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k2__noise_level is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
C:\Users\18101\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\gaussian_process\kernels.py:440: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__k1__constant_value is close to the specified lower bound 1e-05. Decreasing the bound and calling fit again may find a better value.
  warnings.warn(
Notebook 输出图像
Naive Top-4 推荐的 4 个平行温度点       : [ 2.54  2.71  2.34 10.  ]
Kriging Believer 推荐的 4 个平行温度点 : [ 2.54 10.    7.26  5.59]

🏋️ 练习 04b-3:在二维合成工艺窗口上手写实现 Kriging Believer 4 通道并行选点

回到第 2 节的二维薄膜工艺平面 X_2d_norm / y_2d_true(900 个候选点):

  1. 从初始 4 个点 init_4 = [40, 120, 310, 620] 出发,运行 3 轮 q = 4 并行孔板实验(每轮内部用 Kriging Believer 假想观测依次挑出 4 个互不扎堆的工艺点,整轮结束后再统一揭晓真实性能 y_2d_true);
  2. 打印每轮结束后的最高薄膜效率,并在二维等高线图上用不同颜色标出第 1、2、3 轮机器人孔板选中的各 4 个点!
In [13] · Python
# 在下方填写你的代码:

小结:第四讲(贝叶斯推断、贝叶斯优化与自动驾驶实验室)知识全景

模块 核心算法与概念(对齐 LiU L08) 解决的材料与化学实验痛点
04a 贝叶斯推断与 GPR 贝叶斯定理序贯更新、GaussianNB、多元高斯条件切片、RBF/Matern/WhiteKernel、17D 适用域预警 在带噪小样本实验上同步输出预测值 \(\mu\) 与不确定度 \(\sigma\),自动识别域外新材料风险
04b 单目标与组合 BO 四步闭环、PI / EI / UCB 采集函数、物化组成描述符、Bayesian HPO (XGBRegressor) 在 3,955 种催化偶联组合中仅用 <0.7% 实验量找到 >95% 产率配方,并加速模型调参
04b 多目标与自驾驶实验室 帕累托前沿 is_pareto_efficient、超体积 HV、ParEGO 多目标 BO、Kriging Believer 并行批次推荐 同时权衡电导率与光学带隙冲突指标,赋能多通道机器人孔板闭环自动驾驶实验室(SDL)

下一讲预告(05):完成经典监督学习、无监督/半监督流形学习与贝叶斯主动实验设计后,下一讲我们将深入分子与晶体特征工程(Feature Engineering & Molecular Representations)——正式解锁化学结构解析、2048 维 Morgan 指纹、Taylor–Butina 球形排除聚类、Tanimoto 分子核与 SHAP 可解释性归因!

读完了?

标记为已学完,进度会同步到课程大纲与首页的元素周期表。

返回模块 04