Update app.py
Browse files
app.py
CHANGED
|
@@ -244,14 +244,26 @@ def simulate_summary(iteration: int, score: float, target: float) -> Dict[str, A
|
|
| 244 |
"考虑性能优化",
|
| 245 |
]
|
| 246 |
|
| 247 |
-
# 模拟
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
-
|
| 254 |
-
new_score = max(0.
|
| 255 |
|
| 256 |
if new_score >= score:
|
| 257 |
reflection = random.choice(reflections_positive)
|
|
@@ -410,12 +422,12 @@ def create_demo():
|
|
| 410 |
current_score = 0.0
|
| 411 |
|
| 412 |
empty_md = "*等待开始...*"
|
| 413 |
-
|
|
|
|
| 414 |
|
|
|
|
| 415 |
for i in range(1, int(max_iter) + 1):
|
| 416 |
-
|
| 417 |
-
yield status, pd.DataFrame(chart_data) if chart_data else pd.DataFrame(columns=["iteration", "score"]), empty_md, empty_md, empty_md, empty_md
|
| 418 |
-
|
| 419 |
results, current_score = run_pees_iteration(task, i, current_score, target)
|
| 420 |
|
| 421 |
# 分别获取四个阶段的结果
|
|
@@ -464,7 +476,8 @@ def create_demo():
|
|
| 464 |
# 更新图表数据
|
| 465 |
chart_data.append({"iteration": i, "score": current_score})
|
| 466 |
|
| 467 |
-
|
|
|
|
| 468 |
yield status, pd.DataFrame(chart_data), plan_md, exec1_md, exec2_md, summary_md
|
| 469 |
|
| 470 |
# 检查是否达到目标
|
|
|
|
| 244 |
"考虑性能优化",
|
| 245 |
]
|
| 246 |
|
| 247 |
+
# 改进分数模拟逻辑:
|
| 248 |
+
# 1. 起始阶段(iteration <= 2):强劲上升趋势
|
| 249 |
+
# 2. 中期阶段:波动上升
|
| 250 |
+
# 3. 后期阶段:阻尼振荡,接近目标
|
| 251 |
+
|
| 252 |
+
if iteration <= 2:
|
| 253 |
+
# 早期:强劲上升
|
| 254 |
+
base_gain = random.uniform(0.15, 0.25)
|
| 255 |
+
noise = random.uniform(-0.03, 0.05)
|
| 256 |
+
new_score = score + base_gain + noise
|
| 257 |
+
else:
|
| 258 |
+
# 中后期:阻尼振荡
|
| 259 |
+
damping = 0.12 * (0.85 ** (iteration - 2))
|
| 260 |
+
oscillation = damping * (1.0 if iteration % 2 == 0 else -0.6)
|
| 261 |
+
noise = random.uniform(-0.05, 0.05)
|
| 262 |
+
trend = (target - score) * 0.15
|
| 263 |
+
new_score = score + trend + oscillation + noise
|
| 264 |
|
| 265 |
+
# 限制范围
|
| 266 |
+
new_score = max(0.15, min(1.0, new_score))
|
| 267 |
|
| 268 |
if new_score >= score:
|
| 269 |
reflection = random.choice(reflections_positive)
|
|
|
|
| 422 |
current_score = 0.0
|
| 423 |
|
| 424 |
empty_md = "*等待开始...*"
|
| 425 |
+
# 初始状态:显示"准备中"
|
| 426 |
+
yield "状态: 准备执行任务...", pd.DataFrame(columns=["iteration", "score"]), empty_md, empty_md, empty_md, empty_md
|
| 427 |
|
| 428 |
+
# 先执行完整的一次 PEES 迭代,然后一起更新
|
| 429 |
for i in range(1, int(max_iter) + 1):
|
| 430 |
+
# 执行完整迭代
|
|
|
|
|
|
|
| 431 |
results, current_score = run_pees_iteration(task, i, current_score, target)
|
| 432 |
|
| 433 |
# 分别获取四个阶段的结果
|
|
|
|
| 476 |
# 更新图表数据
|
| 477 |
chart_data.append({"iteration": i, "score": current_score})
|
| 478 |
|
| 479 |
+
# 每次迭代完成后才更新 UI
|
| 480 |
+
status = f"状态: 第 {i}/{int(max_iter)} 次迭代完成 (分数: {current_score:.2f})"
|
| 481 |
yield status, pd.DataFrame(chart_data), plan_md, exec1_md, exec2_md, summary_md
|
| 482 |
|
| 483 |
# 检查是否达到目标
|