[AI]: Neural Network and Genetic Algorithm test

I love it!

Long time ago i played with a program called creature evolution, you could set the initial properties and parts of the creature, and then set the goal (Run fast, be tall). I’d love to see this evolving on blender.

The genetic algorythm, does it apply forces?

If so what “seeds” does it use?
9.8*own.mass is a good random rule piece,

I am talking about randomly populating a motion actuator in each limb.

no pre-defined/pre-coded motion is enter here. Torque is applyed by the neural network ( artificial brain ) on each parts of the body they want to move.
They learn all motion by themself , without humain intervention. Without this brain , the setup is just a ragdoll.

Well, can you make it so it can possibly infer gravity and its balence by creating a motion sensor, and a balance sensor, and give it the inputs, but no pre defined rules?

Give it sensor input with the ability to use the change in input to populate its own forces?

Gene 1 Random number or random sensor input or offset
gene 2 = random expression (+, -, *, divided by, power <, >)
Gene 3 random sensor input or random number input or offset

Gene 4 random expression or if empty no gene 5

Gene 5 random number or random sensor offset, or input.

People seem to fire randomly, and have input respones from thr firing, and adjust their firing to adjust the input.

Right now just standing and walking is your goal,

Later I would use

Find property water and collide
Find property food and collide
Find property Friends (other ai) and stay within x distance for x time.

Etc.
And any rule that meets a conditions genes can then be modified to increase % of times it achieves that goal?

Man, wish I had enough time to try NN/GA.
Nice Work Pyroevil.

@Blueprint:
I’m not sure you understand the point of a Genetic Algorithm/Neural Network. I’m not sure I understand them exactly either, but…
The aim is to have virtually nothing pre-defined, and to have nothing controlled randomly. The aim is to have the AI ‘learn’ it’s own way of doing things by trial and error.
So instead of having it fire a weapon randomly (still not sure why we’re bringing weapons into this), you’d instead give it the ability to fire a weapon, and the computer would eventually figure out how to use it IF it offered some advantage to it’s goal.

That is what I am talking about, however,

input- sensors
Evaluate
Randomly make rules
apply forces generated by rules
evaluate
Store gene or remove gene

This way, it could infer gravity, and counter act it or ???
just giving it the ability to collect data, and then use the data to apply to generated rules…

A brain, without inputs might as well be a turnip.

there is a reason EVERY living thing that thinks, has input.

Z axis * 9.8 * Mass = counter gravity

I would not give it this rule, rather give it the ability to infer it with sensor input Vs attempt

think about the fact that your ear is accelerometer, and your eyes are rays with shape recognition, that take time and firing to setup…

Neural networks and genetic algoithm in a game would be good idea.
One that could learn the fighting tactics of the players in multiplayer and adapt.You could have a singal player campaign that would mix dumb ai with smart ai randomly.

So generate rule, test rule, assign value, if value < X delete gene

Are you thinking about incoporating this into Wrectified?

Not sure what you mean exactly , but here is some explanation I try to give about the system:

“Neural Network have a series of inputs , ouputs and between them “hidden neurons”. Each inputs is linked to all hidden neurons and hidden neurons to ouput. All this links is multplied by a weights, So when you insert value in the input , you get value come out the output and the output result depends of the values of all weights ( a bit more complex than that but it’s the idea). So if you want a precise output results , you need to find the right value for all weights. Is impossible to do by hand for a walking characters or probably difficult for AI like the pacman or balancing pole videos. So is where the genetic algorythm come in the equation. All weights a set randomly at the generation 0 and walker try to go far away that they can with this value ( just falling for major case in generation 0). I attribute some score to the walker directly attributed by the distance he make. Genetic algorithm choose two mates to be reproduce by a “roulette wheel” , where highest score walker have more chance to be selected then lowest one. But lowest one have a bit of chance to , it’s help to keep genetic diversity and avoiding to get your evolution stock to a “local maxima”.So reproduction exchange there genetic data ( here the weights ) to get the next generation. Ounce the next generation is created , a small chance of mutation is apply on there weights and is ready to be tested again ( try if the new value can go more far then the last generation ).”

So “rule” is just about how you give score to your walker. If you want it standin , just give points each frame he stay on is feet. Deleting Gene is not a good idea , you want to keep diversity. The big problem in machine learning it’s seam to be call “local maxima”. It’s when your system go to fast in a way of evolution ( thinking is the best ) and hit a ceiling. Because is go too far in this direction , it’s not be able too come back and try somethings else and finding a solution closer to the “global maxima”. “global maxima” is the ultimate answer to the solution. “local maxima” in a kind of " not bad solution". It’s a bit complex and I’m really not a expert of this. I just did this for fun , but this kind problem is the challenge of many Phd in this subject.This people that give all is time to this to find better solution. And they do not understand everythings from this kind of technology , so imagine me :slight_smile: . Just check this paper :

http://www.staff.science.uu.nl/~geijt101/thesis/index.html

I wrote to this guy yesterday and he give me some tips , some of those are nice and I’m working on this … some just get over of my understanding of mathematics ( my understandin is low ). Like he suggest me to use CMA-ES algorithm instead of Genetic Algorithm … it’s a bit faster … yes but for me it’s just impossible to understand that math. So I stay with Genetic. I just want to have fun , not to get a headache everyday day and get blood pouring from my ears and eyes :wink:

For now my big issues when I trying a new challenge to solve with my NN/GAs algo , is not about the code of the core , I not touching it alot , it’s about which inputs your “players” to give you the right output “you want” ( put it in quote because you don’t really control what you want because it’s learn and decid by itself ) and finding the right way to them points for it’s score.

It’s like training a dog to sit. You have to give him some input ( by saying the words “sit” , make a move with your hand … etc ) and give him threat when he do what you want. Not always easy that it’s look like and it’s can give diffirent result on each dog you try to train. But if you use same technics on all dogs (same inputs and treats) , you probably get all dog be able to sit , but all differently … with is own personnality. Same things here.

For the tank example : https://www.youtube.com/watch?v=8_q2aGMTgsc

I give the following 4 inputs ( all inputs need to be normalized, so between -1 and 1) :

  • 2D normalized vector of the direction of himself (X an Y)
  • 2D normalized vector of the direction of the nearest yellow dot (X and Y)

And I give them 1 points everytime they catch a yellow dot. That’s it , no more info , they learn themself how to catch yellow dot progressivly. After you train it and get the result you want , you can save is genetic and you it in a game to avoid to train it from the beginning each time. And probably continu to learn depends on the players move.

Do you use pybrain?

No , I code my own algorithm in C using Cython. PyBrain not have Genetic Algorithm integrated I think ( and need SciPy library ). Deap seam to be a good library too ( but need Numpy and others library ). But all my fun here is to code my own things :slight_smile:

I don’t know how hard is to integrate python library with the internal python in Blender.

I need to get around to using c,
I have a few things I want to do in C but have hohnestly never even looked at C since quake 1,

You ever look at the Bullet linking to the bge?
I would like to get a rigid body joint actuator logic brick,
This would expose all the properties of the constraint to be acceasable via python, rather then only having the ability to set, and not recall,

Like actu.target
Actu.limits etc

This would make many things easier…

Try Cython , it’s a fast and easy way to code C module extension for python.
Yes , for now I create and control all constraint via python , I don’t know directly about bullet integration in Blender.

I saw your video on youtube and want to know if I can apply your idea as solution for the following problem below…

https://blender.stackexchange.com/questions/168724/how-to-make-a-3d-model-move-using-ai-nn

Thanks!

Wow this really brought me back. Not sure why it showed at the top of the WIP section for me though :thinking:
I wonder if I’ve got the skills to create those walkers now.