NAtUrE CaN prOgRAM
Tags: biomimicry, bullettrain, geneticalgorithm
Published: 2019-10-05 18:25:54

My hope is that by the end of this you will believe that nature can program. I had originally picked one topic for this post but I quickly realized that I had gone all over the place. So please join me on this directionless journey.

## Problem Solving
There are many different ways to solve the same problem. But let's talk about the problem solving framework or process in an extremely general sense. The framework below demonstrates an indirect problem solving process.

<img src="https://cdn-images-1.medium.com/max/1600/1*jfP-pQtn1FKicdTv2uwGBg.png"/>

From this we can see that we have a problem, and through analysis we can come up with a representation of a problem. Then, from this representation of a problem we can design a representation of a solution. If we implement then hopefully we will have a working solution!

This seems like a pretty simple process but it holds a lot of power. Because this is so general and abstract we can mix problems and solutions from different fields of study. One field of study in particular is biology or the natural world.

“Nature is the most complex system known to man and it contains countless designs in the form of the biological species and environmental phenomena that make our world unique.”- (( Steven A. Korecki, 2008))

## Biomimicry
“Biomimicry is a maturing science of studying the designs, processes, and phenomena in nature as a source of inspiration for human creations. It acknowledges nature as a model for us to imitate, a measure for us to evaluate our designs, and a mentor from which we can learn.” - ((J. M. Benyus, 2002))

So in a simpler sense, the core idea behind biomimicry is that nature has already come up so solutions or processes for solving problems. Why not apply them to how we engineer things today.

### Let’s look at some examples

<img src="https://miro.medium.com/max/1534/1*L8wzb5KvBD569LXRnSfP6Q.png"/>

In 1989 Japan’s Shinkansen bullet train had a problem. The issue was that it was really fast which is great if you want to get to work on time but bad if you’re coming out of a tunnel. The train would exit the tunnel with a sonic boom which could be heard from 400 meters away. This is bad for dense residential areas. So an engineering team was brought in to design a quieter, faster, and more efficient train. Luckily the general manager of this team, Eiji Nakatsu, was a bird watcher.

Different components of the redesigned bullet train were modeled after different birds.

Owls inspired the pantograph, the rig that connects the train to the electric electric wires above. The new pantograph was modelled after their feathers. Using the same serrations and curvature that allows Owls to catch prey quietly.

<img src="https://miro.medium.com/max/1334/1*pbqRGyqNUQDDWAZaTc3sxQ.png"/>

The Adelie Penguin, whose smooth body allows it to swim effortlessly, inspired the pantographs supporting shaft lowering wind resistance.

<img src="https://miro.medium.com/max/1854/1*VJSPUB_Qi5SzqpVeY2W_AA.png"/>

The kingfisher, whose unique beak shape allows it to catch prey in the water without a splash, inspired the nose of the new train.

<img src="https://miro.medium.com/max/1490/1*ENLVkml1ALafgX649mPtLQ.png"/>

###### Sourced from Vox on YouTube.com https://www.youtube.com/watch?v=iMtXqTmfta0

In the end the engineering team had made a train that was 10% faster, used 15% less energy, and stayed under the noise limit in residential areas.

<img src="https://miro.medium.com/max/1632/1*UKDnG7ZV7u9GUSgrcm9iyQ.png"/>

All information regarding the bullet train was sourced from the Vox Channel
https://www.youtube.com/watch?v=iMtXqTmfta0

## How does this relate to programming?
Much like the engineers of the train used nature to solve their problems, we as programmers can do the same.

### The study of Evolutionary Computing

<img src="https://miro.medium.com/max/886/1*J1Zs2GBdq3NwTf6fVWaugQ.png"/>

### Genetic Algorithms

Genetic algorithms mimic the process of natural selection. Which means that those who adapt best to their environment will survive. Aka survival of the fittest.

#### How they work?
<ul>
<li>Individuals in a population compete for resources and mate</li>
<li>Those individuals who are successful (fittest) then mate to create more offspring than others</li>
<li>Genes from “fittest” parent propagate (trickle down) throughout the generation</li>
<li>Then each successive generation is more suited for their environment</li>
</ul>

#### Genetic Algorithm Example
Let’s say that you’re working in an environment where animals are represented as strings. Let’s call them string animals and the king (fittest) of all strings is the (Representation of the behavior you want to achieve) target = “Puffin”. Each character in the string correlates to a specific trait that that string animal has. Traits can be repeated and the order of the traits matters.

— — — — — — — — — — — — P→ “ Polite ” — — — — — — — — — — — — — —
— — — — — — — — — — — — U→ “ Understanding ” — — — — — — — — — —
— — — — — — — — — — — — F→ “ Fun ” — — — — — — — — — — — — — —
— — — — — — — — — — — — F→ “ Fun ” — — — — — — — — — — — — — —
— — — — — — — — — — — — I→ “ Intelligence ” — — — — — — — — — — —
— — — — — — — — — — — — N→ “ Nice ” — — — — — — — — — — — — — —

All of a sudden the environment changes and the fittest string is no longer the Puffin and it is now the target= “Rabbit”. So the rest of the string animals must evolve into Rabbit’s as well. We can use natural selection modeled by a genetic algorithm to do this.

#### Terms

A Population is a group of string animals.
A Chromosome is a string animal.
A Gene is one letter/characteristic of the string animal

<img src="https://miro.medium.com/max/1446/1*VvCCXnudf3E9DJMIT5I5dA.png"/>

<ol type="1">
  <li>Selection Operator</li>
  <p>The fittest (best fitness score) individuals are selected to pass on their genes. So our string animals will get a ranking based on how close they are to matching the exact string of “Rabbit”. The best will be selected.</p>
  <li>Crossover Operator</li>
  <p>Mating happens. Two string animals are chosen and chunks, crossover points, or sub-strings are randomly selected. The selected chunks will recombine into a new string animal child.</p>
  <li>Mutation Operator</li>
  <p>Random genes are inserted. Nature has randomness. We want this randomness to maintain genetic diversity among all the string animals.
</p>
</ol>

<img src="https://miro.medium.com/max/1448/1*yGPWdPhbnAEMMGZFW98fSQ.png"/>
<img src="https://miro.medium.com/max/788/1*h3cYOrwq1VCENjxJvxy6hQ.png"/>

#### Algorithm Summary

<ol type="1">
  <li>Randomly initialize population</li>
  <li>Determine fitness of population</li>
  <li>Until convergence (isRabbit?) repeat:</li>
  <ol type="A">
    <li>Select parents from population</li>
    <li>Crossover and generate new population</li>
    <li>Perform mutation on new population</li>
    <li>Calculate fitness for new population</li>
  </ol>
</ol>

You may be thinking “what a stupid way to change a string”. This is true, but we didn’t change the string. We modeled a process that generates a string based on a target.

#### Genetic Algorithm Usage

Copies image to its left

<img src="https://miro.medium.com/max/1406/1*tIilUkCrEN5ooo2BYWjs_w.png"/>
<img src="https://miro.medium.com/max/1400/1*Tzu3KyynpnyvKX5_gP2Bwg.png"/>
<img src="https://miro.medium.com/max/1394/1*SYjsL0stjAPY11XVIMBQbQ.png"/>

You can watch a video about this project on Cody Husky on YouTube.
https://www.youtube.com/watch?v=Q-CDOHkQWBw

Here is another one where someone used evolution to drive a car in unity
https://www.youtube.com/watch?v=FKbarpAlBkw&t=196s

So while nature can’t pick up a computer and start programming. We as programmers can and have taken inspiration from nature to solve problems.

### References

https://scholarworks.gvsu.edu/cistechlib/?utm_source=scholarworks.gvsu.edu%2Fcistechlib%2F44&utm_medium=PDF&utm_campaign=PDFCoverPages

https://www.geeksforgeeks.org/genetic-algorithms/?source=post_page-----cb393da0e67d----------------------

https://biomimicry.org/?source=post_page-----cb393da0e67d----------------------