SandHouse
Pages and contents

Conditional Abstraction Agent

Problem
Most modern world models plan by simulating future trajectories and opting for the path with the maximum expected reward. This is computationally expensive, prone to compunding errors over long horizons, and is not aligned with the way humans plan to solve problems.

Instead of simulating future trajectories, humans reason over the conditions that make a goal true. For example, if I am given the goal to "clean the kitchen," I understand the conditions that make that statement true:
1. No dirty dishes in the sink
2. Countertops clean
3. Trash taken out
I can choose a condition to work on, say I have a preference for completing the hardest task first, which is to clean the sink. This condition becomes my immediate goal, and can itself be broken down into simpler conditions.
1. Need a cleaning tool, i.e. a sponge with soap
2. Need to scrub each dish with the cleaning tool
The first condition again becomes a goal, i.e. holding the sponge with soap. This hierarchy breaks down all they way to primitive actions, i.e. moving your arm towards the sponge and grabbing it. This backwards conditional planning has a history in machine learning and neuroscience literature.

The difficult but essential part of an agent that reasons over conditions is the ability to discover these conditional abstractions in an unsupervised setting. This can be thought in terms of Event Segmentation, where conditions are useful temporal segmentations. For human actors, "in all cases segmenting hierarchically was associated with better performance of the learned task."

Method
Environments
The environments I tackled first are three different MiniGrid environments of increasing difficulty.
Tier 1
The first environment is DoorKey-8x8. In this environment, the agent must pick up a key that matches the color of a door, unlock the door, then proceed to a goal square.
tier1

Tier 2
The second environment is BlockedUnlockPickup. In this environment, the agent must move a ball out of the way of the door, then pick up a key, unlock the door, and proceed to the goal square.
tier2

Tier 3
The third environment is ObstructedMaze-Full keys are hidden in boxes, balls block doors, locked doors connect nine rooms, and the target is the blue ball. The agent is the red triangle. It sees only the 7 × 7 window ahead of it (shaded), and walls and closed doors hide what lies behind them.
tier3.png

Given the simple nature of these grid environments, the problem of encoders can be reserved for more complex environments while the focus of the initial model is to build the "brain".
Model
Encoder
The encoder for this model is simplified by the nature of the grid environment. For each tile, the encoder maps the pixels to a vector Eθ(x)=z∈ℝ32 . Two convolutional layers and a linear layer give z∈ℝ32 .
Belief
The belief is a set of tokens [Dosovitskiy2021, Locatello2020]. Each token i has a what, an
appearance vector fi∈𝒵∪{∅} (empty if it has never been seen), and a where, w . This is represented either as an integer offset from the agent in the grid w=(x,y), or the hand token w=𝒽 (and object can be held by the agent). For each movement action a, the agent fits a transformation w→Maw+ba from random play, without being told that the view turns or shifts. It
counts, over stored steps with action a, how often the appearance at view position ω before the
step determines the appearance at position ω′ after it.
Goal Planning
The agent works backward from the goal through the conditions that make it true, for example "holding the key" before "door open". It does not roll out imagined action sequences.
```
Algorithm: Backward chaining over learned conditions

function Solve(c, s, d, C, P): // condition, situation, depth, chain above, protected
X <- achievers (a, u, j) of c in s whose needs avoid C U {c}
for each group of X with equal numbers of unmet needs, fewest first:
Pi <- empty
for each achiever (a, u, j) in the group, with needs N:
if every need in N holds in s:
s' <- predicted step of a in s
if c holds in s' and every p in P that holds in s holds in s':
add plan "do a" to Pi
else:
refuse a here and re-plan
else:
n <- NextNeed(unmet needs of N, s) // orders, then the intention, then cost
P' <- P U {met needs that n is not ordered before}
if n is a `face` need:
pi <- Walk(n, s, d, C U {c}, P') // walking step
else if d < 6:
pi <- Solve(n, s, d + 1, C U {c}, P')
add pi to Pi if it exists
if Pi is non-empty:
return plan in Pi whose first step is nearest, with c prepended to its chain
return no plan
```
Model Diagram
```mermaid
flowchart LR
subgraph perception["Perception and Belief"]
direction TB
obs["Observation o_t<br/>Image patches with positions,<br/>the carried patch"]
enc["Encoder E_θ<br/>Patch → z ∈ ℝ³²"]
place["Placement<br/>Moves as w → M_a w + b_a"]
belief["Belief s_t<br/>Tokens (z_i, w_i)<br/>and the carried token"]

obs --> enc
enc --> place
place --> belief
end

subgraph learning["Memory and Effect Learning"]
direction TB
events["Event memory<br/>Stored tries (a, z_F, z_H) → outcome"]
effect["Effect model<br/>Kernel vote over event memory,<br/>network prior,<br/>episode's own tries first"]
noplan["No plan<br/>Frontier, then the act<br/>whose outcome is least known"]

events --> effect
effect ~~~ noplan
end

subgraph reasoning["Goal-Directed Reasoning"]
direction TB
goal["Goal condition g"]
plan["Backward chaining<br/>over conditions (System 2)"]
intent["Intention<br/>Chosen chain, held between steps"]
walk["Walking<br/>Closeness propagated<br/>over placements"]
act["Action a_t"]

goal --> plan
plan --> intent
intent --> walk
walk --> act
end

belief --> effect
belief --> noplan
effect -->|effects| plan
plan -.->|no plan| noplan
noplan --> intent

obs -.->|own tries| events
act -.->|environment feedback| obs

classDef box fill:#ffffff,stroke:#333333,stroke-width:1.5px,color:#111111
classDef mem fill:#eeeeee,stroke:#333333,stroke-width:1.5px,color:#111111

class obs,enc,place,effect,noplan,goal,plan,walk,act box
class belief,events,intent mem

style perception fill:none,stroke:#bbbbbb,stroke-dasharray:4 4
style learning fill:none,stroke:#bbbbbb,stroke-dasharray:4 4
style reasoning fill:none,stroke:#bbbbbb,stroke-dasharray:4 4
```
Results
The final version won 200 of 200 DoorKey episodes, 100 of 100 BlockedUnlockPickup episodes and 30 of 30 ObstructedMaze-Full episodes. On 100 fresh ObstructedMaze seeds it never saw before, it won 100 of 100, averaging about 146 steps. Comparing this to random actions, random play succeed in 3.3% of tier 1 episodes, 0.45% of tier 2 and 5.9% of tier 3. The planner's own steps are close to the shortest route: about 24 steps on DoorKey and 30 on BlockedUnlockPickup.