参考开源代码:Bayesian Optimization
目的:找未知函数的最大值
1. 手动给初值
# 获取并评估初始点
next_point_to_probe = {"x": 1.6} # 直接使用 pbounds 的键名
target1 = target(**next_point_to_probe)
optimizer.register(params=next_point_to_probe, target=target1)
plot_gp(optimizer, x, y)
图给的信息有:已知1.6处的值
- 1.白色虚线是高斯过程的均值在x=1.6时和target重合,周围值也受该点值得影响(周围值初始是0)
- 2. 绿色是1.96*std,已知点的绿色范围最小
- 3.utility函数图 采用的ucb utility图由函数均值和均方差共同决定
2.下一个点
next_point_to_probe = optimizer.suggest()
print("Next point to probe is:", next_point_to_probe)
target2 = target(**next_point_to_probe)
print("Found the target value to be:", target2)
optimizer.register(
params=next_point_to_probe,
target=target2,
)
plot_gp(optimizer, x, y)
3.下一个点
next_point_to_probe = optimizer.suggest()
print("Next point to probe is:", next_point_to_probe)
target2 = target(**next_point_to_probe)
print("Found the target value to be:", target2)
optimizer.register(
params=next_point_to_probe,
target=target2,
)
plot_gp(optimizer, x, y)
4.下一个点
next_point_to_probe = optimizer.suggest()
print("Next point to probe is:", next_point_to_probe)
target2 = target(**next_point_to_probe)
print("Found the target value to be:", target2)
optimizer.register(
params=next_point_to_probe,
target=target2,
)
plot_gp(optimizer, x, y)
5.下一个点
next_point_to_probe = optimizer.suggest()
print("Next point to probe is:", next_point_to_probe)
target2 = target(**next_point_to_probe)
print("Found the target value to be:", target2)
optimizer.register(
params=next_point_to_probe,
target=target2,
)
plot_gp(optimizer, x, y)
6.下一个点
next_point_to_probe = optimizer.suggest()
print("Next point to probe is:", next_point_to_probe)
target2 = target(**next_point_to_probe)
print("Found the target value to be:", target2)
optimizer.register(
params=next_point_to_probe,
target=target2,
)
plot_gp(optimizer, x, y)
从上面的过程可以发现 下一点愈发集中在一个小范围,这说明收敛
从图上理解,下一点是均值和方差值都比较大的点,当kappa较小的时候,由均值决定,利用性强,容易局部最小,当kappa较大时,由方差决定,未被探索过的std大,探索性强。
当探索足够多的点后,std都不大,均值可以决定下一刻的点,从而找到最大值