The most important correction to make about this experiment is in the title: the car does not update its network while it drives. There is no backpropagation, reward gradient, or online reinforcement step. The browser creates a population of networks, mutates their weights and biases, and scores what happens when the cars meet the same traffic.
That is still a useful machine-learning toy. It becomes more useful when the mechanism is named precisely.
The complete demo puts road physics, sensors, network activations, a population, traffic, persistence, and fitness controls on one screen. That is useful after the pieces have names. Here they arrive one boundary at a time: geometry becomes a number, numbers become switches, switches become a drive, and a score decides what survives.
Sensing is geometry
The default car casts five rays across a ninety-degree spread. Every ray is tested against road-border segments and every polygon edge in traffic. When several intersections exist, the closest offset wins.
A missing hit becomes 0. A detected obstacle becomes 1 - offset, so a nearer obstacle produces a stronger input. This small normalization layer turns drawing geometry into numbers the network can consume.
A ray becomes a number
INTERACTIVE- A ray becomes a number +
Drag traffic through the sensor fan. Only the nearest hit counts, and moving it closer should increase the proximity value.
Accessible experiment transcript
One ray tests road and traffic segments; only the nearest valid intersection becomes its normalized proximity input. Canvas gesture: drag traffic through the sensor fan.
The sensor is not “vision.” It is a designed interface to the environment. Changing its count, reach, or angle changes what the network can distinguish before learning enters the discussion. Garage edits are staged until the next run: rays keep stable IDs, so existing inputs retain their learned weights while a new ray starts with one new row of random weights.
The geometry now produces useful measurements, but the car still behaves exactly as before. Five numbers do not choose left, right, forward, or reverse. The next missing piece is a policy that can turn perception into an action.
The driving policy is a closed sensory loop
FOLLOW THE ARROWSEach sensor ray finds its closest road-border or traffic intersection.
Accessible diagram transcript
Five sensor rays become proximity inputs, pass through a threshold network, drive four controls, and update the next sensory frame.
The network is intentionally small
The default Car creates a 5 → 6 → 4 network, but the input layer now follows the sensor array. Each level computes a weighted sum and compares it with a bias. The result is binary.
A number becomes a switch
INTERACTIVE- A ray becomes a number ✓
- A number becomes a switch +
Drag the input handle across the red threshold mark. The output should switch exactly once at the boundary.
Accessible experiment transcript
A weighted sensor input and bias cross a hard threshold, turning a continuous measurement into a binary driving decision. Canvas gesture: drag the input handle across the threshold.
Turn several sensor readings into one yes-or-no control decision.
- 01 Read every sensorEach x is one input, such as the distance reported by a ray.
- 02 Weight the evidenceEach w decides how strongly that sensor should influence this output node.
- 03 Add a biasThe bias shifts how much combined evidence the node needs before it activates.
- 04 Cross the thresholdH converts the total into an on or off output: steer, accelerate, or reverse.
Those four outputs map directly to forward, left, right, and reverse controls. Vehicle code then applies an adjustable acceleration factor, coasting drag, explicit reverse braking, a hard speed limit, steering direction, polygon collision, and damage state. Releasing forward preserves momentum; reverse is the deliberate brake before it becomes reverse thrust. The network chooses switches; ordinary simulation logic determines what those switches do.
This division is worth preserving. The policy should not need to rediscover basic vehicle physics or collision geometry from pixels.
The car can now sense and act, which makes the next problem impossible to ignore: a randomly initialized policy is terrible. It may steer into a border, hold forward forever, or freeze behind traffic. One policy is a demonstration, not a search.
One policy becomes a population
Copy the same small network many times and perturb its weights and biases. Give every candidate the same traffic seed so differences in the result come from policy, not from one car receiving an easier road.
Variation creates candidates
INTERACTIVE- A ray becomes a number ✓
- A number becomes a switch ✓
- Variation creates candidates +
Drag the mutation handle while the cars run. Their traffic stays fixed while their policy paths spread farther apart.
Accessible experiment transcript
A parent threshold policy branches into nearby mutations; every candidate sees the same traffic so behavior can be compared. Canvas gesture: drag to widen or tighten mutation.
Variation gives the experiment options. It does not tell us which option is better. A population without an objective is only a collection of differently bad drivers.
Selection happens between generations
The application generates a population of cars. The best brain is checkpointed automatically in local storage after every completed run; the next population starts from that saved champion, and all but the first car receive a mutation. Every generation receives a fresh randomized traffic seed, while every candidate inside that generation sees the same layout. That keeps comparisons fair without teaching the population one permanent obstacle pattern.
The old version treated furthest-forward position as the whole objective. That rewarded survival, but it also let a cautious car settle behind traffic. The current score combines forward progress, average pace, overtakes, close-following time, idle time, and collision state—and the Fitness ledger makes each value editable. A Smart run extends only when the champion sustains pace, changes lanes, passes traffic, and avoids tailing or collision; moving straight ahead is not enough. Strong saved fitness also unlocks curved roads, then traffic that changes lanes.
The reward ledger changes the winner
INTERACTIVE- A ray becomes a number ✓
- A number becomes a switch ✓
- Variation creates candidates ✓
- A score chooses what survives +
Drag the reward target across the field. The same three drives should reorder as passing reward and collision cost change.
Accessible experiment transcript
The same three candidate drives receive different rankings when passing reward and collision penalty change. Canvas gesture: drag the reward target; watch the ranking.
Score a complete drive by rewarding useful progress and charging for failure modes.
- 01 Reward forward progressDistance advanced is the largest proof that the car is solving the road.
- 02 Reward useful paceAverage speed distinguishes confident motion from barely creeping forward.
- 03 Reward overtakesPassing traffic gives the policy a reason not to trail a safe car forever.
- 04 Subtract failuresCollisions and idle time reduce the score. Each weight controls how expensive that behavior is.
Now the loop can preserve a candidate and mutate around it. That closes the first evolutionary cycle—and opens a more interesting gap. The score can be internally consistent while rewarding the wrong behavior. A car that safely trails traffic may beat a risky overtaker; a large passing bonus may produce reckless weaving.
Search is scored population mutation
FOLLOW THE ARROWSThe best-scoring network becomes the seed; manual save can persist it between visits.
Accessible diagram transcript
An elite network seeds a population, mutations create variants, identical traffic tests each policy, and composite fitness selects the next elite.
Preserve several kinds of success
One champion is simple, but it narrows the search. A fast overtaker, a cautious lane changer, and a car that recovers well from dense traffic may encode useful but incompatible behaviors. Replacing all three with the single highest score makes the next generation vulnerable to one lucky traffic layout and encourages the population to collapse around one strategy.
The next version should preserve a small, diverse elite set. Selection could keep the top scorer plus candidates separated by behavioral descriptors such as pace, passes, lane-change frequency, following time, and survival. Mutations would then branch from several proven strategies instead of one. The question changes from “which car won?” to “which distinct ways of driving are worth exploring further?”
Treat the reward ledger as a hypothesis
The score is not an objective truth about good driving. It is a compact statement of what this experiment values. Increasing the passing bonus may produce decisive overtaking or reckless weaving. Raising the collision penalty may improve safety or reward a car that never challenges traffic. Even a pace reward can accidentally favor sustained forward motion over useful positioning.
A useful comparison should run the same saved elites and traffic seeds against several named ledgers, then compare progress, passes, survival, tailing, and behavioral diversity separately. That would show whether an apparent improvement survives a change in incentives—or exists only because one coefficient made the chart look better.
Compare switches with continuous control
The current network emits four binary decisions: forward, left, right, and reverse are either on or off. Vehicle physics softens those switches with acceleration, coasting, braking, and a speed limit, but steering still begins with a threshold crossing. That makes the policy easy to inspect while encouraging abrupt corrections near a decision boundary.
A continuous-output policy would instead emit steering and throttle values across a range. The comparison should keep sensors, traffic seeds, fitness terms, and population budget fixed. Then the interesting evidence is not just final score: it is steering smoothness, recovery time, lane stability, overtaking behavior, and whether the more expressive controller becomes harder to evolve or explain.
What the result does and does not show
The source repository demonstrates ray casting, segment intersection, polygon collision, a feed-forward threshold network, mutation, local persistence, seeded traffic, fitness design, and a network visualizer. It does not establish a robust autonomous-driving model. Traffic is synthetic, the objective is hand-designed, and the population is evaluated in a simplified browser world.
The experiment is useful because perception, policy, physics, selection, and visualization are small enough to inspect together. With those boundaries visible, “learning” stops being a glow around the system and becomes a sequence of concrete choices.
Put the pieces together
The complete source lab now arrives after the mechanism. These views share one evolving population and saved history. Garage edits the input topology while paused; Network exposes live activations; Fitness compares the current run with ghosted generations and makes the reward ledger editable.