HOME | DD

Published: 2008-04-13 15:46:00 +0000 UTC; Views: 2609; Favourites: 15; Downloads: 44
Redirect to original
Description
So in this semester I have Artificial Intelligance discipline at uni. And we have few home works there.I think that it may be interesting for some of you people so posted result of first home work.
It is about genetic algorithms.
Info on genetic algorithms
[link] - read here for better info. In short GA is one of not many ways of optimizing/searching something in field that is hard to formalize. For example if you know the function in which you look for minimal value you could use mathematics to try and solve that task. But for that you should have a very good knowledge in math and task should have appropriate mathematical representation. But in realty many tasks and problems often don’t have correct mathematical representation or representation is too hard for math to solve. So here GA helps. Thing is that principles in it allow it to find solutions in any sphere and task. Though it comes at a price of time and uncertainty. For example you can’t be 100% shore when to stop the algorithm.
Idea is simple. You usually can represent solutions as some number sequence. Then you can create criteria to judge solutions based on how good they are. Using those things you make an algorithm that creates populations of random solutions and starts an evolutionary process in which solutions compete/reproduce/mutate trying to be judged better.
Aims
So I changed the task a little so that result would be more representable.
This program receives a graph and then tries to find best mapping of graph nodes to 25x25 grid so that number of collision among edges of graph would be minimal. In some way you may say that it should untangle the graph
Explanations on interface
You can input a graph matrix in to the GraphString box and hit restart. Then algorithm will rebuild inner matrix and start looking solutions for it. String represents squired oriented incidence matrix of 0/1. Each number says if route from x node to y node exists. By default a graph of 25 nodes with that are connected in a circle is imputed.
So that means that each creature is represented by array of mapping coordinates for each node in the graph. For 3 noded triangle graphs matrix will be:
010
001
100
and creature will be:
[[0,0],[25,25],[0,25]]
You can choose one of items in generation list to see actual graph. By default after each calculation it chooses best creature to show. Sometimes you will need to click few times before it selects a creature. Thing is that algorithm runs in parallel to interface and list does not catch some of the clicks
Then there are options on parameters of algorithm:
Population size: how many creatures are created.
% of survivors: - sets % of population that is chosen are representatives that fit for reproduction. Say that with population of 100 and survivors of 50% it will chose 50 creatures and will create 50 more children from them. Children I made by choosing random pair of creatures and then creating new one with characteristics randomly taken from parents.
% of mutations: % of creatures that will be chosen for mutation.
% of effect: % of characteristics of creatures that will be randomly changed in mutation process.
Seems like that’s all. Usually somewhere in 200 generations it untangles the initial graph. Though it depends on luck.
Edit: Added start/stop button and fixed one bug.
Related content
Comments: 43
wonderwhy-ER In reply to TurboFerret [2008-04-16 12:35:19 +0000 UTC]
Nee. Software Engineering. Nu latviski bus kaut Pogramas istrada6ana vai kaut kas
👍: 0 ⏩: 1
TurboFerret In reply to wonderwhy-ER [2008-04-16 13:47:10 +0000 UTC]
Hm, jā jā , man vari netulkot Bet tas ir ekzaktajos?
👍: 0 ⏩: 1
wonderwhy-ER In reply to TurboFerret [2008-04-16 15:12:04 +0000 UTC]
Eee. KAs nozime 'ekzaktajos'?
👍: 0 ⏩: 1
wonderwhy-ER In reply to TurboFerret [2008-04-16 21:39:54 +0000 UTC]
Ne Vistuvaki vardi pie 'ekzaktajos' ir 'exact' angliski un 'ekzamens' latviski... Patie6am nezinu kas tas var nozimet taja konteksta
👍: 0 ⏩: 1
wonderwhy-ER In reply to TurboFerret [2008-04-17 09:07:50 +0000 UTC]
Получаеться exact и было в корне этого слова... Ну в принцепе компютерные науки относяться к естественым но занимаються чем ни попадя Вон гинетические алгортмы точными не назавёш
👍: 0 ⏩: 1
TurboFerret In reply to wonderwhy-ER [2008-04-17 13:52:34 +0000 UTC]
Нда ок не буду высказыватся о латвийской системе образования
👍: 0 ⏩: 1
TurboFerret In reply to wonderwhy-ER [2008-04-17 14:14:05 +0000 UTC]
Мне тут места не хватит
👍: 0 ⏩: 0
cepums [2008-04-15 09:11:27 +0000 UTC]
i couldn't say i get it..
just some dots jumping from one point to another..
understandable only for a guy who made it...
i think you could just write the algoritm down and post it in literature section..
i know that probably took alot of time and thought.. and there probably is some thought under it.. but to me those are just jumping dots that make no sence.. i don't see no evolution.. no mutation.. no nothing.. just dots..
👍: 0 ⏩: 1
wonderwhy-ER In reply to cepums [2008-04-15 09:17:35 +0000 UTC]
Well i suppose that from level of a god we are not evolving but just some jumping dots too
I doubt that algorithm will allow you to see evolution. As i said main aim here is to untangle the graph(no line intersections) and you can see that with time it untangles it.
👍: 0 ⏩: 1
cepums In reply to wonderwhy-ER [2008-04-15 09:46:41 +0000 UTC]
nea... i don't see anything.. just dots and lines that make no sence..
too much math.. and absolutely no aesthetics man
👍: 0 ⏩: 1
wonderwhy-ER In reply to cepums [2008-04-15 09:47:32 +0000 UTC]
Well this thing is not about visual aesthetics
👍: 0 ⏩: 0
Computer-Turret [2008-04-14 11:36:41 +0000 UTC]
Pretty interesting.
Spelling error in the log.
"Mutations finihsed"
should be
"Mutations finished."
👍: 0 ⏩: 1
wonderwhy-ER In reply to Computer-Turret [2008-04-14 12:38:04 +0000 UTC]
Hehe. Wil lcorrect it latter
👍: 0 ⏩: 0
lyc [2008-04-14 01:07:15 +0000 UTC]
by the way, you should tune the parameters!
intuitively, you are keeping too many of the "losers", 50% is extremely generous if looked at from the evolutionary point of view (1-legged humans allowed to survive, that's nonsense ).
if i use a population of 400, 25% survivors kept, 15% of which are mutations then it reaches 1 intersection 1 like < 20 generations. with the default settings it takes forever to get there!
one thing i really enjoy about these kinda evolutionary algorithms is that you can apply a lot of very intuitive reasoning to understand the system and use good parameters for it.
👍: 0 ⏩: 1
wonderwhy-ER In reply to lyc [2008-04-14 10:27:45 +0000 UTC]
Well actually i didn’t gave much thoughts to parameters so far. It just my guess was to find the brother where after witch fittest stop to survive and mutants and their children will take over. So setting parameters somewhere before that border would give best results. Small amount of fittest will still survive and we will have pretty large and fast changing population of challengers. But I haven't played with parameters to tune them yet. I think I will do it tomorrow before I will be handing it over to teacher.
👍: 0 ⏩: 0
lyc [2008-04-14 01:03:43 +0000 UTC]
btw it's artificial *intelligence, not inelegance (it's actually very elegant )
👍: 0 ⏩: 1
wonderwhy-ER In reply to lyc [2008-04-14 10:27:33 +0000 UTC]
Ok thanks Sometimes i don't notice how it corrects my mistakes...
👍: 0 ⏩: 0
lyc [2008-04-14 01:02:08 +0000 UTC]
heh this makes firefox really slow, even on a multicore computer (so flash is not multithreaded!).
nice work, and interesting subject. genetic algorithms (a combination of monte carlo randomisation and fitness-based evolution) are really awesome for solving complex problems.
by the way, since you've clearly understood GAs you might be interested to compare this with the metropolis-hastings sampling i use in my rendering algorithms: [link]
👍: 0 ⏩: 1
wonderwhy-ER In reply to lyc [2008-04-14 10:19:21 +0000 UTC]
Hmm. So some algorithm that allows to create distribution aproximations and claculate aproximate integrals? Not really shore if i know where to use such thing Usualy i am fine with normal distribution and i seem can't remember when i needed integral in my apps
👍: 0 ⏩: 1
lyc In reply to wonderwhy-ER [2008-04-14 10:58:35 +0000 UTC]
well, all rendering is based on integration so it forms a huge part of what i do
👍: 0 ⏩: 1
wonderwhy-ER In reply to lyc [2008-04-14 11:18:39 +0000 UTC]
Hmm. So you use such aproximate integrals to get say fog densety in one calculation of integral?
👍: 0 ⏩: 1
lyc In reply to wonderwhy-ER [2008-04-14 21:46:26 +0000 UTC]
for example; when you render a pixel, just evaluating the colour function once will produce ugly aliasing, so you have to integrate the product of the colour function and the reconstruction filter function. or when you're making an audio stream, a similar thing applies.
actually with my rendering system, the integrals are infinite-dimensional. have a look: [link]
👍: 0 ⏩: 1
wonderwhy-ER In reply to lyc [2008-04-15 07:05:48 +0000 UTC]
Hmm. Seems to be large article. Thanks i will try to read it later. Seems to be interesting
👍: 0 ⏩: 0
killthemouse [2008-04-14 00:47:38 +0000 UTC]
Cool! How is this kinda process used in other AIs?
👍: 0 ⏩: 2
wonderwhy-ER In reply to killthemouse [2008-04-14 10:37:09 +0000 UTC]
I suppose you mean how it could be used in games? Well usually it is not used directly in games. It just that this algorithm can solve almost anything but it’s almost a brute force that makes a lot of tries before he gets where he needs. But it can be used to teach some other systems like neural network AI for a game. Or help AI creator to get first impression on the task and see what good solutions look like and how near to good solutions look like and get ideas how he can make a solver to find those efficiently.
👍: 0 ⏩: 1
killthemouse In reply to wonderwhy-ER [2008-04-14 10:54:01 +0000 UTC]
Well I figured it would be too slow for realtime applications... but yeh, is still pretty interesting!
👍: 0 ⏩: 0
lyc In reply to killthemouse [2008-04-14 01:01:00 +0000 UTC]
you could write a pretty good travelling salesman problem solver using GAs, that's the canonical example i think
👍: 0 ⏩: 0
Taiya001 [2008-04-13 22:44:30 +0000 UTC]
WOAH...
The extensive research and knowlege is astounding
👍: 0 ⏩: 1
wonderwhy-ER In reply to Taiya001 [2008-04-13 22:54:43 +0000 UTC]
Mm thanks Well idealogical part here is not that extensive or astounding. Just simple idea where fittest have better chances and as a result in long run that provides convergence to the better solutions. Taken from nature
👍: 0 ⏩: 1
Taiya001 In reply to wonderwhy-ER [2008-04-14 14:10:07 +0000 UTC]
^^ sweeeeet and welcome
I think this could be used one day for extremely large populations
👍: 0 ⏩: 0
spacewarp [2008-04-13 21:49:38 +0000 UTC]
Gaaaah
GA:s are one of the most interesting things it've experimented with. Those and NN:s.!
👍: 0 ⏩: 1
wonderwhy-ER In reply to spacewarp [2008-04-13 22:02:04 +0000 UTC]
NN? Ouh neuron networks. Well those are close. Just smarter Will be learning them in deeper version again after the summer.
And thanks for fav
👍: 0 ⏩: 0
MediaDesign [2008-04-13 21:45:43 +0000 UTC]
Wow man, you are really really good at maths. But why apply it into Flash? I mean, you'd make (much more) money doing this stuff for Playstation games or xBox games. But still, amazing work, wish I knew as much as you.
👍: 0 ⏩: 1
wonderwhy-ER In reply to MediaDesign [2008-04-13 22:04:22 +0000 UTC]
Well it is not as amazing as you think. Then i am not interested in consoles market. More in web 2.0 websites and browser gaming currently. Though playing with DirectX is one of things i am eager to try(well actually did few small things but don't have time and real interest now)
👍: 0 ⏩: 0
Keydan [2008-04-13 20:50:31 +0000 UTC]
AI eh? I made an AI once... for tic-tac-toe... welll not an AI, a brutal AI. But it worked.
👍: 0 ⏩: 1
wonderwhy-ER In reply to Keydan [2008-04-13 21:24:49 +0000 UTC]
Well this thing is something like semi intelligent brute force. Depending on parameters it can find average solution pretty fast or with other parameters works slow but finds best solution(though there are no ways to determine as if we did found the best. That's one of the drawbacks of this thing).
👍: 0 ⏩: 0
rocketship123 [2008-04-13 18:35:53 +0000 UTC]
this is amazing!
i wish i knew more about ai....
👍: 0 ⏩: 1
wonderwhy-ER In reply to rocketship123 [2008-04-13 18:38:11 +0000 UTC]
Well you always can learn
👍: 0 ⏩: 0