feat: 完成 issue #80 [Ti-2] 跨工序寻优模型训练(纯标准库岭回归+多目标关联建模+R2评估+可解释权重+JSON序列化)
This commit is contained in:
@@ -9,6 +9,7 @@ import sys
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from problem import ConstraintKind, OptimizationProblem, load_problem # noqa: E402
|
||||
from solver import SolverConfig, solve # noqa: E402
|
||||
from cross_process import CrossProcessModel, CrossProcessModelConfig, CrossProcessSample # noqa: E402
|
||||
|
||||
CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
"config", "recipe_optim.template.yaml")
|
||||
@@ -56,12 +57,26 @@ def main() -> int:
|
||||
if sol.strategy != "grid":
|
||||
failures.append(f"求解策略非 grid: {sol.strategy}")
|
||||
|
||||
# 7) 跨工序关联模型(#80)端到端:合成线性数据训练 + R² 评估
|
||||
cfg = CrossProcessModelConfig(
|
||||
upstream_features=["up"], downstream_targets=["down"],
|
||||
alpha=0.0, min_samples=8)
|
||||
samples = [CrossProcessSample(upstream={"up": float(i)},
|
||||
downstream={"down": 2.0 * float(i) + 1.0})
|
||||
for i in range(12)]
|
||||
cm = CrossProcessModel(cfg).fit(samples)
|
||||
report = cm.evaluate(samples)
|
||||
if not cm.fitted:
|
||||
failures.append("跨工序模型未训练成功")
|
||||
if not (report.get("r2_down", 0.0) > 0.99):
|
||||
failures.append(f"跨工序模型 R² 过低: {report}")
|
||||
|
||||
if failures:
|
||||
print("❌ recipe-optim 自检失败:")
|
||||
for f in failures:
|
||||
print(" -", f)
|
||||
return 1
|
||||
print("✅ recipe-optim 自检通过(6 能力点)")
|
||||
print("✅ recipe-optim 自检通过(7 能力点)")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user