Can a Virtual Brain Adapt to a New Physical Obstacle? Replicating a Navigation Model with Python and AI
The goal of my project was to reproduce a brain-based navigation system (Danieli & Lepperød, 2026) and to observe how the virtual animal’s brain adapts to unexpected changes in its environment. Using the code written by the authors and 64 replications, I replicated the main finding of the paper: the introduction of a new wall would cause food-finding to decrease and lead to more bumps into the wall until the brain adapted. The biggest thing I learned was that making hypotheses based on only a few samples can be fooling. After I compared one animal that recovered with one that got stuck, I made an assumption that more exploration leads to better recovery; however, 500 more runs that I tested this theory on didn’t confirm it.
Video Walkthrough
I have also recorded a short Loom video talking about my experience and explaining how the model works in simple words. You can watch it here!
The Main Problem & My ‘Why?’
Wild animals rely on learned routes of their territory to find food, water, and shelter, but environmental change and direct human impact are constantly altering their environment, making their learned maps outdated. When a road crosses a forest or a new fence is built, how do animals’ navigation methods adapt to those changes?
In one of my articles, I studied how we can analyze risk assessment and decision making of wild mammals in those conditions using a combination of GPS collars and satellite maps. While this method can help us effectively observe how animals move across their habitat, it fails to demonstrate the internal brain processes, including how and why those decisions are made. On the other hand, in a lab study of rats scientists can record brain cells directly; however, these recordings usually happened in small, controlled spaces, without representing real habitat conditions.
That’s why I decided to replicate a brain-inspired navigation model. It allowed me to explore what could happen inside a brain when animals navigate in a way that cannot be done using the GPS collar or in the majority of the lab-based experiments. In the simulation, I could add a new wall at any point in time and then run the same experiment multiple times without altering anything else or doing any harm to animals. I chose this paper in particular because its “detour” experiment directly tests what happens when an environment suddenly changes, which combines my two interests: neuroethology and wildlife conservation. Its code is also publicly available, and as I’m completely new to coding, it was a huge advantage.
The Model Itself
The model I replicated was originally created by Krubeal Danieli and Mikkel Elle Lepperød (2026), “Flexible navigation with neuromodulated cognitive maps”, PLOS Computational Biology. It is a simplified, brain-inspired computer model that acts as the brain of a virtual animal moving around a pretend room, which has a food patch and a new wall added later in an experiment. Specifically, it is based on the hippocampus — a part of the brain responsible for memory and navigation.
The program works by creating new place cells — cells that switch on when the animal is in one particular spot — while exploring the map. Place cells work in two ways: when the animal reaches an unfamiliar place, a new place cell is created for it, and when it returns to a familiar place, that cell acts as a “you are here” sign. Some place cells stay untagged, while others get tagged by two signals: “food here” when the animal finds food, and “wall here” when it bumps into a wall. The animal’s main goal is to find food, so it either plans the shortest route to the food patch using its place cells, avoiding the ones tagged “wall here,” or keeps exploring the map if none of its planned routes work.
Once a new wall is placed, the old brain map becomes outdated, so it has to spend more time exploring and tagging cells “wall here” to find the best route around it. The animal in the model is also blind, so it only knows its own movement.
According to the paper’s findings, an animal can usually successfully adapt when a new wall is created, though some of the runs might be unsuccessful and an animal gets stuck (9 out of 64 in the paper). Moreover, the “wall” signals mattered more than the “food” signals for navigation.
My goal was to reproduce a figure from the paper (Figure 2F) that demonstrates how often the animal found food and bumped into walls before and after the wall is placed, averaged over 64 runs.
An animal starts from exploring: a stage of an experiment without a wall but with a food patch, so finding food is expected to increase, while bumping is expected to do the opposite as an animal becomes more aware of its surroundings. Once a new wall is placed (after 5,000 steps of exploration), food-finding drastically falls and bumping rises. After some more time spent on exploration after the wall is placed (the remaining 10,000 steps), both are expected to gradually recover, though not fully back to their original positions.
Methodology
To replicate the results of the experiment, I used the scientists’ own code: an experiment written in Python, with the brain part written in C++ so it runs faster. I worked in VS Code, and as I’m completely new to coding, I mostly relied on Claude Code to write and run the code following my instructions. So I didn’t write the code myself; my main role was analyzing the results and making decisions: which version of the code to use, what counts as “recovered,” what predictions to make and how to effectively test them.
I began by setting up the code on my computer and doing a quick test to ensure that everything worked fine. Next, I generated the 2F Figure from 232 simulations done by the researchers and discovered an inconsistency: in the present code, the new wall is introduced at step 25,000, while in the paper, it is 5,000. With the help of Git, which tracks the history of changes of the code, I discovered that both the parameters and the brain had been altered after the figure was generated, so I went back to the version of the code from 11 May 2026.
This experiment was done 64 times. In all of these cases, the room, the food and the settings were the same and there was a wall introduced at step 5,000. The only difference between them was the set of random decisions made by the animal. At every step the program was logging whether the animal touched the wall or ate the food, and from that I calculated the averaged over all 64 runs number of bumps and meals per 1,000 steps. To verify my results, I compared them with the results presented in the paper’s Figure 2F.
Get Vieronika Labunets’s stories in your inbox
Join Medium for free to get updates from this writer.
Finally, I ran 500 more runs and trained a simple AI to predict which animals would get stuck.
Results
At the end, my results reproduced the main finding of the paper! When the new wall appeared at step 5,000, food-finding dropped rapidly from around 10 to below 1 per 1,000 steps while collisions increased from around 3.5 to 9 per 1,000 steps. It took some time after this for the animal to find its way around the wall: collisions decreased as food-finding increased again, but not fully to what it was before.
Compared to the paper’s result of 9 out of 64 runs failing (animal not being able to find food again), mine ended up being 12 out of 64. This difference is small enough, so it could easily happen by chance.
However, the graph from my experiment was not an exact copy. We can notice that, at the very start, there is a tall green spike, because in the code the animal starts right on the food and gets a free meal right away, while the paper says it starts in a random spot. Also, the recovery after the wall appeared was weaker in my runs: food-finding came back to about half of its peak, compared with about three-quarters in the paper. So I reproduced the main result, but not every detail.
How I Tested My Prediction with AI
While comparing brain maps, I noticed that an animal that recovered (seed 1) had explored more of the room before the wall appeared than one that got stuck (seed 4). So I predicted that animals that explore more are more likely to recover later.
To test this, I ran 500 new runs, measured each animal’s brain map at the moment the wall appeared, and trained a decision tree to predict which animals would get stuck, testing it only on runs it had never seen. The AI scored 53%, where a random guess scores 50%, so it was no better than guessing.
My prediction didn’t hold up either: recovered and stuck animals had explored almost exactly the same amount of the room (34.3% vs. 35.0%).
My best explanation, which I haven’t proven, is that in this version of the code, recovery depends mostly on luck while exploring, not on planning a route around the wall. For instance, the animals that had never found the food before the wall appeared recovered just about as frequently as those that had (91% vs 93%). My first 64 runs seem to be a bit unlucky: 18% of them got stuck, compared with 7% in the 500 new runs, so it also demonstrated ow important it is to check data on bigger samples.
What Went Wrong
The biggest problem was that the shared code didn’t match the paper, which I solved by going back to the 11 May 2026 version, as described in Methodology. Also, I observed a pattern for my first 64 runs: trapped animals would run into the wall more frequently. I decided to test it on 500 other runs, and then it became apparent that there was no such pattern. So I’ve also learned the importance of always checking ideas and hypotheses on new and a broader scope of data.
Limitations
One of the reasons my version is limited is that a model functions as a simplified version of an animal in a small room and with one wall. In natural surroundings, animals use a variety of their senses for navigation, including what they see. In an experiment, an animal is blind, so it only relies on its own movement and two signals, and its brain is much simpler than a real one. It also always starts in the same spot.
I also cannot say for sure that the code for 11 May is exactly the same code that was used by the authors to generate their graph. Moreover, the AI found only 27 stuck instances among all the new runs, thus making me less confident in the results it generated. Hence, I cannot say anything about how wild animals evolve; the model just provided an opportunity to make predictions and test them.
What I learned
While working with this model and testing my hypotheses, I realized how easily a few examples can fool you. By comparing just two animals, one that recovered and one that got stuck, I made an assumption that exploring more helps recovery, but 500 new runs showed it actually didn’t. If I did it again, I would and test my ideas on new data right away instead of trusting the first patterns I saw.
Next steps
For my next step, I’m really interested in exploring how the brain-inspired map can adapt when environmental changes are more complex, more closely resembling real-life conditions. I want to alter an animal’s surroundings in new ways, for example, by adding several walls to break the room into pieces, like a habitat split up by roads, or making a wall with a gap, like a wildlife crossing. Since my results suggested that recovery depends mostly on luck while exploring, it would be interesting to see whether that still holds with such changes.
Hi, it’s Vieronika. I’m an Innovator at The Knowledge Society (TKS), passionate about wildlife conservation.
My curiosity started with a simple question I got while playing with my dog: why do animals respond the way they do, and what drives their reactions? Now I’m exploring how understanding animal cognitive behaviour and conservation tech can help us protect them, and I hope to inspire others to care about the animals we share this planet with.
You can find me on LinkedIn.







