参数网格搜索过程
param_search(DATA,x_range,y_range,x_step,y_step)
# 网格化参数组合-以二维参数为例
# 每个参数的设置范围和步长可调整
# DATA - 数据集
params = [] # 初始化参数空间
for x in x_range: # 参数1取样
for y in y_range: # 参数2取样
params.append([x, y]]) # 送入参数表-注意步长
score = [] # 初始化评分结果
for param in params: # 遍历参数表
score = model(DATA, param) # 计算评分
score_ranking = sorted(score) # 评分排序
best_score = score_ranking[0] # 抽取最优评分
best_param = params[best_score_NO] # 最优评分对应的参数
自动精细化搜索
auto_param_search(DATA,x_range,y_range,x_step,y_step)
old_step = 10 # 原粗略网格搜索步长
new_step = 1 # 新精细网格搜索步长
new_step_num = 10 # 更新的参数采样数目
x_step, y_step = old_step, old_step # 为便于并行计算进行相同赋值
# 1 - 粗筛参数
best_param_x, best_param_y =
param_search(DATA,x_range,y_range,x_step,y_step)
# 更新后的参数网格
x_new_range =
get_range(best_param_x - old_step, best_param_x + old_step,
new_step_num)
y_new_range =
get_range(best_param_y - old_step, best_param_x + old_step,
new_step_num)
# 2 - 精筛参数
x_step, y_step = new_step, new_step
best_param_new =
param_search(DATA,x_range,y_range,x_step,y_step)
# 注 - 也可叠加网格缩放比例来达到多重缩放效果
加速参数计算
accelerate_param_search(DATA,x_range,y_range,x_step,y_step)
# 注-此方法暂时只适用于类似正态分布的优化曲面
# x_range - 人工初筛后的参数1取样空间
# y_range - 人工初筛后的参数2取样空间
# step_fast - 快速移动步长
# step_low - 慢速移动步长
# 初始化评分结果
score_old = 0
score_new = 1
for x in x_iter_times: # 参数1迭代次数
for y in y_iter_times: # 参数2迭代次数
if score_new > score_old:
x = x_range_min + step
y = y_range_min + step
score_new = model(DATA, x, y) # 计算评分
if score_new < score_old:
step = step/2
x = x_range_min - step
y = y_range_min - step
score_new = model(DATA, x, y) # 计算评分
if abs(score_new - score_old) < 1e2:
break