**Created:** 28th October in 2024 **Medium:** [[Generative]] [[Visual]] [[Daily Practice]] **Recource:** [Nature of Code](https://natureofcode.com/genetic-algorithms/) - -- # System Simulation – Genetic Algorithm *Need to make it work:* ### Heredity ### Variation ### Selection - -- 1. Calculate fitness of N elements 2. Reproduction / Selection *(run n times)* 1. Pick *2* "parents" (using fitness score as probability of picking the element) 2. Make a new *element* 1. CROSSOVER 2. MUTATION (f.e. 1% mutation rate –> keeps variation in the system) - fitness function - how to encode you DNA - GENOTYPE x PHENOTYPE - -- <div class="iframe-wrapper"> <iframe id="RefreshMe" src=" https://editor.p5js.org/kindl.work/full/eexhGrN91 " scrolling="no" allow="camera; microphone"></iframe> </div> - -- <div class="iframe-wrapper"> <iframe id="RefreshMe" src=" https://editor.p5js.org/kindl.work/full/Dh_qLSlsT " scrolling="no" allow=""></iframe> </div> - -- - **Heredity:** There must be a mechanism that allows _parent_ creatures in one generation to pass their traits down to _child_ creatures in the next generation. - **Variation:** There must be a variety of traits present in the population of creatures or a means to introduce variation for evolution to take place. Imagine a population of beetles that were exactly the same: same color, same size, same wingspan, same everything. Without any variety in the population, the children would always be identical to the parents and to each other. New combinations of traits could never occur, and nothing could evolve. - **Selection:** There must be a mechanism by which some creatures have the opportunity to be parents and pass on their genetic information, while others don’t. This is commonly referred to as _survival of the fittest_. Take, for example, a population of gazelles that are chased by lions. The faster gazelles have a better chance of escaping the lions, increasing their chances of living longer, reproducing, and passing on their genetic information to offspring. The term _fittest_ can be misleading, however. It’s often thought to mean biggest, fastest, or strongest, but while it can sometimes encompass physical attributes like size, speed, or strength, it doesn’t have to. The core of natural selection lies in whatever traits best suit an organism’s environment and increase its likelihood of survival and ultimately reproduction. Instead of asserting superiority, _fittest_ can be better understood as “able to reproduce.” Take the _Dolania americana_ (aka the American sand-burrowing mayfly), which is believed to have the shortest life span of any insect. An adult female lives for only five minutes, but as long as it has managed to deposit its egg in the water, it will pass its genetic information to the next generation. For the typing cats, a more _fit_ cat, one that I will assign as more likely to reproduce, is one that has typed more characters present in a given phrase of Shakespeare.