贝叶斯优化(一):代码篇(可视化)

参考开源代码: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都不大,均值可以决定下一刻的点,从而找到最大值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值