image.domain\self_evolve\predict.mbt
82.1% · 23 / 28 points · 153 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 预测 self_evolve/predict - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 演化预测模型 — 基于历史预测演化结果 - 7
// Evolution prediction model: predict evolution outcomes based on history - 8
// - 9
// Phase 9 v304: 将演化从"评分"推向"预测" — 基于历史数据预测未来演化结果。 - 10
- 11
///| - 12
/// 预测类型。 - 13
/// 预测 Prediction kind. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum PredictionKind { - 18
DegradationLikely - 19
TestGrowthExpected - 20
StableOp - 21
HighRisk - 22
} - 23
- 24
///| - 25
pub extend PredictionKind with @debug.Debug::{to_repr} - 26
- 27
///| - 28
pub extend PredictionKind with Eq::{not_equal, equal} - 29
- 30
///| - 31
/// 单算子演化预测。 - 32
/// 描述 Evolution prediction for a single op. - 33
#derive(Eq, @debug.Debug) - 34
pub(all) struct EvolutionPrediction { - 35
op_tag : String - 36
kind : PredictionKind - 37
confidence : Int32 - 38
predicted_value : Int32 - 39
description : String - 40
} - 41
- 42
///| - 43
pub extend EvolutionPrediction with @debug.Debug::{to_repr} - 44
- 45
///| - 46
pub extend EvolutionPrediction with Eq::{not_equal, equal} - 47
- 48
///| - 49
/// 预测报告。 - 50
/// 预测 Prediction report. - 51
#derive(Eq, @debug.Debug) - 52
pub(all) struct PredictionReport { - 53
predictions : Array[EvolutionPrediction] - 54
total : Int32 - 55
high_risk_count : Int32 - 56
summary : String - 57
} - 58
- 59
///| - 60
pub extend PredictionReport with @debug.Debug::{to_repr} - 61
- 62
///| - 63
pub extend PredictionReport with Eq::{not_equal, equal} - 64
- 65
///| - 66
/// 预测单个算子的演化结果。 - 67
/// 预测 Predict evolution outcome for a single op. - 68
pub fn predict_op(op : @imgir.IROp) -> EvolutionPrediction { - 69●
let tag = op.tag() - 70●
let degs = detect_degradation(op) - 71●
let deg_count = degs.length() - 72●
let score = score_op(op) - 73●
let log = history_log() - 74
let mut avg_test_growth = 0 - 75
let entries = log.entries - 76●
let n = entries.length() - 77
if n >= 2 { - 78●
let total_growth = entries[n - 1].test_count - entries[0].test_count - 79
avg_test_growth = total_growth / (n - 1) - 80
} - 81
if deg_count > 0 && score.score >= 70 { - 82○
{ - 83
op_tag: tag, - 84
kind: HighRisk, - 85
confidence: 90, - 86
predicted_value: deg_count, - 87
description: tag + - 88
" 高风险: " + - 89○
deg_count.to_string() + - 90
" 个退化, 评分 " + - 91○
score.score.to_string(), - 92
} - 93●
} else if deg_count > 0 { - 94●
{ - 95
op_tag: tag, - 96
kind: DegradationLikely, - 97
confidence: 70, - 98
predicted_value: deg_count, - 99
description: tag + - 100
" 可能退化: " + - 101●
deg_count.to_string() + - 102
" 个退化", - 103
} - 104●
} else if avg_test_growth > 0 { - 105●
{ - 106
op_tag: tag, - 107
kind: TestGrowthExpected, - 108
confidence: 60, - 109
predicted_value: avg_test_growth, - 110
description: tag + - 111
" 预期测试增长 " + - 112●
avg_test_growth.to_string() + - 113
" 个", - 114
} - 115
} else { - 116○
{ - 117
op_tag: tag, - 118
kind: StableOp, - 119
confidence: 80, - 120
predicted_value: 0, - 121
description: tag + " 稳定: 无退化风险", - 122
} - 123
} - 124
} - 125
- 126
///| - 127
/// 预测所有算子的演化结果。 - 128
/// 预测 Predict evolution outcomes for all ops. - 129
pub fn predict_all() -> PredictionReport { - 130●
let predictions : Array[EvolutionPrediction] = [] - 131
let mut high_risk = 0 - 132●
for op in all_ops() { - 133●
let p = predict_op(op) - 134
if p.kind is HighRisk { - 135○
high_risk = high_risk + 1 - 136
} - 137●
predictions.push(p) - 138
} - 139●
let total = predictions.length() - 140
let summary = "演化预测: " + - 141●
total.to_string() + - 142
" 算子, " + - 143●
high_risk.to_string() + - 144
" 高风险" - 145
{ predictions, total, high_risk_count: high_risk, summary, } - 146
} - 147
- 148
///| - 149
/// 预测报告是否有高风险。 - 150
/// 描述 Whether prediction report has high-risk items. - 151
pub fn PredictionReport::has_high_risk(self : PredictionReport) -> Bool { - 152●
self.high_risk_count > 0 - 153
}