Skip to content

Latest commit

 

History

History
280 lines (212 loc) · 8.11 KB

File metadata and controls

280 lines (212 loc) · 8.11 KB

治理與外部驗證升級完成報告

完成日期: 2026-01-26


一、已補齊的治理與驗證缺失

1. 需求可追溯矩陣(RTM)✅

補齊內容:

  • RTM 框架RequirementsTraceabilityMatrix
  • 需求定義:REQ-### 格式,分類(功能/性能/安全/適用域/輸出格式)
  • 驗證案例連結:需求 → 測試案例 → 證據
  • 覆蓋率統計:自動計算需求覆蓋率
  • RTM 報告:自動生成 JSON 和 Markdown 報告

實現位置:

  • requirements_traceability.py: 全新模組

功能:

  • 需求 → 測試案例追溯
  • 驗證方式標註(analysis/test/inspection)
  • 通過門檻記錄
  • 產物連結(報告 JSON/圖/原始 log)

2. 外部 Validation 基準 ✅

補齊內容:

  • 外部基準庫:ISA 1976、標準阻力落體、再入加熱、風洞係數示例
  • 比對功能:最大相對誤差、RMSE、分段誤差(高度/Mach 分段)
  • 校準層CalibrationLayer 類,記錄校準參數、偏差、殘差分布、過擬合風險
  • 模型型式誤差ModelFormUncertaintyManager 類,處理模型不確定度

實現位置:

  • external_validation.py: 全新模組

外部基準:

  1. ISA 1976:US Standard Atmosphere 1976 標準表
  2. 標準阻力落體:Anderson "Introduction to Flight"
  3. 再入加熱:Sutton-Graves 關聯式基準
  4. 風洞係數示例:學術/教科書級數據

校準功能:

  • 校準參數版本管理
  • Train/validation 分割
  • 偏差與殘差分析
  • 過擬合風險檢測

模型不確定度:

  • 加性誤差:y = f(x) + ε_model
  • 乘性誤差:y = f(x) * (1 + ε_model)
  • 模型集成:envelope 方法

3. 事件系統進階測試 ✅

補齊內容:

  • Zeno/抖動事件偵測detect_zeno_events() 方法
  • 處理建議:hysteresis、deadband、cooldown、debounce
  • 事件回溯event_root_finding() 方法(內插/二分法)
  • 狀態重算可重現性check_reproducibility_after_root_finding() 方法

實現位置:

  • event_system.py: EventDetector 類擴充

功能:

  • 偵測短時間內反覆觸發的事件
  • 事件時間精確定位(二分法)
  • 驗證狀態重算可重現性(同 seed 同結果)

4. 回歸測試分層閘門 ✅

補齊內容:

  • 三層閘門
    • HARD_INVARIANT:必須不變(單位、座標轉換、ISA 表格)
    • SOFT_KPI:允許小變動(max-q、熱峰值、燃料裕度)
    • MODEL_UPDATE_EXPECTED:預期變動(需說明與簽核)
  • 分層報告:按閘門類型統計通過/失敗

實現位置:

  • reproducibility.py: RegressionTest 類擴充

5. 可重現性包擴充 ✅

補齊內容:

  • Artifact Manifest:所有檔案的 SHA256 hash
  • Determinism Checklist:NumPy/BLAS/OMP thread、random seed chain、排序穩定性
  • 環境凍結建議:Docker/Conda lockfile 說明

實現位置:

  • reproducibility.py: ReproducibilityPack 類擴充

新增文件:

  • artifact_manifest.json:檔案 SHA256 清單
  • determinism_checklist.json:確定性檢查清單

6. 文件去敏工具 ✅

補齊內容:

  • 關鍵詞替換:高風險關鍵詞自動替換(導彈→飛行器、比例導引→航跡控制等)
  • 用途聲明:自動添加用途聲明與適用域
  • 免責聲明:自動添加免責聲明

實現位置:

  • documentation_sanitizer.py: 全新模組

替換映射:

  • "導彈" → "飛行器"
  • "比例導引" → "航跡控制"
  • "攔截" → "交會"
  • "武器" → "載具"

二、升級對照表

缺失項目 狀態 實現位置
RTM(需求可追溯矩陣) requirements_traceability.py
外部 Validation 基準 external_validation.py
校準層 external_validation.py
模型型式誤差 external_validation.py
事件系統 Zeno/抖動 event_system.py
事件回溯與可重現性 event_system.py
回歸測試分層閘門 reproducibility.py
Artifact Manifest reproducibility.py
Determinism Checklist reproducibility.py
文件去敏 documentation_sanitizer.py

三、使用範例

RTM 使用

from requirements_traceability import rtm, Requirement, RequirementType, VerificationCase, VerificationMethod

# 添加需求
req = Requirement(
    req_id="REQ-001",
    req_type=RequirementType.PERFORMANCE,
    description="最大動壓不超過 50 kPa",
    source="任務需求文檔"
)
rtm.add_requirement(req)

# 添加驗證案例
case = VerificationCase(
    case_id="VV-001",
    req_ids=["REQ-001"],
    verification_method=VerificationMethod.TEST,
    threshold=50000.0,
    artifacts=["V_V_Report_v1.0.json"]
)
rtm.add_verification_case(case)

# 生成 RTM 報告
rtm_report = rtm.generate_rtm_report("RTM_Report_v1.0.json")

外部 Validation

from external_validation import external_validation, calibration_layer, model_uncertainty_manager

# 與基準比對
isa_benchmark = external_validation.isa_standard_1976()
comparison = external_validation.compare_with_benchmark(
    isa_func, isa_benchmark, "T"
)
# 返回:max_relative_error, RMSE, segment_statistics

# 校準報告
calibration_report = calibration_layer.calibration_report(
    "C_D", train_data, validation_data, pred_train, pred_val
)
# 返回:bias, residuals, overfitting_risk

# 模型不確定度
uncertainty = ModelFormUncertainty(
    model_name="heating_model",
    uncertainty_type="additive",
    epsilon_model=0.1
)
model_uncertainty_manager.register_model_uncertainty(uncertainty)

回歸測試分層

from reproducibility import regression_test, RegressionGate

# 設置硬約束
regression_test.set_baseline("coordinate_transform_error", 0.0, "v1.0")
regression_test.set_tolerance(
    "coordinate_transform_error",
    absolute_tol=1e-9,
    gate_type=RegressionGate.HARD_INVARIANT
)

# 設置軟約束
regression_test.set_baseline("max_q", 50000.0, "v1.0")
regression_test.set_tolerance(
    "max_q",
    relative_tol=0.05,
    gate_type=RegressionGate.SOFT_KPI
)

# 設置預期變動
regression_test.set_baseline("C_D", 0.3, "v1.0")
regression_test.set_tolerance(
    "C_D",
    relative_tol=0.1,
    allow_change=True,
    gate_type=RegressionGate.MODEL_UPDATE_EXPECTED
)

文件去敏

from documentation_sanitizer import doc_sanitizer

# 清理文件
result = doc_sanitizer.sanitize_file("README.md", backup=True)

# 添加聲明
doc_sanitizer.add_disclaimer_to_readme("README.md")

四、下一步 Roadmap(務實版)

✅ 已完成

  1. RTM(需求-測試-證據)v1.0
  2. 外部 Validation baseline 套件(4 個公開 benchmark)
  3. 模型不確定度(model form)處理
  4. 回歸閘門分層
  5. Artifact manifest + determinism checklist
  6. 文件去敏工具

🔄 建議後續

  1. 擴充外部基準:更多公開 benchmark(NASA 數據、學術論文)
  2. Docker/Conda lockfile:實際生成環境鎖定文件
  3. RTM 自動化:從需求文檔自動生成 RTM
  4. 校準數據庫:建立校準參數數據庫
  5. 模型集成框架:完整實現 envelope 方法

五、總結

治理與外部驗證升級完成,程式碼現在具備:

  1. 需求可追溯矩陣(RTM):需求 → 測試 → 證據完整鏈條
  2. 外部 Validation 基準:4 個公開 benchmark + 誤差統計
  3. 校準層:參數校準、偏差分析、過擬合檢測
  4. 模型型式誤差:加性/乘性/集成方法
  5. 事件系統進階測試:Zeno/抖動、回溯、可重現性
  6. 回歸測試分層閘門:硬約束/軟約束/預期變動
  7. 可重現性包擴充:Artifact manifest、Determinism checklist
  8. 文件去敏:高風險關鍵詞替換、用途聲明

這是一個具備完整治理框架、外部驗證能力、可追溯性的工程級平台。


狀態: ✅ 治理與外部驗證升級完成