image.domain\self_evolve\predict.mbt

82.1% · 23 / 28 points · 153 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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