Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * * 4 votes

Goopies - Evolving neural networks (w.i.p.)


  • Please log in to reply
135 replies to this topic

#1 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 29 October 2012 - 10:20 AM

Hey guys. This is my first post on the forum! And on it, I wish to share my newest invention:

GOOPIES

After reading the post by Darren Cubitt about his Neural Bots experiment (http://www.atheistne...source=activity) I couldn't help to "extend" his original idea and give it my own little twist. So far, this has been the result.

Goopies are little bi-dimensional creatures that live on a closed circular world called "The Tank." Each of them has a set of sensors and is powered by a Neural Network (http://en.wikipedia..../Neural_network), a little piece of software that allows them to respond intelligently to their environment.

A genetic algorithm (http://en.wikipedia....netic_algorithm) is then used to select the best individuals of each generation. Their virtual "genes" are then mixed and crossed in order to produce a new generation. Over many iterations, the population's performance improves over time.

If you want, you can see them in action here:
http://www.youtube.com/watch?v=tCPzYM7B338

I plan on releasing a beta version of the software for anyone to test and play with once I have implemented a simple GUI that allows users to adjust basic parameters of the simulation (Neural Network style, population size, colors, etc.). Perhaps I'll even implement some kind of Goopy-Tournament mode, so people can have fun making their Goopies compete against each other, who knows.

/////////////////////////////////////////////

This is my first coding project (ever!). Coded in C++11 and compiled using GCC 4.7 (http://gcc.gnu.org/). Credits to SFML (http://www.sfml-dev.org/) for the graphic's engine and Box2D (http://box2d.org/) for the physics engine. And, of course, thanks to Darren for his original idea, which inspired me to make this.
  • 2

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 29 October 2012 - 11:28 AM

Looks interesting! What platforms will you be releasing it on?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 29 October 2012 - 02:41 PM

Looks interesting! What platforms will you be releasing it on?


Code and libraries are portable. I will release it for Windows and Linux first because those are the OS's I currently have access to (thus, where I can test the program in). I don't know about a future Mac release (or even a release for mobile devices), but hey, I don't discard the possibility!
  • 0

#4 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 30 October 2012 - 07:03 AM

This would be great perpetually running on my 2nd monitor here at work. Sure beats goldfish.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 30 October 2012 - 03:05 PM

This would be great perpetually running on my 2nd monitor here at work. Sure beats goldfish.


Perhaps I could turn it into a screen-saver. ;)
  • 0

#6 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts
  • Location:Cedar Rapids, IA
  • Programming Language:Java
  • Learning:C, Java, C++, C#, Python, JavaScript, Assembly

Posted 31 October 2012 - 12:16 PM

This is a very interesting project. I'm now inspired to write something similar myself now :)
  • 0
Speaks fluent Java

#7 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 31 October 2012 - 04:12 PM

This is a very interesting project. I'm now inspired to write something similar myself now :)


Hey, I'm glad!
Let me know if you do. It'd be fun and interesting to compare the results. :)
  • 0

#8 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts
  • Location:Cedar Rapids, IA
  • Programming Language:Java
  • Learning:C, Java, C++, C#, Python, JavaScript, Assembly

Posted 01 November 2012 - 01:18 PM

Hey, I'm glad!
Let me know if you do. It'd be fun and interesting to compare the results. :)

Alright, I'll be making it in Java, and I won't be using a graphics engine, so the graphics won't be up to par with yours. I'll have it done in about a week or two, considering school.
  • 0
Speaks fluent Java

#9 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 01 November 2012 - 02:01 PM


Hey, I'm glad!
Let me know if you do. It'd be fun and interesting to compare the results. :)

Alright, I'll be making it in Java, and I won't be using a graphics engine, so the graphics won't be up to par with yours. I'll have it done in about a week or two, considering school.


Awesome, Chall, let me know how it goes!
What kind of virtual creatures do you aim to evolve?
  • 0

#10 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts
  • Location:Cedar Rapids, IA
  • Programming Language:Java
  • Learning:C, Java, C++, C#, Python, JavaScript, Assembly

Posted 01 November 2012 - 02:33 PM



Hey, I'm glad!
Let me know if you do. It'd be fun and interesting to compare the results. :)

Alright, I'll be making it in Java, and I won't be using a graphics engine, so the graphics won't be up to par with yours. I'll have it done in about a week or two, considering school.


Awesome, Chall, let me know how it goes!
What kind of virtual creatures do you aim to evolve?


Well, umm.... Micro-organisms. I'm not aiming for anything more complex than advanced genetic inheritance and possibly the ability to socialize with other organisms (Would need to add aspects to the environment for this to be useful and eventually obtainable).

Currently, my idea is going to handle the organism like an OS Kernel, and the Gene(s) are going to be x-dimensional arrays contained in a MocDNA class, and each index of the Gene refers to the index of the desired Neuron to pass the rest of the information on to. The Genetic code is going to be more like a set of instructions, the start of a MocDNA strand will tell the new Neurons constructor how to set up the neural network (How many neurons, indexes of Input/output neurons, types (memory, utility, output, input), and the rest is instructions that will be called upon by index depending on the information recieved by the input neurons.

I'm going to continue the idea of using 2 "booster" jets on the organism for movement, and each jet will correspond to an individual output neuron that tells it how fast, how long, etc. The eyes are going to be difficult. I had an idea of using a basic method of using multiple "lines" that extended from the "eyes", and based on what colors the object that fall inside those lines are is what it "sees".

Once the eyes recieve data, they locate a certain gene by using an "index card" contained in the input neuron, which tells it the index of the gene to use, and the first index of that gene is the neuron to send the rest of the gene to.

Once the recieving neuron recieves that data, it can then modify the data based on current conditions (health, food, position, speed), and then proceed to send it to the next neuron that the gene reffers to, or just send it automatically withod modification.

By the end of this long chain, it will either have reached a memory neuron, an output neuron, or absolutely nowhere.

If it's a memory neuron, it stores the information in the impulse for later use. If the neuron was an output neuron, it then uses the data to move. If it was nowhere, nothing happens. After the impulse is reacted upon, if there are still indexes left in the gene, it will continue to process that impulse until it either reaches an end point, or the gene runs out of indexes.

The gene itself is nothing but instructions to indexes of neurons. The real signal is the impulse.
When 2 organisms collide, if they have enough food or energy to supply a new organism with life, they will create a new organism by mixing their MocDNA together, and creating a new organism using the new MocDNA. While mixing, if the information is not crucial (There are predefined neuron indexes which cannot be modified, as they refer to either input or output neurons), then it will randomly select an index out of thin air (actually the maximum neurons the new organism is going to have).

I thought all of this out in my Biology class today, so it's still got some work left, but I think it will be a fun project. :)

Current neuron/gene build specs:
/* Catalogue of Predefined Indexes
  * 0: Contains amount of cells in neural network
  * 1: RBooster
  * 2: LBooster
  * 3: REye
  * 4: LEye
  * 5: Memory
  * 6: Memory
  * 7: Memory
  * 8: Memory
  * 9: Memory
  * 10: Memory
  * 11: Modify based on Health
  * 12: Modify based on Hunger
  * 13 - 13+[0]: Network layout
  * +60: 30(10 red, 10 blue, 10 green, left), 30(10 red, 10 blue, 10 green, right)
  *
  * Neuron types and data requirements for generation
  * OutputNeuron (0): [0][direction(0 or 1)]
  * InputNeuron (1): [1][color(0-red; 1-blue; 2-green)]
  * MainInputNeuron (2): [2][side(0-left; 1-right)]
  * MemoryNeuron (3): [3][?]
  * ModificationNeuron (4): [4][0-+; 1--; 2-*; 3-/][Index of MemoryNeuron to use] // Check to make sure valid mem index?
  * BasicNeuron (5-infinity): [5] ?
  */

  • 0
Speaks fluent Java

#11 nino

nino

    CC Resident

  • Validating
  • PipPipPipPip
  • 66 posts
  • Programming Language:C, C++, PHP, Python, JavaScript

Posted 02 November 2012 - 02:40 AM




Hey, I'm glad!
Let me know if you do. It'd be fun and interesting to compare the results. :)

Alright, I'll be making it in Java, and I won't be using a graphics engine, so the graphics won't be up to par with yours. I'll have it done in about a week or two, considering school.


Awesome, Chall, let me know how it goes!
What kind of virtual creatures do you aim to evolve?


Well, umm.... Micro-organisms. I'm not aiming for anything more complex than advanced genetic inheritance and possibly the ability to socialize with other organisms (Would need to add aspects to the environment for this to be useful and eventually obtainable).

Currently, my idea is going to handle the organism like an OS Kernel, and the Gene(s) are going to be x-dimensional arrays contained in a MocDNA class, and each index of the Gene refers to the index of the desired Neuron to pass the rest of the information on to. The Genetic code is going to be more like a set of instructions, the start of a MocDNA strand will tell the new Neurons constructor how to set up the neural network (How many neurons, indexes of Input/output neurons, types (memory, utility, output, input), and the rest is instructions that will be called upon by index depending on the information recieved by the input neurons.

I'm going to continue the idea of using 2 "booster" jets on the organism for movement, and each jet will correspond to an individual output neuron that tells it how fast, how long, etc. The eyes are going to be difficult. I had an idea of using a basic method of using multiple "lines" that extended from the "eyes", and based on what colors the object that fall inside those lines are is what it "sees".

Once the eyes recieve data, they locate a certain gene by using an "index card" contained in the input neuron, which tells it the index of the gene to use, and the first index of that gene is the neuron to send the rest of the gene to.

Once the recieving neuron recieves that data, it can then modify the data based on current conditions (health, food, position, speed), and then proceed to send it to the next neuron that the gene reffers to, or just send it automatically withod modification.

By the end of this long chain, it will either have reached a memory neuron, an output neuron, or absolutely nowhere.

If it's a memory neuron, it stores the information in the impulse for later use. If the neuron was an output neuron, it then uses the data to move. If it was nowhere, nothing happens. After the impulse is reacted upon, if there are still indexes left in the gene, it will continue to process that impulse until it either reaches an end point, or the gene runs out of indexes.

The gene itself is nothing but instructions to indexes of neurons. The real signal is the impulse.
When 2 organisms collide, if they have enough food or energy to supply a new organism with life, they will create a new organism by mixing their MocDNA together, and creating a new organism using the new MocDNA. While mixing, if the information is not crucial (There are predefined neuron indexes which cannot be modified, as they refer to either input or output neurons), then it will randomly select an index out of thin air (actually the maximum neurons the new organism is going to have).

I thought all of this out in my Biology class today, so it's still got some work left, but I think it will be a fun project. :)

Current neuron/gene build specs:
/* Catalogue of Predefined Indexes
* 0: Contains amount of cells in neural network
* 1: RBooster
* 2: LBooster
* 3: REye
* 4: LEye
* 5: Memory
* 6: Memory
* 7: Memory
* 8: Memory
* 9: Memory
* 10: Memory
* 11: Modify based on Health
* 12: Modify based on Hunger
* 13 - 13+[0]: Network layout
* +60: 30(10 red, 10 blue, 10 green, left), 30(10 red, 10 blue, 10 green, right)
*
* Neuron types and data requirements for generation
* OutputNeuron (0): [0][direction(0 or 1)]
* InputNeuron (1): [1][color(0-red; 1-blue; 2-green)]
* MainInputNeuron (2): [2][side(0-left; 1-right)]
* MemoryNeuron (3): [3][?]
* ModificationNeuron (4): [4][0-+; 1--; 2-*; 3-/][Index of MemoryNeuron to use] // Check to make sure valid mem index?
* BasicNeuron (5-infinity): [5] ?
*/


Woah Chall, I must admit, your approach seems quite more elaborate and illustrious than mine! :biggrin:
It's almost like a mix between ordinary Neural Network functionality and what Tierra (http://en.wikipedia....ter_simulation)) does for artificial evolution. Your critters' DNA is actually composed of Instructions, thus, your critters acting more like independent Programs. I wonder, what type of Genetic Algorithm do you plan on using for your creatures to evolve towards better adapted models?

In my simulation I kept it more simple: all critters have a fixed Neural Network topology and the only thing that "evolves" is the connection weights between synapses. Thus, we can think of their virtual brains as (complex, polynomial) "functions" defined in their "genes". The GA just needs to worry about finding the most optimal function model to ensure the creature's survival. I wonder if, in your approach, you will consider some form of mutability inside the individual neurons (weights, biases, activation function, etc.) besides the main "topological" approach that you mention?

I'm excited to see what you come up to!
  • 0

#12 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts
  • Location:Cedar Rapids, IA
  • Programming Language:Java
  • Learning:C, Java, C++, C#, Python, JavaScript, Assembly

Posted 02 November 2012 - 06:12 PM

Woah Chall, I must admit, your approach seems quite more elaborate and illustrious than mine! :biggrin:
It's almost like a mix between ordinary Neural Network functionality and what Tierra (http://en.wikipedia....ter_simulation)) does for artificial evolution. Your critters' DNA is actually composed of Instructions, thus, your critters acting more like independent Programs. I wonder, what type of Genetic Algorithm do you plan on using for your creatures to evolve towards better adapted models?

In my simulation I kept it more simple: all critters have a fixed Neural Network topology and the only thing that "evolves" is the connection weights between synapses. Thus, we can think of their virtual brains as (complex, polynomial) "functions" defined in their "genes". The GA just needs to worry about finding the most optimal function model to ensure the creature's survival. I wonder if, in your approach, you will consider some form of mutability inside the individual neurons (weights, biases, activation function, etc.) besides the main "topological" approach that you mention?

I'm excited to see what you come up to!


Alright, first input "gene" (red, left eye). Loads the memory neurons designated for the left eye's red:
{67, 6, 0, 68, 7, 0, 69, 8, 0, 70, 9, 0, 71, 10, 0, 72, 11, 0, 73, 12, 0, 74, 13, 0, 75, 14, 0, 76, 15, 0, 77, 16, 0};
The first digit specifies which input neuron and loads it into impulse's "stack", second digit specifies which memory neuron, and third specifies which operation (0 is store) and it stores the first value on the impulse's "stack", which would be the distance of the color that that neuron is seeing. The cycle then repeats, and will continue to do so until the gene runs out of indexes/operations.

If a gene needs access to a memory neuron, all it needs is the index of cell, and the operation 1, which loads onto impulse stack. So, if I wanted to access the distance of red at the first input neuron, it would look like this:
{..., 6, 1,...};

I also decided that since I'm more interested in the genes, and natural selection based on genes, I should focus less on the neurons, and more on gene optimization, so when a new organism is created, it will combine parent genes, and then modify/add existing/new ones. I know it's more like a very basic assembly language than genetics, but that's also pretty much what genetics are, instructions for the body. Same principal applies in my case too :) I'm ecstatic to see how my project turns out.

And I'm not using weights just because I can't get an exact definition of what the weight is supposed to do exactly. :S
  • 0
Speaks fluent Java




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download