DEV Community

loading...

NAtUrE CaN prOgRAM

Chet Chopra
I like to tinker
・5 min read

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.

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

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.

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

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

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.

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

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?

  • Individuals in a population compete for resources and mate
  • Those individuals who are successful (fittest) then mate to create more offspring than others
  • Genes from “fittest” parent propagate (trickle down) throughout the generation
  • Then each successive generation is more suited for their environment

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

  1. Selection Operator
  2. 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.

  3. Crossover Operator
  4. 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.

  5. Mutation Operator
  6. Random genes are inserted. Nature has randomness. We want this randomness to maintain genetic diversity among all the string animals.


Algorithm Summary

  1. Randomly initialize population
  2. Determine fitness of population
  3. Until convergence (isRabbit?) repeat:
    1. Select parents from population
    2. Crossover and generate new population
    3. Perform mutation on new population
    4. Calculate fitness for new population

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



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----------------------

Discussion (0)