Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
A Generic Genetic Algorithm using Phenotype Building Functions

A Generic Genetic Algorithm using Phenotype Building Functions

Ratings: (0)|Views: 3,607|Likes:
Published by mtanti87
A scientific paper written by Marc Tanti in 2010 as a B.Sc. IT thesis. The research is about making genetic algorithms generic so as to make them more reusable.
A scientific paper written by Marc Tanti in 2010 as a B.Sc. IT thesis. The research is about making genetic algorithms generic so as to make them more reusable.

More info:

Categories:Types, Research, Science
Published by: mtanti87 on Feb 12, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





A Generic Genetic Algorithm using Phenotype Building Functions
Marc Tanti
Dept Artificial IntelligenceUniversity of Malta
The problem with genetic algorithms isthat their use is made difficult by the factthat they are not very reusable. This isbecause the chromosome representation,genetic operators and fitness functionneed to be redefined for many problems.In order to use a genetic algorithm onehas to think in terms of evolution whichmight not be easy for a programmer. Inthis project, we aim to solve these prob-lems by creating a generic chromosomerepresentation which always uses thesame genetic algorithm regardless of theproblem being solved. The user then di-rects the genetic algorithm by writing afunction, called the ‘phenotype buildingfunction’ or the ‘builder function’, whichmaps the generic chromosome into can-didate solutions. The fitness function willstill have to be provided in order tomeasure the fitness of a candidate solu-tion.Results of examples executed with thismethod show that the genetic algorithm’sprocess is not significantly hindered bythis abstraction and that the use of thegenetic algorithm was intuitive.
In genetic algorithms, the problem being solveddictates the encoding of the chromosome.(Obitko) mentions four types of chromosomalencodings:Binary encoding is when the chromosome is astring of bits and its applications include evolv-ing binary numbers and sequences of Booleanvalues. Crossover is done by exchanging bitsbetween chromosomes using methods such assingle point crossover, two point crossover, n-point crossover and uniform crossover whilstmutation is done by randomly inverting bits.Permutation encoding is when the chromo-some is a permutation, that is, an ordering of elements. Things like Hamiltonian cycles or or-dering problems can be encoded this way. Sincethe permutation property needs to be preserved,partially matched crossover is used for crossoverand random swaps are used from mutation.Value encoding is the same thing as binaryencoding except that it uses a greater cardinality,that is, more than just ‘0’ or ‘1’, such as enume-rations, integers, real numbers and objects. Anyof the crossover methods for binary chromo-somes can be used. For mutation, a small randomreal number can be added to a number in thechromosome in the case of real numbers or anelement in the chromosome can be randomlyexchanged with another random element.Tree encoding is when trees are used forchromosomes. This is used in genetic program-ming where equations are represented as expres-sion trees and programs are represented as syntaxtrees. Crossover can be the swapping of sub-treesbetween trees and mutation can be the replace-ment a sub-tree with a random sub-tree.This variety of encodings (and correspondinggenetic operators) is contrasted with biologicalevolution where only one encoding is used, theDNA. Yet, an enormous diversity of form andfunction exists in the different phenotypes weobserve. So biological evolution can be thoughtof as a form of generic genetic algorithm, wherefrom a single chromosome encoding, any solu-tion can be evolved. It would be desirable tohave the same ability in genetic algorithms.Of course the DNA can be thought of as a val-ue encoding with a cardinality of four (since it ismade up of four different nucleotides) and thatthings like Hamiltonian cycles and expressiontrees are probably not best evolved on such a
system. But the power of biological evolution isnot in how the genotype is represented, but inhow it is used. (Kratz, 2009) describes that theDNA is used by first dividing it into sectionscalled genes which encode proteins. Proteins aresequences of molecules called amino acids, thesequence of which is determined from the gene.Once a protein is produced it folds up into a threedimensional structure, the shape of which willgive it a function such as breaking or joiningmolecules. All the different proteins producedwhen working together make cells do what theydo and this gives rise to the phenotype.So it can be said that the power of chemistry isheld inside this chromosome representation. Dif-ferent DNA instances give rise to different chem-ical results rather than encoding the phenotypedirectly in the DNA, as is the case with tradition-al genetic algorithms. This is what makes biolog-ical evolution so versatile. The question iswhether we can place the power of the Turingmachine, rather than of chemistry, inside a ge-neric genetic algorithm. That way it can be usedand reused for a wide variety of problems, ratherthan having to redesign the encoding and geneticoperators for different problems.There are, of course, several indirect encod-ings developed which use a process to convertthe chromosome into a candidate solution ratherthan encoding the candidate solution itself in thechromosome. Such examples include the follow-ing: (i) Developmental Genetic Programming(Banzhaf & Keller, The Evolution of GeneticCode in Genetic Programming, 1999) which usesan arbitrary sequence of symbols found in ma-thematical equations as a chromosome and re-pairs these sequences into legal expressions, (ii)Gene Expression Programming (Ferreira, 2001)which encodes a tree of nodes into a linearlystructured chromosome to be converted to a treesuch that any chromosome is guaranteed to havea prefix that encodes a valid tree, and (iii)Grammatical Encoding (Mitchelle, 1998, p. 74)where a context free grammar is evolved, out of which a single string is produced which encodeshow the neurons of an artificial neural network are to be interconnected.However the only indirect encoding foundwhich was meant to be used as a general solutionrather than being problem oriented was that de-scribed in (Guillaumier, 2002) where problemsare described as DBMS tables which need rela-tionships between the tables; the genetic algo-rithm will then evolve the relationships. Thissystem is very natural to use for solving relation-ship problems such as time table schedulingwhere a relationship between time slots and les-sons has to be found. However, it becomes lessnatural to use for other problems such as numeri-cal ones.This paper describes a way to create a genericgenetic algorithm which is both reusable for dif-ferent problems and easy to use by a program-mer.
Specification and Analysis
One way to create a generic genetic algorithm isto make one which can evolve any value of anytype (strings, integers, floats, arrays of strings,etc). The user would then only have to supply afitness function which, apart from acting as anormal fitness function, also penalizes a candi-date solution for being of an undesired type andfor being an illegal value (such as an array whichisn’t a permutation). The problem, of course, isthe massive search space created as well as theincreased complexity of the fitness function.Instead, a way to guide the genetic algorithmto create only candidate solutions of a desiredtype is used. The genetic algorithm used is asimple binary chromosome encoding, irrespec-tive of the problem being solved. Therefore thegenetic algorithm needs never be altered and isgeneric. What’s new is that apart from the fitnessfunction, the user also supplies a phenotypebuilding function, or builder function.This function takes as a parameter a reader ob- ject which encapsulates the binary chromosomeand provides methods to read the sequence of bits as primitive data type values such as integ-ers, strings and floats. In other words, each me-thod reads a part of the binary chromosome andconverts the binary number read to the appropri-ate type. For example reading a single bit to re-turn a Boolean value or reading several bits toreturn an integer. This is analogous to the way afile reader works, which reads a file byte by byte,converting the bytes into data of the desiredtypes.The user writes the phenotype builder functionsuch that its parameter, the reader object, is usedto obtain inputs for the function. Based on theseinputs, the function is to output a candidate solu-tion. The function is written such that only can-didate solutions of the desired type and only le-gal values are returned. For example, if a feedforward artificial neural network is to beevolved, a phenotype building function could bewritten which reads as many floats as there are
weights, organizes these floats into matrices forthe artificial neural network and returns the neur-al network as a candidate solution, or phenotype.An example of a phenotype building functionwhich produces square numbers would be thefollowing:This function first reads a natural numbermade from 10 bits from the binary chromosomeand then returns the square of that number.But the builder function could be more com-plex. For example permutations could be gener-ated by reading pairs of array indexes and thenusing these pairs to swap the indexes in an or-dered array. Thus an ordered array would beshuffled into a new permutation just by readingnumbers from the chromosome, without havingto use special encodings.It was thought that reading the chromosome atruntime rather than preloading all required inputsbeforehand would allow for a shorter chromo-some as the same bits can be read differentlybased on previous inputs read.Thus we have a new way of thinking aboutgenetic algorithms. Instead of viewing geneticalgorithms as evolving solutions to problems, weview them as evolving inputs to an algorithmwhich generates solutions. As the inputs areevolved, the output is also evolved and the genet-ic algorithm searches for the inputs which max-imize the fitness of the output.We believe that this new way of using geneticalgorithms is easier for programmers to use asinstead of thinking in terms of evolution, theywould be thinking in terms of algorithms whichmap inputs to outputs. Hence in this way wehave created a genetic algorithm which is genericbecause it harnesses the power of the Turing ma-chine in the phenotype building function to begeneric, just as biological evolution harnesses thepower of chemistry in the proteins to be generic.
The genetic algorithm used was intentionallymade simple in order to demonstrate that the per-formance of the search is not drastically deteri-orated by the way the genetic algorithm is usedand that no special genetic algorithm needs to beused for it to work. The genetic algorithm usesbinary chromosomes, rank selection, 2-pointcrossover and point mutation (giving each bit asmall probability of being flipped).
Examples and Experiments
In order to demonstrate the validity of the con-cept, a suite of problems were attempted to besolved using the described system. Each experi-ment was run 3 times and was allowed to evolvefor 500 generations. The best fitness of eachgeneration was recorded and will be presentedhere as a graph.
Artificial Neural Network for Parity
In this problem, the genetic algorithm was usedto evolve the weights for an artificial neural net-work to learn the 7-bit odd parity problem using20 hidden neurons (plus 7 inputs and 1 outputneuron).The builder function reads rational numbers of 10 bits for the whole number and 10 bits for thefractional part for each weight, 160 (7×20+20×1)weights in all, and organizes them into the ma-trices of the artificial neural network.The fitness function calculates the meansquare error of each 7 bit input. The genetic algo-rithm minimizes the error.None of the 3 runs reached zero error. Thelowest MSE reached was 0.0234375 with only 3(of 127) inputs which give an error greater than0.1.
Figure 1 Graph of best fitness vs generation of evolutionof weights of an ANN.
N-Queens Problem
In this problem, the genetic algorithm was usedto evolve a solution for the 16-queen problem, byplacing 16 queens on a 16 by 16 chess boardwithout restrictions on the placement in order tointentionally make it harder to evolve (queenscan even overlap).The builder function reads 16 chess boardcoordinates (pairs of natural numbers) and placeseach queen there.
        1       4        3        8       5        1        2       7        1        6        9        2        1        1        2       5        3        2        9       5        3        3       7        3       7        9       4        2        1       4        6        3
   M   e   a   n   S   q   u   a   r   e   E   r   r   o   r
function int builder(reader) {int num = reader.readNatural(10);return num*num;}

Activity (12)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Lawal Razaq liked this
Pero Prebeg liked this
Šime Gverić liked this
Just Ice liked this
Pau Vina liked this
Dragan Karanovic liked this
mokkabokka liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->