Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Artificial intelligence that evolves in Python [closed]

So I've been thinking of creating a program similar to this in Python. The problem is that I know next to nothing about AI. Right now I'm reading up on genetic algorithms and neural networks and such, but there's a lot of things to absorb.

My largest problem now is I don't know how the entire thing is put together. So if anyone can tell me the general framework for a program like this, I'll be really grateful. For example, how the creatures can "see" things in their surroundings, the kind of "chromosomes" they have and how the environment is created.

Also, can anyone suggest suitable libraries for AIs, any engines, etc? I've been thinking of using neurolab, will that be a good idea?

Thanks!

like image 788
user1689935 Avatar asked Nov 18 '12 16:11

user1689935


People also ask

Can Python do artificial intelligence?

Python has proven to be one of the most efficient programming languages for AI and ML solutions. The technology transformation of AI can help in providing better outputs.

What are the 4 types of artificial intelligence?

There are a lot of ongoing discoveries and developments, most of which are divided into four categories: reactive machines, limited memory, theory of mind, and self-aware AI.

What is the latest breakthrough in AI?

Mimicking Life: Breakthrough in Non-Living Materials Nov. 10, 2022 — Researchers have discovered a new process that uses fuel to control non-living materials, similar to what living cells do. The reaction cycle can easily be applied to a wide range of materials and ...


2 Answers

Interestingly, I've created what you're describing, in Python.

Here's a pic:

enter image description here

The green dots are food, and the red ones are organisms that need to evolve and learn how to eat the food blocks.

The best source of inspiration and guidance for something like this is definitely Polyworld: youtube.com/watch?v=_m97_kL4ox0.

Another great example which helped me learn about backpropagation, which I suggest you should learn too, is here: arctrix.com/nas/python/bpnn.py.

Although this question is simply too vague to answer correctly, the general tip is that you first get a solid ground on how ANN's function, and then construct a program with this general algorithm:

  • Check for user input (should the camera move? should the program quit?)
  • For each organism:
    1. Check if it is alive, etc.
    2. Take input from the world
    3. Evaluate its neural network
    4. Apply the results to the physical body
    5. Apply positive or negative feedback (as you'll see, it all comes down to this)
  • Update the world (you can use a physics engine)
  • Optionally, draw the world

For example, your input neurons could correspond with physical or visual stimulation. Is there something in front of me? Then set neuron X to 1, otherwise to 0.

And your output neurons could map into forces. Is neuron Y active? If so, apply an impulse to this organism's in this world cycle.

I also recommend that you don't use other people's libraries for your neural network computation, because this is a great way to actually learn how to implement them yourself. You could you Pygame for rendering, and PyBox2D for physics, though.

Now, about "seeing" other organisms... These problems are best solved when isolated. You need a good software design, that will enable you to divide the whole problem into many subproblems, which are easier to solve.

In general, seeing can be done by raycasting. Create a directional, normalized vector (where the length is 1 unit, that is, sqrt(x*x + y*y) == 1), and then scale it (x *= factor; y *= factor;). That way, you get a line that's stretching outwards. Before you scale it, you can then loop through all of the organisms in the world (you'll have to optimize this), and check if the vector is inside of them. If it is, calculate its length, and your organism has some information about its surroundings.

There are many simpler ways. For example, divide space around each organism into four quadrants, which four represent eyes (X - up, right, down, left of the organism). Then calculate the length from the organism to every other organism (optimize!). Find the closest organism. Find out in which quadrant it is. Voila, an active eye!

I hope I was helpful, but you'll have to be more precise and come back when you have an actual problem. Read the FAQ as well.

like image 187
corazza Avatar answered Sep 21 '22 15:09

corazza


http://scikit-learn.org/ is a great resource (and framework) for you to learn about machine learning in python.

If you want to build a neural network, http://pybrain.org/ is a good framework.

like image 20
Calvin Cheng Avatar answered Sep 20 '22 15:09

Calvin Cheng