Tag: Genetic Algorithms

Genetic Algorithms, Pyevolve, pys60, Python

TSP on Nokia N73 using PyS60 and Pyevolve

As I promised on the post about Pyevolve on N73, I’ve ported the TSP problem to run on the cellphone. The script will draw the best individual of every generation on the screen using the PyS60 Canvas API. The quality of the video is very low, I’m using another cellphone with VGA only recording.

When I have time, I’ll release the source-code here in the same post. The TSP code is the same used in PSP, but ported to use the Canvas API of PyS60.

I hope you enjoy.

UPDATE 24/04: the source-code can be downloaded here.

Genetic Algorithms, genetic programming, News, Pyevolve, Python, Time Waste

Genetic Algorithms on cellphones ! Pyevolve on Nokia N73 (Symbian + PyS60)

Hello ! This is the 2nd post related to the Pyevolve on portable devices, the first was in the Sony PSP here and the PoC of Pyevolve solving the TSP problem with a graphical output of best individuals on the Sony PSP screen. Now, it’s time to go further and run Pyevolve into the most portable device used by us, the cellphone.

Using the new version of the PyS60, the release 1.9.1, which comes with the new amazing 2.5.1 Python core, I’ve executed the Pyevolve with no problem, and I was very surprised by the performance of the GA on the Nokia N73, the GA I’ve ran is the minimization of one of the De Jogn’s test suite functions, the Sphere function, the function is very simple and I’ve used 5 real variables between the interval of [-5.12, 5.12], the Gaussian Real Mutator and the Single Point Crossover of the Pyevolve framework. Also I’ve set a population size of 80 individuals and the mutation rate of 2% and crossover rate of 90%.

After 18 generations (about 8 seconds), the GA ended with the best score of 0.0, representing the optimal minimization of the De Jong’s Sphere function.

Follow some screenshots of the adventure (click on the pictures to enlarge):

How to install Pyevolve on the PyS60 ?

1) First, you need to install the PyS60 for your Symbian platform. Here is the installation manual. The order of the installation is: Python Runtime for S60, Python Script Shell and PIPS Library.

2) Then, you must create a directory on your Memory Card, inside the “Python” directory, named “Lib”, and inside this directory, you copy the “pyevolve” folder. The absolute folder structure will be like this:

MemoryCard:\Python\Lib\pyevolve

Some features of the framework will not work, like the some DB Adapters, however, the GA core is working really good. I’ve used the Pyevolve subversion release r157, but it should works with the 0.5 release too. I’ve not finished the documentation of the new release, I’m working on some features yet.

Here is the source code I’ve used to minimize the De Jong’s Sphere function:

import e32
print "Loading Pyevolve modules...",
e32.ao_yield()

from pyevolve import G1DList, GSimpleGA
from pyevolve import Initializators, Mutators, Consts

print " done !"
e32.ao_yield()

def sphere(xlist):
   n = len(xlist)
   total = 0
   for i in range(n):
      total += (xlist[i]**2)
   return total

def ga_callback(ga_engine):
   gen = ga_engine.getCurrentGeneration()
   best = ga.bestIndividual()
   print "Generation %d - Best Score: %.2f" % (gen, best.score)
   e32.ao_yield()

   return False

if __name__ == "__main__":

   genome = G1DList.G1DList(5)
   genome.setParams(rangemin=-5.12, rangemax=5.13, bestRawScore=0.00, roundDecimal=2)
   genome.initializator.set(Initializators.G1DListInitializatorReal)
   genome.mutator.set(Mutators.G1DListMutatorRealGaussian)

   genome.evaluator.set(sphere)

   ga = GSimpleGA.GSimpleGA(genome)
   ga.setMinimax(Consts.minimaxType["minimize"])
   ga.setGenerations(100)
   ga.setMutationRate(0.02)
   ga.terminationCriteria.set(GSimpleGA.RawScoreCriteria)
   ga.stepCallback.set(ga_callback)

   ga.evolve()

   best = ga.bestIndividual()
   print "\nBest individual score: %.2f" % (best.score,)

You can note the use of the module “e32” of the PyS60, this is used to process pending events, so we can follow the statistics of current generation while it evolves.

I hope you enjoyed this work, the next step is to port the TSP problem to cellphone =)

Some time ago I’ve asked Guido van Rossum on the Google Moderator about the future of Python for mobile phones (aka PyS60), and here is the full answer from him:

I’m hopeful, but concerned that Java has cornered this market. For example, the Android development kit is extremely slick but only supports Java at the moment. There’s no doubt about which is the dominant app development language on most mobile platforms, including S60 and anything Symbian-based. In the long run I expect Python to just happen on mobile devices, as increases in disk space will allow the set of pre-installed tools to grow. In the mean time I see a bigger role for Python server-side, for example there are iPhone apps backed by services written in Python running on App Engine (and probably also apps backed by Python running on other server platforms).
Guido van Rossum, San Francisco Bay Area

Well, I think that with this new version of PyS60, with the 2.5.1 core, the Python on mobiles can be very useful and productive. Recently, Nokia have signed a loan agreement with the European Investment Bank (EIB) to the tune of €500 million ($623.9 million). According to Reuters, the five-year loan will be used in part to “finance software research and development (R&D) projects Nokia is undertaking during 2009-2011 to make Symbian-based smartphones more competitive.” So I’m with great expectations with this new investment on Symbian smartphones and with the future possibilities of the PyS60.

Genetic Algorithms, genetic programming, News, Science

Google Search Insight for GA and GP

I have done a search for the keywords “genetic algorithm” and “genetic programming” on Google Insights for Search and I noticed that India is the region with the most interest on this search terms:

insight

I’ve used the category “Science” to remove some terms of other search categories, but unfortunately this is only an approximation of the real interest, since is obviously that the terms “genetic algorithms” can be searches of algorithms for genetics too.

Genetic Algorithms, Pyevolve, Python

Rosenbrock’s banana function and friends

This post is a report of an optimization test suite applied to Pyevolve GA Core.

I’m writing a paper about Pyevolve and I’ve done some tests on the GA quality of Pyevolve with must common optimization test functions: Schaffer, Rastringin, Sphere, Ackley and the absolute GA-hard Rosenbrock. Follows in the end of the post, the results of the trials, I’ve exported the latex formulae as images.

The only function that the GA had some trouble (it failed to find the global minima in 3 of 10 trials, the “fail” term means that it had not found an optimal solution for 5.000 generations) was the Rosenbrock’s function with 20 variables, also known as Rosenbrock’s banana function due the dinstinctive shape of the contour lines, here is the 3D plot with 2 variables.

As Wikipedia says,

This function is often used to test performance of optimization algorithms. The global minimum is inside a long, narrow, parabolic shaped flat valley. To find the valley is trivial, however to converge to the global minimum is difficult.

However, this behavior was not unexpected, since we can note the same on the research of [1], [2], [3] and [4], among other many papers.

I think this trial results brings more reliability to the framework, when the Pyevolve paper was published, I’ll post it here.

[1] Seredynski, Franciszek, et. al. (2003). “Function Optimization with Coevolutionary Algorithms”, in International Intelligent Information Processing and Web Mining Conference.

[2] Hiroyasu, Tomoyuki, et. al. (1999). “Distributed Genetic Algorithms with Randomized Migration Rate”, IEEE Proceedings of Systems, Man and Cybernetics Conference SMC’99, Vol. 1, pp. 689-694.

[3] Bouvry, Pascal, et. al. (1997). “Distributed evolutionary optimization in Manifold: the Rosenbrock’s function case study”, Duke University.

[4] Panait, Liviu (2002). “A comparison of two competitive fitness functions”, in GECCO 2002: Proceedings of the Genetic and Evolutionary Computation Conference.

Genetic Algorithms, News, Science

Genetic Algorithms help us to understand how we see

There is a very interesting article on the insciences.org, it talks about the use of a Genetic Algorithm to create images used to test people brain performance:

The team developed a ‘genetic algorithm’, based on a simple model of evolution, that can breed a range of images and visual stimuli which were then used to test people’s brain performance. By using artificial intelligence to design the test patterns, the team removed any likelihood of predetermining the results which could have occurred if researchers had designed the test pictures themselves.

Read the full article or see the created images.

Genetic Algorithms, News, Science

A beautiful example of cooperation between theory and experiment, the new Boron form

The NY Times has a nice article talking about the discovery of a new Boron form using Genetic Algorithms:

Now researchers led by Dr. Oganov have added to the actual discoveries. They have found a form of boron that is nearly as hard as diamond.

This discovery even illustrates the power of the idea of evolution, using a so-called genetic algorithm to decipher the structure of the new boron crystal.

“This work is a beautiful example of cooperation between theory and experiment,” said Aitor Bergara, a physicist at the University of the Basque Country in Spain. Dr. Bergara was not involved with the research, which was published online by the journal Nature.

Read the full article.

I'm starting a new course "Machine Learning: Foundations and Engineering" for 2024.