Commit 28214fe
committed
add inverse_reward_from_demo example
A new embodied-AI example that learns linear reward weights from a
single demonstration trajectory and reuses them to plan to a brand
new goal in the same world.
The demonstrator walks from a start cell to a goal cell along a path
that detours through two hidden "scenic" zones the engineer never
told the agent about. The agent extracts a per-cell feature vector
phi(s) = (scenic, wall_adjacent, interior), computes the demo path's
feature expectation mu_demo, the uniform-walkable-cell expectation
mu_uniform, and clips their difference to learn linear reward
weights `w = clip(mu_demo - mu_uniform)`.
It then plans to a *different* (start, goal) pair with shaped A*
whose edge cost is `1 - lambda * (w . phi(target_cell))`. On the
default grid the learned-reward path is the same length as the
Manhattan-baseline path (21 cells) but visits four scenic cells
versus one incidentally for the baseline. The agent never saw a
label saying scenic mattered - it inferred that preference from one
trajectory.
This is structurally different from 28_curiosity_grid_exploration.py
and 32_empowerment_navigation.py, where the intrinsic signal is
hand-designed by the engineer. Here the agent has no built-in
preference for scenic zones; it learns the preference from the demo.
Exposes demo_path_length, learned_path_length, baseline_path_length,
demo_scenic_step_count, learned_scenic_step_count,
baseline_scenic_step_count, mu_demo, mu_uniform, learned_weights.
Structured failures: timeout (terminal), no_demo_path (recoverable -
the demo trajectory cannot be synthesized), no_learned_path
(terminal - shaped A* could not reach the new goal),
out_of_bounds/collision (recoverable, only on rejected actions).
Tests: smoke test pins seed=0 and asserts success, the demo touches
multiple scenic cells, the learned path's scenic step count strictly
exceeds the Manhattan-baseline path's, and the scenic-feature weight
is positive. A second test pins the IRL math: `mu_demo[scenic] >
mu_uniform[scenic]` and the resulting scenic weight is positive.
Counts: 36 examples / 35 GIFs / 88 tests / 8 embodied-AI examples.1 parent 04babb6 commit 28214fe
11 files changed
Lines changed: 685 additions & 17 deletions
File tree
- docs
- assets/gifs
- examples
- embodied_ai
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
Loading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
0 commit comments