Hands-On Neuroevolution with Python: Build high-performing artificial neural network architectures using neuroevolution-based algorithms - podcast episode cover

Hands-On Neuroevolution with Python: Build high-performing artificial neural network architectures using neuroevolution-based algorithms

Jul 18, 202521 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

Provides an in-depth guide to neuroevolution, a field focusing on evolving artificial neural networks, primarily using the NEAT algorithm and its advanced derivatives like HyperNEAT and ES-HyperNEAT. It covers practical applications such as solving the XOR problem, pole-balancing, and autonomous maze navigation, highlighting the effectiveness of Novelty Search optimization in deceptive landscapes. The text also explores deep neuroevolution for reinforcement learning in complex environments like Atari games, detailing CNN architectures and unique genome encoding schemes. Additionally, it offers best practices, coding tips, and performance metrics for those implementing neuroevolutionary algorithms.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/Hands-Neuroevolution-Python-high-performing-neuroevolution-based-ebook/dp/B082J28SZ7?&linkCode=ll1&tag=cvthunderx-20&linkId=253a597add5fafba06c6ae92ac8c9868&language=en_US&ref_=as_li_ss_tl


Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

What if the key to building really intelligent AI isn't about meticulously optimizing every single parameter. What if it's more about letting it evolve. Imagine maybe a shortcut to sophisticated AI, one that sidesteps some of the usual complexities. May be taking a page straight from Nature's playbook. Today, we're embarking in a deep dive into neuroevolution. It's this fascinating family of machine learning methods that use evolutionary algorithms to build well,

high performing artificial neural networks. Our mission is to unpack this powerful alternative to conventional deep learning. We want to reveal how it's used for complex tasks than games, robotics, and how it delivers sometimes surprisingly energy efficient, kind of elegant solutions. You'll get insights from the core concepts right through to some really surprising real world applications, all distilled from hands on neuroevolution with Python. So let's explore this

alternative path to AI. I mean, many of us know about AI learning from massive data sets complex calculations, but neuroevolution offers this really different, almost organic approach.

Speaker 2

It's really fascinating, isn't it. How directly it draws inspiration from natural selection. Instead of, you know, explicitly programming the perfect network, you're essentially cultivating a population of networks. You let the fittest survive and reproduce, and that leads to increasingly complex, more optimal solutions over generations. It's a very different way of thinking.

Speaker 1

So it all starts at the brain, doesn't it? Our own brains these incredibly complex graphs of nodes and links. Early AI ambitions were sort of to imitate that directly, right, hoping for artificial general intelligence. We're still well working towards that, but neuroevolution is helping us build some powerful narrow AI agents right now.

Speaker 2

Indeed, artificial neural networks an ns their universal approximators. Theoretically they can approximate to any function, but the real challenge is how you train them. How do you select the right weight values for all those connections. Do you like meticulously adjust weights with methods like gradiate descent, or do you let them evolve? Neuroevolution takes that second.

Speaker 1

Path, utionary path. So a foundational algorithm here is neat neuroevolution of augmenting topologies. What's the core idea there? What makes it revolutionary, especially in how it deals with complexity.

Speaker 2

Well, the big breakthrough is it's complexification strategy. It starts simple, It reduces the huge parameter search space. But beginning with tiny simple ceed genomes, just inputs, outputs, maybe a biased neuron, no hidden nodes at first. Then generation by generation it introduces additional genes. It expands the solution space incrementally. This mirror is natural evolution, you know, where new genes sometimes

add complexity. It's way more efficient than trying to search a massive space from the get go.

Speaker 1

Okay, so if they're evolving, how do they reproduce and mutate in a way that lets them get more complex? Is it like classic genetic algorithms?

Speaker 2

It is, Yeah, neurorevolution uses those genetic operators. Mutation can be simple things flipping bits, changing values in the genome, altering existing connections. But where NEAT gets really clever is with structural mutations, actually adding new or even entirely new nodes to the network's architecture itself.

Speaker 1

Huh. But if their structures are constantly changing, growing independently, how do you combine two different networks during reproduction? Doesn't that get messy? How do you match things up.

Speaker 2

That's a really important question, and NEAT solves it brilliantly with the innovation number. Every new gene, a connection, or a node introduced by mutation gets a unique, globally incrementing number across the whole evolutionary run during crossover. These numbers act like genetic IDs. They let the algorithm precisely align corresponding genes from two parents, even if their structures look

quite different. Any genes that don't match up, disjoint or excess ones are just added unconditionally to the offspring.

Speaker 1

Okay, I think I follow that. But what if a new, more complex structure is like temporarily less fit than a simpler one that's already pretty optimized. How do these potentially groundbreaking innovations survive long enough to actually prove their worth. Ah.

Speaker 2

That's where speciation comes in. It's directly inspired by how species form in nature. Literally, in NEAT, the population gets divided into species or niches based on how similar their network structures their topologies are. Organisms within the same species mainly compete and mate with each other. This is crucial.

It shields new, possibly brilliant, but currently underperforming topologies from immediate negative pressure For the more established networks, it gives them breathing room, lets them evolve within their niche until they might become genuinely superior. It's all about cultivating diversity for long term gain.

Speaker 1

That's pretty neat. Okay, so neat sounds powerful, But I can imagine a problem when you need a really big network, like millions of connections for complex visual recognition, directly encoding, every single connection must get unwieldy.

Speaker 2

Right, You're absolutely right. That's the big drawback of directing coding for large scale A and NS. As the network grows, the genome just balloons. It becomes computationally expensive, hard to manage. So researchers developed indirect encoding schemes much more efficient.

Speaker 1

Okay, and here's where it gets I think, really ingenious, hyper need. It uses something called a compositional pattern producing network a CPPN. What exactly is that? What does it let you do? Right?

Speaker 2

A CPPN it's a specialized neural network itself. Its job is to represent the connectivity patterns of another network, the main one You want to build the phenotype ANN as a function of its geometry. Think of it like a master blueprint, a compact set of rules for building a complex structure. This connectivity pattern is often visualized as a kind of high dimensional space like a grid. Each point on the grid tells you if and how strongly two

specific nodes in the main ANN should connect. The CPPN takes the coordinates of these nodes as input, and it outputs the connection weight. If the waits below a certain threshold, well no connection gets made.

Speaker 1

WHOA. So one small CPPN can basically act as a compressed set of instructions a blueprint for a potentially massive ANN. That sounds incredibly efficient.

Speaker 2

It allows for remarkable information compression, seriously remarkable. There is this visual discrimination task, for instance, where a CPPN with only like sixteen connections define the patterns for a main A and M with almost fifteen thousand connections. That's the compression ratio of what about point one one percent?

Speaker 1

Wow?

Speaker 2

And what this practically means for you? The listener is potentially much more energy efficient AI you can deploy powerful models where traditional deep learning is just too big or power hungry. Think edge devices. Plus, it often lets you generate solutions at different resolutions without retraining.

Speaker 1

That's a huge leap, but okay, HyperNEAT sounds powerful, but If the CPPN is the blueprint, someone still has to decide where the bricks go. Right, someone has to define the layout of the nodes in the final network.

Speaker 2

You've hit its main limitation exactly. The human experimenter still defines the layout of the phenotype Ann's nodes, the substrate we call it, right at the start. If you make a bad assumption about that layout, performance can suffer, so es HyperNEAT or evolvable substrate hypernea. It tackles this. It introduces an evolvable substrate.

Speaker 1

Hold on, so the layout of the network itself that evolves automatically too. That's really next level.

Speaker 2

Precisely, it figures out where information seems to be flowing most intensely within the potential connection space. It uses techniques like quad tree information extraction, basically clever ways to divide up the space and focus effort where needed, and then it automatically puts more hidden nodes in those high intensity regions, so the system learns not just the connections, but where

to put the nodes for the best representation. It allows automatic hidden node placement easier modular networks, and it can elaborate the structure adding nodes and connections during evolution, which basic hyper need it doesn't really do.

Speaker 1

Okay, let's shift gears a bit. Most optimization algorithms, including a lot of evolutionary ones, they try to get closer and closer to a goal. Right. They reward progress towards some objective. But what happens if the best path to that goal involves, I don't know, temporarily moving away from it, or if there are dead ends that look promising. That sounds like a fundamental problem.

Speaker 2

It is. It's the classic local optima trap. Imagine a maze the shortest path out actually requires you to walk away from the exit for a bit. First, a simple goal oriented search, one that just rewards getting closer, might walk into a dead end, a cul de sact that seems close to the exit but offers no way forward. The algorithm gets stuck. It converges to a local champion, not the true best solution.

Speaker 1

Okay, So if that goal focused approach gets stuck, what's the alternative? How does neuroevolution break free from these deceptive landscapes.

Speaker 2

That's where novelty search or NS comes in, and the core idea is really counterintuitive, almost zen like the ejective function isn't proximity to a goal. It's defined by the novelty of the behavior shown by the agent. It actively rewards doing something different. It drives evolution towards diversity of behavior.

Speaker 1

Wait you're saying it just wanders around exploring, hoping to stumble onto the solution by accident. That feels indirect.

Speaker 2

It's more sophisticated than just random watering. There's a novelty metric. Often it's measured as like the average distance of an individual's behavior to its k nearest neighbors in some abstract behavioral space. If you're doing something unique far from what others are doing, you get a high novelty score. You're rewarded. This encourages divergent evolution. It forces the population to spread out, explore the whole space, not just clump together in one

seemingly good spot. And here's the really wild part. For certain tricky, deceptive problems, novelty search can actually find solutions faster than traditional objective based search. It forces exploration that goal seeking misses.

Speaker 1

Okay, wow, so we've covered the mechanics, these cool complexification strategies, ways to handle scale. Even this idea of rewarding novelty. Let's see how this all plays out in practice. How does neuroevolution tackle some real challenges, from classic problems to complex games, even evolving its own goals. Let's start simple. Maybe the xor problem sounds basic but notoriously tricky for simple networks because it's not linearly separable. How does net handle that?

Speaker 2

Right? XR a basic ANN no hidden layers, just can't crack it, but neat starting super simple, two inputs, one output consistently evolves the necessary structure. It adds that crucial hidden node. It perfectly demonstrates needs power to grow the complexity it needs and avoid those traps that stump fixed networks. For XOR, fitness is usually calculated based on how close the output is to the correct zero or one for

all four input patterns. Get close enough, like fifteen point five out of sixteen and you solved it.

Speaker 1

Okay, makes sense moving to something more dynamic. Balancing a pole on a cart. That's a real classic and reinforcement learning.

Speaker 2

Isn't it absolutely the single pole balancing task? It's an avoidance control problem. The ANN gets inputs, cart position, velocity, poll angle, its angular velocity, all scaled nicely and then it just outputs a simple action push left or push right. Fitness is just how long it keeps the pole balanced, often measured in time steps, maybe up to hundreds of thousands, and the physics underneath are often simulated using something like a Runge Kuda method to keep it accurate.

Speaker 1

And then you mentioned trying a double pole balancing problem. That sounds way harder.

Speaker 2

Two poles, oh much harder. Two poles, often different lengths on the same cart, more state variables, much more complex physics involved. That experiment really highlighted how important that speciation thing is, finding the right balance of species diversity. Too many species and they become too small. Maybe it don't evolve fast enough. Too few any stifle innovation. It also really showed how sensitive things can be to the initial

random seed. Sometimes you just need a bit of luck in that initial population set up right.

Speaker 1

The starting conditions matter. Okay, Mazes, they're great test beds for autonomous agents. How does neuroevolution do with, say, a robot navigating a maze, avoiding walls, finding an exit.

Speaker 2

Mazes are fascinating because they often have those deceptive landscapes. We talked about cul de sacs that look promising, but are dead ends local optima. If you just use a goal oriented fitness function rewarding distance to the exit, agents often get stuck. We saw this in experiments with a hard maze configuration. Objective based search just failed. Agents got trapped near the start or in those dead ends.

Speaker 1

But what about novelty search? Did that make a difference in the mazes? Could it actually beat the goal focused approach? There?

Speaker 2

That's the key question, right For a simple maze, NS often found a solution faster and interestingly, often with a simpler network topology, sometimes even needing no hidden nodes at all. Compared to the goal oriented method. It consistently pushed agents to explore more varied paths, even for the really hard maze. While the specific library implementation we use struggled to find a perfect, winning solution, The results were far more promising

with novelty search. The exploration was much broader, much more intelligent looking. It really shows that sometimes not aiming directly at the goal is the best way to get there.

Speaker 1

Okay, this next one. It sounds like pure science fiction co evolution. Two AI populations evolving together, influencing each other.

Speaker 2

Yeah, it's a really azance concept inspired by biological ideas like commensalism, where one species benefits without affecting the other mine much. The method called safe involves two populations evolving side by side, one population of MAY solving agents and another population of well objective function candidates.

Speaker 1

Wait objective function candidates. So the MAY solver's fitness isn't just about reaching the exit anymore exactly.

Speaker 2

That's where it gets really clever. The maze solver's fitness is a combination of two things. One it's distance to the exit that's the objective part, and two the novelty of its final position, the behavioral novelty part. But here's the crucial twist. The weights used to combine these two scores. They come as outputs from an individual in the other evolving population, the objective function candidates. So the system literally evolved to find solutions for that hard maze where objective

search alone failed. It's like the AI is learning how to define its own success criteria, dynamically shifting focus between the goal and exploration.

Speaker 1

That is wild. Okay. From mazes to video games you mentioned, neuroevolution can train agents for classic atari games that usually involves deep reinforcement learning like DQN, which is known for being super computationally heavy.

Speaker 2

Traditionally, yes, deep RL methods like DQN use deep neural nets. Gradient based backpropagation needs serious GPU power for all those matrix multiplications. Deep neuroevolution offers a different path. It can approximate that q value function needed for reinforcement learning without relying on air or backpropagation at all.

Speaker 1

No backpropagation. How on earth does it train those huge deep neural networks?

Speaker 2

Then, instead of backpropit uses a pretty straightforward genetic algorithm to evolve a population of potential network controllers. The genome of each individual encodes all the trainable parameters, the millions of connection weights of a deep neural network. For the Frostbite Atari game, for instance, the agent learns just by looking at the screen pixels. It uses a convolutional neural network a CNN with something like four million parameters.

Speaker 1

Four million parameters? How do you encode that efficiently in a genome that sounds massive?

Speaker 2

This is another really clever bit of encoding. It uses the seeds of a pseudorandom number generator. The genome isn't the weights themselves, It's a list of these random seeds. These seeds are then used sequentially to generate the entire massive parameter vector for the network. So a relatively compact list of seeds can define an incredibly complex high dimensional network.

GPU acceleration is still vital, mind you, because you have to evaluate each agent, maybe running the game for twenty thousand frames or more, but the learning mechanism itself is different. It potentially avoids some of the complexities and instabilities of gradient based methods for these huge RL problems.

Speaker 1

Amazing stuff. Okay, with all this complexity evolving topologies, CPPNs, novelty, coevolution, what are some practical tips for someone listening who actually wants to build or experiment with these systems? Where should they start? What's crucial?

Speaker 2

Rule number one always careful problem analysis and really rigorous data preprocessing. Neuroevolution is pretty robust, but numerical instability can totally derail things. Input data needs attention, especially if different features have vastly different scales, like differing by orders of magnitude. You absolutely need to standardize it zero mean unit variants like with Psychic Learned standard scaler, or scale it to a specific range maybe zero to one using minmax scaler

or normalize it. If you don't, the features with bigger numbers will just dominate the learning process and you'll miss subtle but important signals.

Speaker 1

Got it preprocessing first, and once the data is ready, what about tuning the evolution itself? What are the key dials we can turn right?

Speaker 2

Tuning the evolutionary process? That's critical. Okay, so things seem installed. If fitness isn't improving, maybe try decreasing the need survival threshold. This makes selections stricter, only letting higher quality individuals reproduce. You could also try increasing max stagnation. This gives species more generations to potentially develop useful mutations before being considered stagnant. But maybe start lower like fifteen twenty generations for quicker turnover. Initially,

keep an eye on the number of species. Usually somewhere between five and twenty is a decent range. Too many and they might be too small to evolve effectively. Too few and you might kill off diversity too quickly. Population size is a big one. Larger populations mean more initial diversity, which is good but obviously increases the computational costs per generation. It's a trade off, and please please always put the

random seed value at the start of every run. If you get an interesting result, you absolutely need that seed to replicate the exact evolutionary path later for analysis, for debugging. Super important.

Speaker 1

That's a great practical tip. Okay, beyond just looking at fitness scores going up, are there visual ways to understand what's happening, how the evolution is progressing.

Speaker 2

Oh? Absolutely, visualization is crucial. Don't just look at numbers. Use tools like matt plotlib or seaborn to plot fitness trends over generations. See how the best and average fitness are changing, look at species counts. And it's incredibly valuable to visually inspect the topology of the final evolved an ns, like when tackling that modular red enough problem with the es hyper need. Actually seeing the evolved modular structures in

the network diagram confirms the algorithm worked as intended. It gives you intuition you can't get from numbers alone.

Speaker 1

Right, Seeing is a leading sometimes. And finally, how do you know if your evolved solution is genuinely good? Not just it worked, but how well did it work? What metrics should we look at?

Speaker 2

Yeah, don't just rely on one single success metric like raw fitness or just accuracy, especially for classification tasks. Get familiar with things like precision recall, the F one score ROCAUC that's the receiver operating characteristic area under the curve, and of course overall accuracy. They pain in a much richer picture of performance and for actually implementing this stuff. There are several good Python libraries out there. Neat Python

is stable, well documented. For standard NEED, it's in maintenance mode now maybe a bit slower. Multi Need is probably the most versatile right now. It does need hyper neat es, hyper need, even novelty search. It has a C plus plus cour so what's fast and is decent visualization support. Then there's deep neuroevolution from uber Ai lab built on TensorFlow, specifically for those big DP neural networks on GPUs. Choosing the right one really depends on your specific problem, what

features you need. And one last tip always use isolated virtual Python environments for each project, things like Anaconda or van voked. It saves so many headaches with dependencies.

Speaker 1

What an absolutely incredible journey through neuroevolution, I mean, from mimicking a single neuron to evolving these complex networks that play atary, navigate mazes, even figure out their own learning goals. It's really a testament to the power of looking at the natural world for inspiration to solve some really tough AI problem.

Speaker 2

It trually does redefine how we think about intelligence emerging, doesn't it that core idea the complexity and really optimal solutions can arise not from meticulous, top down design, but from this iterative, messy, nature inspired evolutionary process. It's just profoundly powerful and really challenges us to think differently about building intelligent systems.

Speaker 1

So as we keep pushing the boundaries of AI, it makes you wonder, right, what other unconventional approaches maybe hiding and planesight in biology, might unlock that next level. And how might you, the listener, apply this mindset, this idea of evolving, adapting, maybe even co evolving solutions in your own projects or just in how you approach problem solving generally. If you are eager to dive deeper, we definitely recommend exploring the work from Uber ai labs, checking out the

International Society for Artificial Life that's alife dot org. There are great discussions on open ended evolution on Reddit. The neat Software Catalog list implementations, rxv dot org always has cutting edge papers, and of course go back to the source kenneth O. Stanley's original PhD dissertation on the NEAT algorithm itself. There's always always more to learn.

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android