Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -245,8 +245,6 @@ def simulate_jitter(seed: int,
|
|
| 245 |
jitter_rft_next = jitter + u_rft * 0.35
|
| 246 |
duty_rft += int(abs(u_rft) > 0.01)
|
| 247 |
|
| 248 |
-
# Apply combined evolution (keep it fair by updating the same jitter state)
|
| 249 |
-
# We store both "what baseline would do" and "what RFT would do"
|
| 250 |
act_baseline = u_base
|
| 251 |
act_rft = u_rft
|
| 252 |
|
|
@@ -364,10 +362,6 @@ def simulate_landing(seed: int,
|
|
| 364 |
conf = rft_confidence(uncertainty)
|
| 365 |
|
| 366 |
# anomaly definition (reduced spam): only count if materially bad
|
| 367 |
-
# pitch/yaw/roll are not modelled here; we count "control-relevant" anomalies:
|
| 368 |
-
# - high wind
|
| 369 |
-
# - high lateral error near ground
|
| 370 |
-
# - high descent rate near ground
|
| 371 |
anomaly_types = []
|
| 372 |
if wind > (0.85 * wind_max):
|
| 373 |
anomaly_types.append("High wind")
|
|
@@ -380,7 +374,7 @@ def simulate_landing(seed: int,
|
|
| 380 |
if is_anomaly:
|
| 381 |
anomalies += 1
|
| 382 |
|
| 383 |
-
# Baseline control: continuous proportional
|
| 384 |
u_base_x = -kp_baseline * meas_x - 0.25 * meas_xv
|
| 385 |
u_base_v = -kp_baseline * (meas_vv + 5.0) # target ~ -5 m/s
|
| 386 |
|
|
@@ -399,12 +393,10 @@ def simulate_landing(seed: int,
|
|
| 399 |
actions += 1
|
| 400 |
|
| 401 |
# apply dynamics
|
| 402 |
-
# vertical: vv integrates thrust + gravity (simplified)
|
| 403 |
g = -9.81
|
| 404 |
vv = vv + (g + 0.18 * u_rft_v + 0.08 * thrust_dev) * dt
|
| 405 |
alt = max(0.0, alt + vv * dt)
|
| 406 |
|
| 407 |
-
# lateral: wind pushes, control counters
|
| 408 |
xv = xv + (0.35 * wind - 0.30 * u_rft_x) * dt
|
| 409 |
x = x + xv * dt
|
| 410 |
|
|
@@ -516,7 +508,6 @@ def run_benchmarks(seed: int,
|
|
| 516 |
tau_gain=tau_gain,
|
| 517 |
show_debug=False
|
| 518 |
)
|
| 519 |
-
# Baseline alerts equals df baseline count; derive from CSV
|
| 520 |
neo_df = pd.read_csv(neo_csv)
|
| 521 |
neo_base = int(neo_df["baseline_alert"].sum())
|
| 522 |
neo_rft = int(neo_df["rft_alert"].sum())
|
|
@@ -541,14 +532,13 @@ def run_benchmarks(seed: int,
|
|
| 541 |
dt=land_dt,
|
| 542 |
wind_max=land_wind,
|
| 543 |
thrust_noise=land_thrust_noise,
|
| 544 |
-
kp_baseline=0.06,
|
| 545 |
-
kp_rft=0.10,
|
| 546 |
gate_threshold=0.55,
|
| 547 |
tau_gain=tau_gain,
|
| 548 |
goal_m=10.0
|
| 549 |
)
|
| 550 |
|
| 551 |
-
# Scorecard table
|
| 552 |
score = pd.DataFrame([
|
| 553 |
{
|
| 554 |
"Module": "NEO",
|
|
@@ -578,7 +568,6 @@ def run_benchmarks(seed: int,
|
|
| 578 |
|
| 579 |
score_path = df_to_csv_file(score, f"bench_score_seed{seed}.csv")
|
| 580 |
|
| 581 |
-
# Summary text
|
| 582 |
txt = (
|
| 583 |
f"Benchmarks (seed={seed})\n"
|
| 584 |
f"- NEO: baseline alerts={neo_base}, RFT candidates={neo_candidates}, RFT filtered={neo_rft}\n"
|
|
@@ -586,7 +575,7 @@ def run_benchmarks(seed: int,
|
|
| 586 |
f"- Landing: final offset={l_sum['final_landing_offset_m']:.2f} m (goal 10 m), anomalies={l_sum['total_anomalies_detected']}, actions={l_sum['total_control_actions']}\n"
|
| 587 |
)
|
| 588 |
|
| 589 |
-
all_imgs = neo_imgs + jit_imgs + land_imgs
|
| 590 |
return txt, score, score_path, all_imgs, [neo_csv, jit_csv, land_csv]
|
| 591 |
|
| 592 |
# -----------------------------
|
|
@@ -781,7 +770,10 @@ def ui_run_landing(seed, steps, dt, wind_max, thrust_noise, kp_base, kp_rft, gat
|
|
| 781 |
summary_txt = json.dumps(summary, indent=2)
|
| 782 |
return summary_txt, imgs[0], imgs[1], imgs[2], imgs[3], csv_path
|
| 783 |
|
| 784 |
-
def ui_run_bench(seed, neo_steps, neo_dt, neo_alert_km, neo_noise_km,
|
|
|
|
|
|
|
|
|
|
| 785 |
txt, score_df, score_csv, imgs, logs = run_benchmarks(
|
| 786 |
seed=int(seed),
|
| 787 |
neo_steps=int(neo_steps), neo_dt=float(neo_dt), neo_alert_km=float(neo_alert_km), neo_noise_km=float(neo_noise_km),
|
|
@@ -789,7 +781,23 @@ def ui_run_bench(seed, neo_steps, neo_dt, neo_alert_km, neo_noise_km, jit_steps,
|
|
| 789 |
land_steps=int(land_steps), land_dt=float(land_dt), land_wind=float(land_wind), land_thrust_noise=float(land_thrust_noise),
|
| 790 |
tau_gain=float(tau_gain)
|
| 791 |
)
|
| 792 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 793 |
|
| 794 |
with gr.Blocks(title="RFT — Agent Console (NEO / Jitter / Landing)") as demo:
|
| 795 |
gr.Markdown(HOME_MD)
|
|
@@ -944,7 +952,7 @@ with gr.Blocks(title="RFT — Agent Console (NEO / Jitter / Landing)") as demo:
|
|
| 944 |
|
| 945 |
# ----------------------------------------------------------
|
| 946 |
with gr.Tab("Benchmarks"):
|
| 947 |
-
gr.Markdown("# Benchmarks\
|
| 948 |
|
| 949 |
# ----------------------------------------------------------
|
| 950 |
with gr.Tab("Theory → Practice"):
|
|
|
|
| 245 |
jitter_rft_next = jitter + u_rft * 0.35
|
| 246 |
duty_rft += int(abs(u_rft) > 0.01)
|
| 247 |
|
|
|
|
|
|
|
| 248 |
act_baseline = u_base
|
| 249 |
act_rft = u_rft
|
| 250 |
|
|
|
|
| 362 |
conf = rft_confidence(uncertainty)
|
| 363 |
|
| 364 |
# anomaly definition (reduced spam): only count if materially bad
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
anomaly_types = []
|
| 366 |
if wind > (0.85 * wind_max):
|
| 367 |
anomaly_types.append("High wind")
|
|
|
|
| 374 |
if is_anomaly:
|
| 375 |
anomalies += 1
|
| 376 |
|
| 377 |
+
# Baseline control: continuous proportional (computed for reference / logging)
|
| 378 |
u_base_x = -kp_baseline * meas_x - 0.25 * meas_xv
|
| 379 |
u_base_v = -kp_baseline * (meas_vv + 5.0) # target ~ -5 m/s
|
| 380 |
|
|
|
|
| 393 |
actions += 1
|
| 394 |
|
| 395 |
# apply dynamics
|
|
|
|
| 396 |
g = -9.81
|
| 397 |
vv = vv + (g + 0.18 * u_rft_v + 0.08 * thrust_dev) * dt
|
| 398 |
alt = max(0.0, alt + vv * dt)
|
| 399 |
|
|
|
|
| 400 |
xv = xv + (0.35 * wind - 0.30 * u_rft_x) * dt
|
| 401 |
x = x + xv * dt
|
| 402 |
|
|
|
|
| 508 |
tau_gain=tau_gain,
|
| 509 |
show_debug=False
|
| 510 |
)
|
|
|
|
| 511 |
neo_df = pd.read_csv(neo_csv)
|
| 512 |
neo_base = int(neo_df["baseline_alert"].sum())
|
| 513 |
neo_rft = int(neo_df["rft_alert"].sum())
|
|
|
|
| 532 |
dt=land_dt,
|
| 533 |
wind_max=land_wind,
|
| 534 |
thrust_noise=land_thrust_noise,
|
| 535 |
+
kp_baseline=0.06,
|
| 536 |
+
kp_rft=0.10,
|
| 537 |
gate_threshold=0.55,
|
| 538 |
tau_gain=tau_gain,
|
| 539 |
goal_m=10.0
|
| 540 |
)
|
| 541 |
|
|
|
|
| 542 |
score = pd.DataFrame([
|
| 543 |
{
|
| 544 |
"Module": "NEO",
|
|
|
|
| 568 |
|
| 569 |
score_path = df_to_csv_file(score, f"bench_score_seed{seed}.csv")
|
| 570 |
|
|
|
|
| 571 |
txt = (
|
| 572 |
f"Benchmarks (seed={seed})\n"
|
| 573 |
f"- NEO: baseline alerts={neo_base}, RFT candidates={neo_candidates}, RFT filtered={neo_rft}\n"
|
|
|
|
| 575 |
f"- Landing: final offset={l_sum['final_landing_offset_m']:.2f} m (goal 10 m), anomalies={l_sum['total_anomalies_detected']}, actions={l_sum['total_control_actions']}\n"
|
| 576 |
)
|
| 577 |
|
| 578 |
+
all_imgs = neo_imgs + jit_imgs + land_imgs # 3 + 3 + 4 = 10 images
|
| 579 |
return txt, score, score_path, all_imgs, [neo_csv, jit_csv, land_csv]
|
| 580 |
|
| 581 |
# -----------------------------
|
|
|
|
| 770 |
summary_txt = json.dumps(summary, indent=2)
|
| 771 |
return summary_txt, imgs[0], imgs[1], imgs[2], imgs[3], csv_path
|
| 772 |
|
| 773 |
+
def ui_run_bench(seed, neo_steps, neo_dt, neo_alert_km, neo_noise_km,
|
| 774 |
+
jit_steps, jit_dt, jit_noise,
|
| 775 |
+
land_steps, land_dt, land_wind, land_thrust_noise,
|
| 776 |
+
tau_gain):
|
| 777 |
txt, score_df, score_csv, imgs, logs = run_benchmarks(
|
| 778 |
seed=int(seed),
|
| 779 |
neo_steps=int(neo_steps), neo_dt=float(neo_dt), neo_alert_km=float(neo_alert_km), neo_noise_km=float(neo_noise_km),
|
|
|
|
| 781 |
land_steps=int(land_steps), land_dt=float(land_dt), land_wind=float(land_wind), land_thrust_noise=float(land_thrust_noise),
|
| 782 |
tau_gain=float(tau_gain)
|
| 783 |
)
|
| 784 |
+
|
| 785 |
+
# IMPORTANT:
|
| 786 |
+
# The Live Console Benchmarks tab has 16 outputs:
|
| 787 |
+
# - 1 textbox, 1 dataframe, 1 file
|
| 788 |
+
# - 10 images
|
| 789 |
+
# - 3 log files
|
| 790 |
+
# run_benchmarks returns 10 images (3 NEO + 3 jitter + 4 landing)
|
| 791 |
+
# so we MUST return imgs[0]..imgs[9] here.
|
| 792 |
+
while len(imgs) < 10:
|
| 793 |
+
imgs.append(None)
|
| 794 |
+
|
| 795 |
+
return (
|
| 796 |
+
txt, score_df, score_csv,
|
| 797 |
+
imgs[0], imgs[1], imgs[2], imgs[3], imgs[4],
|
| 798 |
+
imgs[5], imgs[6], imgs[7], imgs[8], imgs[9],
|
| 799 |
+
logs[0], logs[1], logs[2]
|
| 800 |
+
)
|
| 801 |
|
| 802 |
with gr.Blocks(title="RFT — Agent Console (NEO / Jitter / Landing)") as demo:
|
| 803 |
gr.Markdown(HOME_MD)
|
|
|
|
| 952 |
|
| 953 |
# ----------------------------------------------------------
|
| 954 |
with gr.Tab("Benchmarks"):
|
| 955 |
+
gr.Markdown("# Benchmarks\nBaseline vs RFT runs, same seed, exported logs.\nUse Live Console to run full benchmark packs.\n")
|
| 956 |
|
| 957 |
# ----------------------------------------------------------
|
| 958 |
with gr.Tab("Theory → Practice"):
|