Yellowstone
Put a herd of grazers on the real ground of the Yellowstone area, with its rain, snow, rivers and seasons, give each animal a small brain that evolves, and let a few years go by. Then release wolves, the way they were brought back to Yellowstone in 1995 after about seventy years away, and see what changes. Nothing tells the grass where to grow, the grazers how to flee, or the wolves how to hunt. It runs entirely in your browser, so there is no server behind it.
A toy ecosystem, not a model of the real park. Rebuilt in JavaScript from github.com/jpsank/thesis, with terrain, water, snow, wolves, days and seasons added. The heights are real, from the public Terrain Tiles (built from USGS and NASA elevation data); everything on top of them is made up, except that the weather outside the map (the free atmosphere's temperature and wind) is put in from weather-balloon records, and how much it precipitates, and how that changes with height and latitude, is set to match the PRISM 1991–2020 normals, and the snow melts out within about three weeks of the dates at the park's SNOTEL stations (the model's snowpacks are thinner than the stations' at the same heights).
The model
- The world is a 400 × 400 grid covering a square 600 km across, centred on Yellowstone National Park (41.9° to 47.3° north, 106.7° to 114.3° west), so a cell is 1.5 km wide. The ground is the real ground: the park's high plateau and caldera, the Absaroka, Beartooth, Gallatin, Teton and Wind River ranges around it, the Bighorns to the east, the Snake River plain to the south-west and the river valleys below, from about 700 m to nearly 3,900 m. All four edges are walls. Every cell has ground at some height, a temperature, an amount of water, an amount of nitrogen and an amount of grass, and at most one animal. It starts with 1,600 prey and grass everywhere. Wolves arrive when you release them.
- Height is the climate. The map spans a little over five degrees of latitude, which makes the north only about three degrees colder than the south. What changes the weather from place to place is height: the air is about 6 °C colder for every kilometre up in summer (less in winter, when cold air pools in the valleys), and it rains and snows more the higher the ground, so the valleys at the edges are warm and snow-free early, while the plateau and the ranges above about 2,400 m pile up deep snow that lasts into summer, the way they do in the park. Nothing tells an animal where to be when. If any of them move with the seasons, down in winter and up in summer, they have worked it out for themselves.
- Days and seasons. A day is 60 steps and a year is 30 days (1,800 steps), so each season lasts about 450 steps. The world starts at noon on the summer solstice, 21 June, and the year follows the real calendar, with spring from March to May. The sun is placed where it really would be: from the latitude, the time of year (it climbs to 23.4° north of the equator at midsummer and falls the same distance south at midwinter) and the hour, with the small drift of noon through the year that real sundials have. So the days are long in summer and short in winter, and the sun stands higher in the south of the map than in the north. The air near the ground is worked out, not given. Only what comes from outside the map is put in: the temperature and the wind of the free atmosphere above it, as weather balloons at Riverton, Wyoming and Great Falls, Montana measured them in 1991–2020 (NOAA's radiosonde archive), with the wind near the ground taken as 40% of that at about 3 km. The air at each cell is a layer that the wind carries across the map, so what arrives at the west edge is the free atmosphere. The ground warms or cools it (day and night come from this) through a boundary layer that is deeper the more heat the ground gives, it mixes with the free atmosphere above (quickly while the ground heats it, slowly while it cools it), and cold air runs downhill. The temperature shown is the air at the middle of the map. The ground has a temperature of its own on every cell, from an energy balance. It gains the sunlight it absorbs (thinned by the air and by cloud, which the model has no weather for, so it uses the average, and mostly reflected by snow) and the heat the sky sends down; it loses the heat it radiates, the heat it gives the air above it and the heat that evaporates water; and animals warm it (see below). The heat it gives the air is what warms the air above it. Water holds a lot of heat for its weight, so wet ground and ponds warm and cool slowly while dry ground swings with the day. The surface (the skin of snow, ice or ground that meets the air) passes heat down to a layer of ground through whatever lies on it, so a snowpack, which is ice and air and conducts heat poorly, keeps the ground under it near freezing while the air above goes far below (at the park's SNOTEL stations the soil under the snow sits at about 0 °C all winter), and deeper ground holds the year's average warmth. What snow is like follows from how dense it is, which is a state: new snow is light (about 100 kg/m³) and a good insulator, it settles under its own weight (faster when warm) and where meltwater freezes in it, and as it ages it conducts better and darkens (its albedo falls from 0.85 to 0.75). Snow that falls on open water melts into it, and the water pays the heat that takes. Substances (water, ice, soil, air) are described once, by their density, specific heat, conductivity, albedo and emissivity, in
substances.js, and the heat capacities, conductivities and albedos used everywhere come from there. Snow stops the surface rising above freezing: the heat that would warm it melts snow instead, but a pack first has to warm through and holds some meltwater, which freezes again on cold nights, as in life. Deep water freezes over when the ground layer under it cools to freezing, and the ice insulates it too (Yellowstone Lake is frozen from December to April, though its ice is thinner than the real half metre or more, since the model leaves the wind's snow-clearing out). The ground temperature slows the grass and makes animals burn more; an animal standing on snow or ice is in the air, so it feels the air's temperature. A slope gets more sun the more squarely it faces it, so slopes that face south are warmer than ones that face north: their snow melts first and their grass starts first, while the north-facing ones stay cold and snowy longest. The sun is also placed for each cell's own longitude, so it rises and sets about half an hour earlier in the east of the map than in the west, and the light moves round the hills through the day and the year. A hill throws a shadow: from each cell a ray is followed toward the sun for up to 60 km, and if ground along it rises higher in the sky than the sun is, the cell gets only skylight (with a soft edge, because cells are 1.5 km across). So valleys behind a ridge wait for the sun on winter mornings and evenings (at 8 am at midwinter about a third of the middle of the map is in shade, and at noon none of it). The shadows are cast by the map's 1.5 km cells, so they are those of the big ranges; the finer terrain data show two to five times as much shade in mid-morning and mid-afternoon, from smaller hills, which is not in the model. - Water. Rain falls over the whole map, in showers that are more frequent and heavier in wetter months. How much falls each month follows the average over the map in the PRISM 1991–2020 normals: wettest in May and June, driest from July to September. It rains and snows more the higher the ground (in winter each kilometre up adds about as much as the map's average, in summer about a third of that) and more in the north than in the south. Where the air is near freezing it falls as snow instead, which piles up, mostly on the high ground first, and melts when the sun and the warm air give it the heat to, so the snow lies longest on the ridges. Water runs downhill, filling the low ground, and carries dissolved nitrogen with it. Rivers leave across the edges of the map: water that gets there drains away, with its nitrogen. The lakes are in the ground: where the elevation data shows a lake (a flat patch at the water level) the lake bed is dug below it, to a depth worked out from the lake's area (the volume and area scaling law of Cael and colleagues, 2017) and shaped like a bowl, so the depths are estimates, not surveys. They start full, then fill and drain with the rain, the snowmelt, the evaporation and the river that leaves them, so Yellowstone Lake rises in early summer and falls through the winter. Every cell holds on to the first couple of centimetres of water on it (about 26 mm), which is how soil and grass keep rain, and only what lies above that runs off; deeper water runs downhill in any of eight directions. Some evaporates (as much as the energy left over from the sun allows: more where it is warm and sunny, none through snow), some soaks away below the roots, and grass drinks the rest.
- Grass grows on every cell in proportion to the sunlight, as long as the soil has water and nitrogen and is not frozen, flooded, dried out or under snow. Cold soil slows the roots, so grass takes up less water and nitrogen and grows less the colder the ground is. Growing uses up water and takes nitrogen out of the soil. Grass cannot grow under an animal, so standing still has a price. Seed blows in from the cells around it, so patches spread and regrow once they are grazed down.
- Seeing. An animal faces one of eight directions and looks out along a fan of 21 rays from the way it faces, reading the colour of the ground along each at four distances: the cell next to it, the next cell, then the average of the cells 3 and 4 away, then the average of the cells 5 and 6 away (out to 9 km), so that no cell along a ray goes unseen. A herbivore's fan covers about 300° of the circle, nearly all the way round; a hunter's narrows with its diet, to 100° for a pure meat-eater, with the same 21 rays packed closer, so it sees less of the world but in finer detail. Ground that rises into the line of sight hides everything behind it, and hidden cells are seen as plain grey, so a ridge shows up as a grey wedge. The eye is 2 m up, and the model's cells are 1.5 km, so it is the big hills that block the view and not the small ones. The ground is the colours of the land view: bare ground is tan, lighter the higher it is and shaded where a slope turns from the sun, with green grass, blue water and white snow over it. Other animals are orange for grass-eaters through yellow for meat-eaters, with more blue as their energy runs down. Nobody sees energy, height, depth or snow depth as a number, only these colours. How clearly they see depends on the sunlight on each cell: so it is clear where the sun shines squarely and fades toward grey where the light fails: at dawn and dusk, on slopes turned away from the sun, in the shade of a hill or in winter's low sun, down to a fifth of its clarity at night, because deer and wolves both see well by starlight.
- Acting. What the brain sees is always from the way the animal faces, so what it does is relative to that too. It has nine outputs, a grid of turning (left, none or right, by one eighth of a circle) against moving (forward, stay or back, along the new heading), and each says how much it wants that action. Each step costs energy, more the longer it is and more again for every bit of height it climbs (going downhill is free) for water and for ploughing through snow (the deeper, the dearer, though standing in snow costs nothing; a puddle costs next to nothing, and from about a metre down the animal is swimming, which costs several times a step on dry land, however deep it goes, and treading water costs the same as a step), and the animal takes the step where what it wants outweighs what it costs the most. So wanting a step twice as much cancels a step that costs twice as much, and slopes, floods and snow are felt without the network ever being told about them. Stepping onto an empty cell moves there, and stepping onto another animal is a bite. An animal with more than 100 energy also picks where to breed, with a second set of nine outputs that is a map of its eight neighbours as it faces: ahead, ahead and to the right, and so on round to ahead and to the left.
- Eating and digesting. An animal grazes the grass on the cell it stands on (less of it the deeper the snow lies over it, and none once the snow is deep enough to bury it), and food then passes through a gut for a few steps. Every animal has a diet between 0 and 1, passed on to its children with small changes. At 0 it gets full energy from grass and almost nothing from meat; at 1 it is the reverse; in between it gets some from each and the most from neither. A bite succeeds with a chance equal to the square of its diet, so grazers almost never kill and wolves usually do. A killer takes part of its victim as meat. Whatever an animal cannot use goes onto the ground below it as nitrogen, and a body gives its nitrogen back to the ground when it dies. The nitrogen then flows with the water and feeds the grass.
- Energy. Animals burn a little energy every step, more when it is cold, which means in winter and higher up the hill, and a good deal more when they stand in cold water, which draws heat from a body far faster than air does. Everything they burn is given off as heat into the ground they stand on, which conducts it to the eight cells around it until it leaks away into the air above. So an animal warms its neighbours and is warmed by them, and a crowd in winter burns less than a loner. Anything at zero is dead. Keeping a brain costs energy too, a hundred-thousandth of a unit a step for each of its connections, so a bigger brain has to pay for itself. Breeding costs 25 per parent, and only animals with similar diets mate. Wolves are the animals with a diet of 0.5 or more. Released wolves start at 0.9, with random brains.
- Evolving. A child copies its parent's genome, with small random changes to weights and biases and now and then a new neuron or connection. Two neighbours that each pick the other as the one to breed with breed together and mix their genomes. Released wolves start with random brains and have to evolve their way into hunting.
- Genome to brain. The genome is a small network (grown by NEAT) that is asked about pairs of places in a three-dimensional space, "how strongly should a neuron here be wired to one there?" (the HyperNEAT recipe). The eye's 252 neurons and the 18 outputs have fixed places in that space. The hidden neurons do not: the architecture is found the way ES-HyperNEAT finds it. There are three layers, and each has its own 4 × 4 × 4 grid of 64 places a hidden neuron could be (with room for 32 neurons in the first layer and 16 in each of the others). In the first layer a place gets a neuron where the genome, asked about connections into it from the eye, gives a strong answer that differs from its answer next door, so that a smooth stretch is not filled with neurons. The second layer is found the same way from the first layer's neurons, and the third from the first two. The genome is told which layer it is being asked about, as two more inputs, so it can wire the layers differently. Then every neuron is asked about each of the 18 outputs; a neuron that cannot reach an output is dropped, with any that only fed it. So how many hidden neurons there are, how many layers deep they go, how densely they are wired and which parts of the eye they listen to all come from the genome, and evolve with it: a brain can have no hidden neurons at all or well over two thousand connections. (The original subdivides space more finely wherever the answers vary; here the places are a fixed grid, which keeps growing a brain cheap enough to do for every newborn.)
- Where it runs. If your browser has WebGPU, the ground (grass, water, snow, nitrogen and temperature on all 160,000 cells) and every animal's brain are worked out on the graphics card, thousands of cells and animals at a time, and only the animals' choices come back to be carried out. A brain is grown on the card from its genome the moment its animal is born. Without WebGPU, or with the box below ticked off, the same rules run on the CPU, which is much slower on a map this big. The card works in 32-bit numbers and the CPU in 64-bit, so a seed repeats on the same machine and setting but not between the two.
- The 3D view. With WebGPU you can switch the map to a 3D landscape, drag it round, zoom in and slide across it. The land is drawn at its real heights, stretched upward (the real land is very flat beside its width, and a slider sets how much), in the same colours as the flat map, so every layer shows there too. Hills hide what is behind them, because the picture is made from where the camera is, much as an animal sees from where it stands. Animals are small arrowheads pointing the way they face, and clicking one shows its brain and lays the field of view it sees with on the ground. The graphics card draws the surface straight from the heights and colours it already has, and a run goes no slower with the 3D view showing.
Run it
Drag to turn the view, shift-drag or right-drag to slide it, scroll or pinch to zoom, double-click to start again. Click an animal to see its brain.
- grass
- water
- diet: grass to meat
- low energy (paler)
- can breed (darker)
Orange cells are positive, blue negative, and the outlined cell is the one it picks. The hidden neurons are in columns by layer: layer 1 listens to the eye, layer 2 to layer 1, layer 3 to layers 1 and 2, and the picks listen to all of them. Hover a neuron to light up what it listens to in yellow (parts of the eye, or earlier neurons; a dashed outline is a part of the eye it hears of only through earlier neurons) and the picks it feeds in blue. The stronger the connection, the stronger the outline. Hover a cell for its value.
The genome that grew it
The genome is a small NEAT network. It is asked about pairs of places, with eight inputs (where the receiving neuron is, where the sending one is, and the layer of each) and gives back the connection weight, and where its answers stand out decides where the hidden neurons are. Orange links add, blue links subtract, and thicker is stronger.
Prey, wolves and grass in this run
Each is on its own scale: prey on the left, wolves and grass on the right. Move over the plot to read a step.
Every seed gives a different run, and the same seed repeats the same run in the same browser. Expect booms and crashes. If it slows down, that is hundreds of brains each deciding something every step.