Skip to content

leobrod44/Natural_Selection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 

Repository files navigation

Natural Selection Simulator with Genetic Algorithms and Neural Networks

Summary

Procedurally generated biomes, creatures, and neural networks for real-time decision-making. Genetic algorithms and neural networks are used to evolve behavior and gauge environment adaptation through selective reproduction.

Example

Parameters: Batch per generation: 5, Size of each batch: 40, Selection Count: top 12, Inner layers: 2, Neuron per inner layer: 5, Sensor neurons: 4, Output neurons: 3

NS.sim.-.Made.with.Clipchamp.2.mp4

Performance

This simulation uses the Unity game engine but bypasses all physics engines for movement and collision detections and instead uses matrices storing locations of important objects to determine where to move or where each object is stored. Movement is then simulated by performing small teleportations to the nearest desired tile.

This allows maximized training speed since each input value is fed to each NN and their outcome relies solely on local CPU processing power and RAM, maximizing training throughput.

The example's 1x speed demonstrates this speed.

Biome generation

Natural habitat generation

-Spawning tiles that can have various properties and contain elements such as food, obstacles, water and trees. Lakes tiles spawned recursively.Engine.cs and Area.cs

medium nature density low nature density high nature density
Screenshot 2023-01-16 154057 Screenshot 2023-01-16 154248 Screenshot 2023-01-16 154337

Creature generation

  • Eventually, more complex character will be generated. For now, random sized and colored cubic animals with randomly generated latin names. Current implementation Body.cs. The animal's character control will happen through Animal.cs
Sulyha Sotaenis Maejubis Gijolis Qeshusis Raso & Pebyshaho Haeqisheqa
Capture Screenshot 2023-01-16 154742 Screenshot 2023-01-16 155040

Neural Network

This approach to reinforcement learning borrows common NN characteristics such as the input, inner layers and output neurons, each interconnected through weights and having their value tweaked by a bias. However, instead of employing traditional backpropagation for optimization, genetic algorithms are used. Across generations, this algorithm selects top performers of each batch to gradually narrow down weights and biases to their optimal value, aiming to discover an optimal solution to surviving the longest.

Each individual in a population has a unique neural network generated. Either completely random on the initial population or based on a combination from a previous population

Activation Function: Hyperbolic Tangent Activation

image

Genetic Algorithm Design

Fitness Function

How each individual's performance is evaluated image

Crossover Function

How each subsequent generation is generated based on the previous image

Selection

The generation is sorted by descending order according to each indiviuals fitness. The top n individuals are selected to reproduce and produce the next generation

Persistence

Each Neural Network can be stored as a list of hexadecimals each representing a connection. This can allow for optimzed brain files to be stored and reuploaded

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages