Virtual Agent Playground
Four model agents from my research on classes of adaptive behavior. Each solves a task with a tiny nervous system, coupled to a body and an environment. Pick a task, watch the agent do it, then change its parameters and see how the behavior changes. Everything runs in your browser, in JavaScript ports of the Julia and Mathematica models I use for my figures.
Approach: steer to a goal
A Braitenberg vehicle has two sensors at its front and a motor on each side. Each sensor drives the motor on the opposite side: the wires cross. When the stimulus lies to the right, the right sensor reads more, the left wheel turns faster, and the vehicle swings toward it. A constant forward drive keeps it moving at 1 m/s, and a lag makes its turning catch up with its motors.
Drag the stimulus to move it. Click anywhere to release a vehicle; drag before letting go to aim it.
Wiring
A negative synapse inhibits its motor. With both negative the vehicle behaves like Braitenberg's uncrossed "coward" and turns away.
What these settings do
approach, with overshoot
This is how my parameter charts classify the vehicle: by where its heading comes to rest for a goal held still 2 m away. In the arena the goal is a point, so a vehicle that approaches drives through it and loops back.
The model
Each vehicle moves at the constant speed V along its heading φ, and turns toward the stimulus:
ẋ = V cos φ, ẏ = V sin φ, τ φ̈ = −φ̇ + (δ/d) e−cd r [ (fl − fr) / (δ cd) − ½(fl + fr) sin ψ ]
Here r is the distance to the stimulus and ψ the heading error, the angle between where the vehicle points and where the stimulus is. The stimulus is S = e−cd r/cd, each sensor reads it at its corner of the vehicle, and each motor's output is its synapse times the opposite sensor's reading. With equal synapses fl = fr = f the equation is τ φ̈ = −φ̇ − m e−cd r sin ψ with m = (δ/d) f. That is Fajen and Warren's (2003) law for how people walk to a goal, with sin ψ in place of ψ. The default vehicle is matched to their fit: τ = 1/b = 0.31 s, m = k/b = 2.31 /s and cd = 0.4 /m, and its paths stay within about a centimetre of theirs. Unequal synapses give it a built-in turn, like a car whose wheels are out of line.
Walk: step in rhythm
Beer's one-legged walker is a cockroach with a single leg and a single neuron. The neuron senses the leg's angle. While its output is above ½ the foot is down and the leg pushes the body forward (stance); otherwise the foot is lifted and the leg swings forward (swing). Nothing in it keeps time. The rhythm comes from the loop through the body: the neuron excites itself strongly enough to have two stable states over a range of leg angles, a fold, and the leg runs back and forth between the fold's edges.
Grab the leg to hold it at an angle. Move it forward until the neuron flips and the foot goes down.
- Period
- –
- Amplitude
- –
- Mean leg angle
- –
- Stride
- –
Neuron and body
Reading the fold
The grey curve in the lower chart is where the neuron would settle if you held the leg still at each angle. For w > 4 it folds back on itself: between its two bends there are two stable outputs (solid) with an unstable one between them (dashed). A fast neuron rides the lower branch while the leg swings forward. At the fold's front edge it jumps up and the foot goes down. Stance then pushes the leg back along the upper branch to the back edge, where the neuron drops and the foot lifts.
The fold sets the step's amplitude, and the body's gains and the neuron's speed set its period. Take the fold away (w ≤ 4) and a fast neuron can no longer hold a decision: the leg stalls at one angle. A slow neuron can still walk without a fold, because its lag stands in for the fold's memory.
The model
The leg has angle φ (forward positive) and angular velocity ω. The neuron has state y and output o = σ(y + β), with σ the logistic function. It senses the leg angle through the gain SW = 30/π:
τ ẏ = −y + w o + SW φ
Swing (o < ½, foot up): ω̇ = αmax(1 − 2o), which pushes the leg forward, and the body stands still. Stance (o > ½, foot down): ω̇ = amax(1 − 2o) cos²φ / d − 2ω² tan φ, which pushes the leg back. The foot stays put, so the body moves forward at −d ω / cos²φ, where d = L cos φ is fixed when the foot goes down. The foot goes down when o rises through ½ and lifts when it falls through ½. The leg has length L = 15 and stops at ±30°. The gains are Beer's (2010): αmax = 1/40 and amax = 1/20. The paper's walker has w = 10, β = −5 and τ = 0.1, and walks with a period of 26.2 time units and an amplitude of 16°.
Swing: pump it up
A swing with a single mass on a rope that stretches like a spring. The swinger can only move the mass along the rope, out from the pivot or in toward it, and has one motor neuron to do it with. The neuron senses how fast the mass moves along the rope and pushes it further the same way. It never senses the swing's angle. Turn up the neuron's gain and the mass starts to bob on the rope by itself. Turn it up further and the bobbing slows until it falls into step with the swing, two bobs to every swing, as a child stands and squats twice in each swing. The swing then pumps itself up.
Grab the mass to hold it, and let go to drop the swing from there. The arrow keys push it.
from a nudge from a drop at 90° from a spin now × the rope ran away
- Swing amplitude
- –
- Swing period
- –
- Bob period
- –
- Bobs per swing
- –
Neuron and body
On the edge, a nudge dies away but a swing that is already high keeps going: push it a few times and see.
Reading the diagram
Each dot in the lower chart is where the swing ends up after 200 s at that gain, from one of three starts: a nudge, a drop from 90° and a spin over the top. Above, its swing's amplitude, or the band at the top if it loops; below, how far the mass bobs along the rope. The ring is the swing now.
Where the starts end up in different places, the swing has more than one behavior at that gain, and which one you see depends on its history.
The model
The swing has angle θ (0 hanging down) and angular velocity Ω. The rope's rest length is 1 m, and the mass sits a stretch r beyond it, moving along the rope at v. The neuron's output u pushes the mass outward when positive and inward when negative:
Ω̇ = −g sin θ / (1 + r) − b Ω, v̇ = u / (1 + r²) + g cos θ + (1 + r) Ω² − k r − c v, u̇ = ϕ (A tanh(ρ v) − u)
The swing's angle obeys a damped pendulum's equation for the rope's present length, so the swing slows when the rope is long and speeds up when it is short. Along the rope the mass feels gravity's share g cos θ, the swing's centrifugal pull (1 + r) Ω², the rope's spring −k r and damping −c v, and the neuron's push, which weakens as 1/(1 + r²) the further the mass is from the rope's rest length. The neuron relaxes at rate ϕ toward A tanh(ρ v). It senses the mass's speed along the rope and, with a positive gain, pushes it further the way it is already going. The defaults are those of my notebook: g = 9.81, b = 0.3, ρ = 2, ϕ = 20, k = 100 and c = 20, which makes the rope's spring critically damped.
Linearized at the rest, the bob's characteristic polynomial is λ³ + (c + ϕ) λ² + (cϕ + k − aϕρA) λ + kϕ, with a = 1/(1 + r*²) and the rest's stretch r* = g/k. The rest loses its stability at the Hopf bifurcation (c + ϕ)(cϕ + k − aϕρA) = kϕ, at A ≈ 11.4, and the mass starts to bob with period 2π / √(kϕ/(c + ϕ)) = 0.89 s. That is too fast for the swing, whose own period is 2.1 s. The swing is pumped only once the bob has slowed to half the swing's period.
Categorize: catch circles, avoid lines
An object falls toward an agent that can only move left and right and sees through seven distance rays. If the object is a circle it must end up underneath it, within 30 of its centre. If it is a line it must get out of the way. Circles and lines are the same width, so one glance can't tell them apart: the agent has to move to find out. Its brain is a small, left–right symmetric network of neurons, evolved to do the task.
The strip shows what each of the seven rays reads, left to right: white is far, black is close. Up close a circle reads about 15 nearer than a line of the same height (its bottom hangs below its centre); the strip's exponential scale spends its greys on short rays so the difference shows. Drag the agent to push it off course: as long as the object stays in its view, it recovers. Between drops, drag it to choose where the next object falls.
circle trials line trials catch zone
Agent
Trials
Advanced configuration
How a ray's length maps to the strip's grey. Linear spreads the greys evenly over the 220 of a ray; the curved scales spend most of them on short rays, where circles and lines differ.
The model
The agent (Beer 2003) is a disc of diameter 30 at the bottom of the world. Seven rays fan out over 30° from its top, each 220 long. Ray j gives the input Ij = 10 (220 − its length to the object)/220. The neurons form a continuous-time recurrent neural network,
τi ẏi = −yi + Σk Wik σ(yk + θk) + Σj Uij Ij
with every neuron connected to every neuron and to every ray. The network is mirror-symmetric: each left neuron Li has a twin Ri with mirrored weights, and odd-sized brains add a midline neuron C. L₁ and R₁ drive the body with the force F = 5 (oR₁ − oL₁), and the agent's velocity follows it, v̇ = F − v. The object falls from height 275 at speed 3. Each trial runs 8670 Euler steps of 0.01 until the object reaches the agent. The weights were evolved so that all 100 trials of the task come out right: 50 circles and 50 lines, started 1 to 50 to one side, each standing for its mirror image on the other. Every agent here does so. The agents are grouped into families by the angle at which they hold the object's edge in view.
