119 lines
3.2 KiB
Markdown
119 lines
3.2 KiB
Markdown
---
|
||
phase: 11-predictv3
|
||
plan: 04
|
||
subsystem: predictV3
|
||
tags:
|
||
- 权重优化
|
||
- 网格搜索
|
||
- 回测
|
||
- 参数调优
|
||
dependencies:
|
||
requires:
|
||
- 11-01
|
||
- 11-02
|
||
provides:
|
||
- optimizeWeights API
|
||
- _optimizeWeightsGridSearch method
|
||
affects:
|
||
- History.php model
|
||
- History.php controller
|
||
tech_stack:
|
||
added:
|
||
- 权重网格搜索优化
|
||
- 综合评分公式
|
||
- 超时保护机制
|
||
patterns:
|
||
- 预定义配置集
|
||
- 批量回测比较
|
||
key_files:
|
||
created: []
|
||
modified:
|
||
- path: application/admin/model/History.php
|
||
changes: 新增 _optimizeWeightsGridSearch 方法(约160行)
|
||
- path: application/admin/controller/History.php
|
||
changes: 新增 optimizeWeights 接口入口,更新 noNeedRight 数组
|
||
decisions:
|
||
- 采用5种预定义权重配置进行网格搜索,而非随机参数空间搜索
|
||
- 综合评分公式:hit_rate * 0.6 + ndcg_5 * 100 * 0.4,命中率权重更高
|
||
- 超时保护默认60秒,允许用户自定义10-120秒范围
|
||
metrics:
|
||
duration: 2min
|
||
completed_date: 2026-05-01
|
||
task_count: 2
|
||
file_count: 2
|
||
---
|
||
|
||
# Phase 11 Plan 04: 权重网格搜索优化
|
||
|
||
## Summary
|
||
|
||
实现权重网格搜索优化功能,通过5种预定义权重配置批量回测,找出最优权重配置,提升算法预测准确性。
|
||
|
||
## Changes
|
||
|
||
### Model: _optimizeWeightsGridSearch 方法
|
||
|
||
在 `application/admin/model/History.php` 新增私有方法,实现权重网格搜索优化:
|
||
|
||
- **5种预定义配置**:
|
||
- 遗漏优先型:omit_regression=0.25(最高)
|
||
- 转移概率优先型:transition_prob=0.25(最高)
|
||
- 走势方向优先型:trend_direction=0.25(最高)
|
||
- 平衡型:各维度权重较均衡
|
||
- 组合特征优先型:combination=0.20(最高)
|
||
|
||
- **优化目标**:综合得分 = hit_rate * 0.6 + ndcg_5 * 100 * 0.4
|
||
|
||
- **超时保护**:默认60秒,超时后停止剩余配置测试,返回已完成结果
|
||
|
||
- **返回结构**:
|
||
```php
|
||
[
|
||
'best_weights' => [], // 最优权重配置
|
||
'best_hit_rate' => float, // 最优命中率
|
||
'best_ndcg' => float, // 最优NDCG
|
||
'best_combined_score' => float, // 最优综合得分
|
||
'all_results' => [], // 所有配置测试结果(按得分降序)
|
||
'periods' => int,
|
||
'backtest_count' => int,
|
||
'timeout_seconds' => int,
|
||
'timed_out' => bool, // 是否超时中断
|
||
'elapsed_time' => float // 实际耗时
|
||
]
|
||
```
|
||
|
||
### Controller: optimizeWeights 接口
|
||
|
||
在 `application/admin/controller/History.php` 新增公开方法:
|
||
|
||
- **参数验证**:
|
||
- periods:统计期数,范围50-500,默认200
|
||
- backtest:回测期数,范围10-100,默认30
|
||
- timeout:超时秒数,范围10-120,默认60
|
||
|
||
- **超时警告**:超时时返回警告消息和已完成测试数量
|
||
|
||
- **权限配置**:已添加到 noNeedRight 数组
|
||
|
||
## Verification
|
||
|
||
```bash
|
||
# grep 验证
|
||
grep -n "_optimizeWeightsGridSearch" application/admin/model/History.php
|
||
# 结果:3924行,方法签名存在
|
||
|
||
grep -n "optimizeWeights" application/admin/controller/History.php
|
||
# 结果:25行(noNeedRight)、506行(方法定义)、526行(方法调用)
|
||
```
|
||
|
||
## Deviations from Plan
|
||
|
||
None - plan executed exactly as written.
|
||
|
||
## Known Stubs
|
||
|
||
None.
|
||
|
||
## Threat Flags
|
||
|
||
None. |