docs(11-05): complete 二阶马尔可夫转移概率增强 plan
- 新增 _getTransitionMatrix2ndOrder、_calcTransitionScore2ndOrder 方法 - getPredictionV3 根据数据量自动选择一阶或二阶算法 - 阈值: 200期历史,状态对观察>=5次,比例>=30%
This commit is contained in:
+5
-4
@@ -4,14 +4,14 @@ milestone: v1.0
|
|||||||
milestone_name: milestone
|
milestone_name: milestone
|
||||||
status: verifying
|
status: verifying
|
||||||
stopped_at: context exhaustion at 95% (2026-04-30)
|
stopped_at: context exhaustion at 95% (2026-04-30)
|
||||||
last_updated: "2026-05-01T07:17:46.503Z"
|
last_updated: "2026-05-01T07:22:32.135Z"
|
||||||
last_activity: 2026-05-01
|
last_activity: 2026-05-01
|
||||||
progress:
|
progress:
|
||||||
total_phases: 11
|
total_phases: 11
|
||||||
completed_phases: 1
|
completed_phases: 1
|
||||||
total_plans: 8
|
total_plans: 8
|
||||||
completed_plans: 6
|
completed_plans: 7
|
||||||
percent: 75
|
percent: 88
|
||||||
---
|
---
|
||||||
|
|
||||||
# Project State
|
# Project State
|
||||||
@@ -30,7 +30,7 @@ Plan: 5 of 5 (planned)
|
|||||||
Status: Phase complete — ready for verification
|
Status: Phase complete — ready for verification
|
||||||
Last activity: 2026-05-01
|
Last activity: 2026-05-01
|
||||||
|
|
||||||
Progress: [████████░░] 75%
|
Progress: [█████████░] 88%
|
||||||
|
|
||||||
## Performance Metrics
|
## Performance Metrics
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@ Progress: [████████░░] 75%
|
|||||||
| Phase 11-predictv3 P01 | 5min | 3 tasks | 1 files |
|
| Phase 11-predictv3 P01 | 5min | 3 tasks | 1 files |
|
||||||
| Phase 11-predictv3 P02 | 2min | 2 tasks | 1 files |
|
| Phase 11-predictv3 P02 | 2min | 2 tasks | 1 files |
|
||||||
| Phase 11-predictv3 P04 | 2min | 2 tasks | 2 files |
|
| Phase 11-predictv3 P04 | 2min | 2 tasks | 2 files |
|
||||||
|
| Phase 11-predictv3 P05 | 5min | 3 tasks | 1 files |
|
||||||
|
|
||||||
## Accumulated Context
|
## Accumulated Context
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
phase: 11-predictv3
|
||||||
|
plan: 05
|
||||||
|
subsystem: prediction
|
||||||
|
tags: [markov, transition-probability, second-order, algorithm-enhancement]
|
||||||
|
dependency_graph:
|
||||||
|
requires: []
|
||||||
|
provides: [二阶马尔可夫转移矩阵构建, 二阶转移得分计算]
|
||||||
|
affects: [getPredictionV3]
|
||||||
|
tech_stack:
|
||||||
|
added: [二阶马尔可夫链, 拉普拉斯平滑, 状态对观察检查]
|
||||||
|
patterns: [conditional-algorithm-selection, fallback-strategy]
|
||||||
|
key_files:
|
||||||
|
created: []
|
||||||
|
modified:
|
||||||
|
- path: application/admin/model/History.php
|
||||||
|
changes: 新增 _getTransitionMatrix2ndOrder、_calcTransitionScore2ndOrder 方法,修改 getPredictionV3 集成二阶逻辑
|
||||||
|
decisions:
|
||||||
|
- 数据量阈值设为200期(而非100期),确保二阶概率估计稳定
|
||||||
|
- 状态对观察次数阈值设为5次,比例阈值30%
|
||||||
|
- 以tail类型状态空间(100)为基准判断二阶可用性
|
||||||
|
metrics:
|
||||||
|
duration: 5min
|
||||||
|
tasks: 3
|
||||||
|
files: 1
|
||||||
|
completed_date: 2026-05-01
|
||||||
|
---
|
||||||
|
|
||||||
|
# Phase 11 Plan 05: 二阶马尔可夫转移概率增强 Summary
|
||||||
|
|
||||||
|
## One-liner
|
||||||
|
|
||||||
|
实现二阶马尔可夫转移概率,根据数据量和状态对观察次数自动选择一阶或二阶算法,提升预测准确性。
|
||||||
|
|
||||||
|
## Implementation Details
|
||||||
|
|
||||||
|
### Task 1: 实现二阶马尔可夫转移矩阵构建方法
|
||||||
|
|
||||||
|
**File:** `application/admin/model/History.php`
|
||||||
|
|
||||||
|
新增 `_getTransitionMatrix2ndOrder` 方法:
|
||||||
|
- 状态空间从 N 扩展到 N^2(zone:25状态,tail:100状态,head:25状态)
|
||||||
|
- 状态键格式为 "prev1-prev2",如 "2-3" 表示前一期区域2、前两期区域3
|
||||||
|
- 使用拉普拉斯平滑处理避免零概率问题
|
||||||
|
- 返回 `sufficient_pairs`、`total_pairs`、`min_threshold` 供调用者判断是否足够稳定
|
||||||
|
|
||||||
|
### Task 2: 实现二阶转移概率得分计算方法
|
||||||
|
|
||||||
|
**File:** `application/admin/model/History.php`
|
||||||
|
|
||||||
|
新增 `_calcTransitionScore2ndOrder` 方法:
|
||||||
|
- 综合区域、尾号、首号三个维度的二阶转移概率
|
||||||
|
- 各维度权重:区域40%、尾号35%、首号25%
|
||||||
|
- 使用 `prob_matrix` 中对应状态键的概率值计算得分
|
||||||
|
|
||||||
|
### Task 3: 在 getPredictionV3 中集成二阶马尔可夫
|
||||||
|
|
||||||
|
**File:** `application/admin/model/History.php`
|
||||||
|
|
||||||
|
修改 `getPredictionV3` 方法:
|
||||||
|
- 根据历史数据量决定使用一阶或二阶马尔可夫
|
||||||
|
- 阈值条件:总期数 >= 200 且 状态对观察次数 >= 5 比例 >= 30%
|
||||||
|
- 以 tail 类型状态空间(100)为基准判断二阶可用性
|
||||||
|
- 在 `analysis` 数组中添加 `transition_order`、`transition_available` 字段
|
||||||
|
- 得分计算循环中根据阶数选择 `_calcTransitionScore` 或 `_calcTransitionScore2ndOrder`
|
||||||
|
|
||||||
|
## Deviations from Plan
|
||||||
|
|
||||||
|
None - plan executed exactly as written.
|
||||||
|
|
||||||
|
## Verification Results
|
||||||
|
|
||||||
|
所有验收标准通过:
|
||||||
|
- `_getTransitionMatrix2ndOrder` 方法存在,包含 `$minStatePairCount` 参数
|
||||||
|
- `sufficient_pairs`、`total_pairs` 在返回结构中存在
|
||||||
|
- `_calcTransitionScore2ndOrder` 方法存在,包含 prev1/prev2 参数
|
||||||
|
- `minPeriodsThreshold = 200`、`minStatePairCount = 5`、`sufficientRatio >= 0.3`
|
||||||
|
- `transition_order`、`transition_available` 在 analysis 数组中存在
|
||||||
|
|
||||||
|
## Key Decisions
|
||||||
|
|
||||||
|
1. **数据量阈值提升到200期** - 原计划可能考虑100期,但二阶状态空间更大(N^2),需要更多数据才能稳定估计
|
||||||
|
2. **以tail为基准判断** - tail类型状态空间最大(100),是最苛刻的指标,确保整体二阶概率估计稳定
|
||||||
|
3. **状态对观察次数阈值5次** - 经验值,平衡数据需求与概率估计可靠性
|
||||||
|
|
||||||
|
## Self-Check
|
||||||
|
|
||||||
|
### Files Created/Modified
|
||||||
|
|
||||||
|
- application/admin/model/History.php: MODIFIED (新增2个方法,修改1个方法)
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- aab18df: feat(11-05): 实现二阶马尔可夫转移概率增强
|
||||||
|
|
||||||
|
## Self-Check: PASSED
|
||||||
Reference in New Issue
Block a user