Intent-Aware Data Collection

HighwayEnv setup and rule-based dataset workflow · 2026-11-19

Environment and vehicles

CustomEnv is defined in src/cooperative_driving/environments/customEnv.py.

RoadFour highway lanes
EgoOne controlled vehicle
TrafficTen background vehicles
TypesFive aggressive and five defensive
SpeedEgo target speed: 27 m/s
Visibility60 m intent-aware radius

By default the ego starts in any lane from 0 through 3, chosen per episode. Background traffic types are shuffled at reset, and lead-vehicle offsets are randomly assigned to lanes.

Every vehicle receives a stable ID:

vehicle.vehicle_id = self.next_vehicle_id
self.next_vehicle_id += 1
self.vehicles_by_id[vehicle_id] = vehicle
self.vehicle_types[vehicle_id] = vehicle_type

Visible neighbors

scripts/data_collection/show_visible_neighbors.py considers the ego lane and its immediate left and right lanes. It keeps the closest vehicle in each slot within 60 m.

LaneFrontBesideRear
Left111
Ego lane1—1
Right111

The theoretical maximum is eight visible vehicles, although the actual number can be zero through eight. A vehicle is classified as beside the ego within a 10 m longitudinal side window.

.venv/bin/python -m scripts.data_collection.show_visible_neighbors

State and intent messages

get_vehicle_state(vehicle) returns the vehicle's current ID, behavior type, position, velocity, speed, heading, current lane, target lane, target speed, acceleration, steering, and crash status.

preview_next_action(vehicle_id) deep-copies the road and calculates the neighbor's next controller action without changing the real environment.

{
  "vehicle_id": ...,      // stable ID
  "behavior_type": ...,   // aggressive, defensive, or idm
  "crashed": ...,         // crash status
  "target_lane": ...,     // predicted target lane
  "target_speed": ...,    // desired speed
  "acceleration": ...,    // predicted acceleration
  "steering": ...,        // predicted steering
}

The current state describes what the vehicle is doing now. The preview describes what its controller would do next.

.venv/bin/python -m scripts.data_collection.smoke_test_messages
.venv/bin/python -m scripts.data_collection.compare_neighbor_state_action

Rule-based informed ego action

scripts/policy/intent_aware_policy.py combines geometry with requested messages. It checks distance, closing speed, time to collision, beside vehicles, lane-entry intentions, braking front vehicles, and accelerating aggressive rear vehicles.

It supports all five discrete actions:

LANE_LEFT, IDLE, LANE_RIGHT, FASTER, SLOWER
  1. When a front vehicle enters the caution range, choose a safe adjacent lane.
  2. If neither adjacent lane is safe, choose SLOWER.
  3. If the lane is clear and the ego is below target speed, choose FASTER.
  4. Otherwise choose IDLE.
.venv/bin/python -m scripts.policy.intent_aware_policy --steps 10

Request-subset scenarios

scripts/data_collection/enumerate_message_requests.py evaluates every non-empty subset of visible vehicles. For n visible vehicles, there are 2^n - 1 scenarios. Use --include-none to add the no-request case.

1 visible1 scenario
2 visible3 scenarios
8 visible255 scenarios
With none256 scenarios at the maximum

Each subset uses only the messages requested in that subset. Unrequested vehicles contribute observable geometry but not private intent. Each scenario is evaluated on a deep-copied environment.

Dataset collection flow

1. ResetRandomize lanes, types, and traffic offsets.
→
2. ObserveFind neighbors within 60 m.
→
3. RequestEnumerate message subsets.
→
4. PreviewCalculate requested neighbor intent.
→
5. DecideChoose an ego action.
→
6. RecordSave the transition.
Transition format
state + requested messages + ego action → next state + reward + terminated/truncated

The real rollout advances separately using the action chosen with all currently visible messages. The dataset records counterfactual one-step outcomes for every request subset.

.venv/bin/python -m scripts.data_collection.collect_intent_aware_dataset \
    --episodes 1000 \
    --include-none \
    --experiment 3

Corrected records use message_slot_encoding: spatial_v1. The eight visible_vehicle_slots preserve empty positions with null, so messages use the same spatial indices in training and planning. The adapter rejects ambiguous legacy packed informed records. No-message records encode as all zeros.

Crash metrics

  • Counterfactual scenario crash rate: crashes among request/action combinations evaluated on copied environments.
  • Actual rollout crash rate: crashes from the real rollout using all currently visible messages. This is the metric for judging policy safety.

Each request subset is a separate counterfactual transition, so record counts and truncations can exceed the number of real episode endings. See the dataset dashboard for per-experiment totals and rollout statistics.

Uninformed random-action baseline

scripts/data_collection/collect_random_no_message_dataset.py collects a separate baseline in which the ego requests no vehicles and chooses a random action. It records the same transition fields, including messages=None, and preserves crash transitions instead of stopping data collection globally.

.venv/bin/python -m scripts.data_collection.collect_random_no_message_dataset \
    --episodes 1000 \
    --experiment 3

This dataset gives the World Model uninformed examples of both safe and unsafe actions, including the outcomes that lead to crashes.

Combining datasets

The two JSONL datasets can be merged while preserving provenance. Each merged record contains dataset_source, source_episode, global_episode, and a unique record_id.

.venv/bin/python -m scripts.data_collection.merge_world_model_datasets \
    --experiment 3 \
    --random data/experiment_2/random_no_message_dataset.jsonl

Experiment 3 reused the Experiment 2 no-message baseline, which remains compatible with the corrected encoding. To use a newly collected Experiment 3 random baseline instead, omit --random. Choose one route; rerunning collectors overwrites their default files.

Per-experiment counts, action/message distributions, and source provenance live on the dataset dashboard. Follow the training run guide for subsequent steps.