Repository navigation
coef_train: terrain-risk steering lever + opt-in w_risk exposure loss - #91
Merged
Merged
Conversation
Make the policy learn to spend less time in terrain-risk areas — the "act on the signal" half of the material nav-stats work (buckets landed in #90). Three pieces, all default-off so a plain call is byte-identical to the geometry-only trainer: - sdf_nav.coef_feats(material=): appends the WORST terrain risk between the vehicle and its carrot (the terrain twin of the mu-probe, MAX not MIN), differentiable through the trajectory. add_risk_feature(model) widens a trained net to see it, output-identical at init (the widen-basin trick, like widen_coef_mlp for grip); CoefMLP grows use_mu/use_risk flags to disambiguate a 6-in net's optional column. - train_bicycle(material=, w_risk=, lam_soft=, lam_hard=): the material reroute force (F_soft = -lam_soft*grad risk) steers around risk, and a w_risk*Sum(risk) term penalizes dwelling in it (reported as the 3rd last_loss_terms summand). Only the bicycle rollout can learn this; a risk net without material= is rejected. - material.city_material_grid(): a matched (MaterialGrid, MaterialIdRaster) pair so the differentiable risk force/feature/loss and the reported buckets see the SAME terrain. - CLI: --w-risk/--lam-soft/--lam-hard/--risk-lookahead + --grid. A risk .cvcnav is a torch research artifact (the C++ coef_feats has no risk column yet) — the CLI warns, and --score skips widened nets (the Swarm drive is base-5-feature). Smoke measurement (grid 64, 40 steps, lam_soft 0.4, 2 seeds): w_risk=8 cuts terrain-risk exposure ~24% (0.108->0.082) with reach unhurt (0.166->0.172) on both seeds — a Pareto improvement, and evidence the additive feature + fixed reroute already work (a learned lam head is an enhancement, not a prerequisite). Full 3-seed study documented as follow-up. tests/test_risk_lever.py pins the feature append + byte-identical default, MAX-ahead + differentiability, add_risk_feature identity/flags/stacking, the w_risk loss wiring, and the risk-needs-material guard. Updated two train_bicycle tests for the new error message and the 3-tuple last_loss_terms.
… test + temper the smoke claim Three review-driven improvements (no behavior change to the lever): - eval_risk_exposure(model): the direct bicycle-rollout harness behind the smoke table, so the numbers are one-command reproducible and a widened net has a real eval path (feeds the risk column automatically; Swarm/scorecard_eval stay base-5-feature). - test_risk_feature_is_max_ahead: was fwd>=here (a tautology since the probe set includes o); now a hand-built clear-underfoot / risky-ahead scene asserts fwd > here strictly, so a degenerate lookahead (reach=0 / o-only) fails it. Adds an eval_risk_exposure smoke test. - docs: temper 'reach not hurt / Pareto improvement' to 'exposure down, reach not measurably changed' (the +0.006 reach delta is within 2-seed noise) and point at eval_risk_exposure.
This was referenced Sep 23, 2026
transfix
added a commit
that referenced
this pull request
Sep 23, 2026
…#94) * sdf_nav: learned lam head — the deployable per-position reroute lever The reroute force F_soft = -lam_soft*grad(risk) is what actually steers around terrain risk; PR #91 drove it with a FIXED lam_soft dial. This adds a learned lam head so the policy outputs lam_soft per position (stronger near risk, weaker in the open) — the deployable lever, and the piece the critic flagged as the real answer to "reroute, not just slow down". - CoefMLP(use_lam=): a 4th OUTPUT lam_soft. The output stack stays one uniform softplus(net + log(expm1(out_bias))) — full_out_bias() appends lam_init — so the exporter and the C++ forward need NO per-output special case; only the drive reads output[3]. forward() still returns (a,b,g) (backward compatible); coeffs_and_lam() returns the 4th. add_lam_head(model) widens identity-preserving (a/b/g bit-unchanged, lam starts at lam_init), mirroring widen_coef_mlp/add_risk_feature. - train_bicycle + eval_risk_exposure + the Swarm drive use the LEARNED lam for a use_lam net instead of the fixed dial; a lam net needs material= (raises otherwise) and forces the torch drive. coef_export writes the 4-output .cvcnav; scorecard_eval attaches the grid so a lam net is scored as deployed. CLI: --learned-lam (--lam-soft = the init). Measured (grid 64, 40 steps, 2 seeds): learned lam trims terrain-risk exposure a further ~3% over the fixed dial (0.082 -> 0.079) at equal reach, consistent across seeds. A risk .cvcnav stays a torch artifact until the coordinated C++ coef_mlp/drive update (next). tests/test_lam_head.py: identity+flags, forward backward-compat, coeffs_and_lam guard, full_out_bias + 4-output export, learns-off-init, needs-material, and Swarm scoring. * review: reject lam_init<=0 (dead/NaN lam head) Adversarial review CONFIRMED (forward-compat + export dims clean): add_lam_head / CoefMLP(use_lam) with lam_init<=0 silently broke — log(expm1(0))=-inf freezes the lam output at 0 with a dead gradient (the 'learned' lever never trains), and lam_init<0 gives log(expm1(<0))=NaN that poisons the drive/loss/weights/.cvcnav. Reachable via the documented --learned-lam --lam-soft 0 (--lam-soft 0 is valid for FIXED mode but a dead learned init). Guard lam_init>0 in CoefMLP.__init__ (covers add_lam_head) + a clear CLI error in main. Tests: constructor/add_lam_head/CLI rejection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR2 of the terrain-risk training program (buckets landed in #90). Makes the policy act on the terrain-risk signal — learn to spend less time in risk areas — instead of just measuring it. Everything defaults off, so a plain
coef_traincall is byte-identical to the geometry-only trainer.The lever (three pieces)
coef_feats(material=…)appends the WORST terrain risk between the vehicle and its carrot (the terrain twin of the grip μ-probe; MAX not MIN), differentiable through the trajectory.add_risk_feature(model)widens a trained net to see it, output-identical at init (the widen-basin trick, likewiden_coef_mlpfor grip).CoefMLPgrowsuse_mu/use_riskflags so a 6-in net's optional column is unambiguous.train_bicycle(material=, w_risk=, lam_soft=, lam_hard=): the material forceF_soft = -lam_soft·∇risksteers around risk, andw_risk·Σ risk(pose)penalizes dwelling in it (the 3rdlast_loss_termssummand). Only the bicycle rollout can learn this; a risk net withoutmaterial=is rejected.material.city_material_grid()returns a(MaterialGrid, MaterialIdRaster)pair so the differentiable risk force/feature/loss and the reported buckets see the SAME terrain.--w-risk/--lam-soft/--lam-hard/--risk-lookahead(+--grid). A risk.cvcnavis a torch research artifact (the C++coef_featshas no risk column yet) — the CLI warns, and--scoreskips widened nets (the Swarm drive is base-5-feature).Measurement (evidence it works)
Smoke study (grid 64, 40 steps,
lam_soft=0.4, 2 seeds — indicative):w_risk=0w_risk=8Both seeds show the drop; reach is unhurt — a Pareto improvement, and evidence the additive feature + fixed reroute already work (the critic predicted α/β/γ alone can only "slow down"; the fixed
F_softsupplies the reroute). A learnedlamhead (PR2b) is a planned enhancement, not a prerequisite; a full 3-seed/longer-horizon study on a stable/GPU box is the validation of record (BPTT is CPU-fragile).Tests
tests/test_risk_lever.py: feature append + byte-identical default, MAX-ahead + differentiability,add_risk_featureidentity/flags/stacking (→7 with grip), thew_riskloss wiring, and the risk-needs-material guard. Twotrain_bicycletests updated for the new error message and 3-tuplelast_loss_terms. 90 tests green locally across the material/coef/nav/vehicle suites.Next: PR3 scorecard-driven curriculum; a cross-repo PR wires the native
sim_worldmaterial_id + a learned-lamdeployable head + C++/Python parity gate (which also makes the Swarm drive risk-aware so--scorecovers risk models).