17
Genetic Algorithms Genetic algorithms imitate a natural optimization process: natural selection in evolution. Developed by John Holland at the University of Michigan for machine learning in 1975. Similar algorithms developed in Europe in the 1970s under the name evolutionary strategies Main difference has been in the nature of the variables: Discrete vs. continuous Class is called evolutionary algorithms

Genetic Algorithms

  • Upload
    mirra

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Genetic Algorithms. Genetic algorithms imitate a natural optimization process: natural selection in evolution. D eveloped by John Holland at the University of Michigan for machine learning in 1975. Similar algorithms developed in Europe in the 1970s under the name evolutionary strategies - PowerPoint PPT Presentation

Citation preview

Slide 1

Genetic AlgorithmsGenetic algorithms imitate a natural optimization process: natural selection in evolution.Developed by John Holland at the University of Michigan for machine learning in 1975.Similar algorithms developed in Europe in the 1970s under the name evolutionary strategiesMain difference has been in the nature of the variables: Discrete vs. continuousClass is called evolutionary algorithmsKey components are population, parent and child designs, and randomness (e.g. mutation)

Genetic algorithms imitate natural selection In evolution. The key ideas that distinguish genetic algorithms from traditional search algorithms are the use of population of designs, the mating of pairs of design to create child designs in a process called crossover, and the use of mutations to enhance exploration. Together it creates an optimization process that has a strong random component, so every time you run it you may get a different answer.Genetic algorithms were developed in 1975 by John Holland from the University of Michigan. However, similar algorithms were developed in Europe around the same time with the name of evolutionary strategies. GAs are usually associated with discrete variables, while evolutionary strategies with continuous ones.1Basic SchemeCoding: replace design variables with a continuous string of digits or genesBinaryIntegerRealPopulation: Create population of design pointsSelection: Select parents based on fitnessCrossover: Create child designs Mutation: Mutate child designs

In order to use a genetic algorithm we have to first start by coding the design variables as a string that imitates DNA. There is information on different ways to do that in Section 4.4 of Elements of Structural Optimization, with the three choices is whether to use binary, integer, or real variables. We will discuss that in the context of composite laminate design.

A key factor is working with a population of designs that can mate and create child designs. Then we need a method to select parents based on their objective function value that we translate to fitness as described later.

Child designs are created by crossing over the strings of the parents, that is taking some genes from one parent and some from a second parent. Selection plus crossover form together an exploitation mechanisms that looks for combination of good designs. Mutation adds an element of exploration.2Genetic operatorsCrossover: portions of strings of the two parents are exchangedMutation: the value of one bit (gene) is changed at randomPermutation: the order of a portion of the chromosome is reversedAddition/deletion: one gene is added to/removed from the chromosome

The slide illustrates the two basic genetic operators of crossover and mutation that are used in practically every genetic algorithm, plus two others that are useful for designing composite laminates.

Permutation changes the order of the genes, and for laminates it preserves the in-plane properties and changes only the bending properties.

Addition/deletion is important if we have laminates with each play assigned a gene and we do not know ahead of time the number of genes.3Select parentsAlgorithm of standard GACreate initialpopulationCalculatefitness401003070Create children

This illustrates how the basic operators work. You start with a population of designs and you calculate the fitness of each design based on its objective function and possibly constraint satisfaction.

Then you select parent designs based on their fitness but with randomness thrown in. From the figure we see that the best (green) design was selected three times, as was the second best (red). The third best design (blue) was selected twice and the worst design (orange) not at all.

Finally you create children by crossover and mutation. Here only crossover is illustrated.4Stacking sequence optimizationFor many practical problems angles limited to 0-deg, 45-deg, 90-deg.Ply thickness given by manufacturerStacking sequence optimization a combinatorial problemGenetic algorithms effective and easy to implement, but do not deal well with constraints

We will use stacking sequence optimization to illustrate the implementation of a genetic algorithm. In particular for the case where the ply angles are limited to 0, +-45 or 90 degrees. Ply thickness is given by the manufacturer, so the design problem is to select the number of plies you need and select the ply angles for each ply from the four choices.

Genetic algorithms do not deal well with constraints, and so it is common to use a penalty function to transform to an unconstrained problem.5Coding - stacking sequenceBinary coding common. Natural coding works better. (00=>1, 450=>2, - 450=>3, 900=>4) (45/-45/90/0)s => (2/3/4/1) To satisfy balance condition, convenient to work with two-ply stacks (02=>1, 45=>2, 902=>3) or (45/-45/902/02)s => (2/3/1) To allow variable thickness add empty stacks (2/3/1/E/E)=> (45/-45/902/02)s

Coding the stacking sequence of a composite laminate that has a finite number of possible angles is typically done by assigning a number to each angle, or even just using the angle itself. When the laminate is symmetric, we need to code only one half.

There is often also a balance condition that requires that the laminate has equal number of positive and negative angles. In our case, this means that the number of 45-deg plies needs to be equal to the number of -45-deg plies. This is tough to enforce, and an easy way out is to require that plies come in groups of two. This, however, may mean wasted plies for the zero or 90 directions.To allow variable number of plies, we also introduce an empty ply gene. Finally, if 6Coding - dimensionsBinary coding most common. Real number coding possible but requires special treatement. Trinary coding used in one example.Genetic algorithm not effective for getting high precision. It is better to go for coarse grid of real values. With n binary digits get 2n values.Segregate stacking sequence and geometry chromosomes.

For dimensions, such as stiffener height, it is common to use binary coding. Genetic algorithms like most global algorithms, are not good for zooming on a solution, so it is best to have a course grid. With n binary digits you can get 2n possibilities.

For example, if you have a stiffener whose height can vary from 1inch to 2 inches, and you care to determine it to 0.1 inch precision, you have 11 possible values. With four binary digits you actually get 16 values, so you can divide the range to 15 intervals, each 1/15 inch wide. So0000 denotes 1 0001 denotes 16/15 ,1111 denotes 2.

It is recommended to have separate strings or chromosomes for stacking sequence and dimensions, with possibly different mutations or crossover ruels.7Initial populationRandom number generator usedTypical function call is rand(seed)In Matlab rand(n) generates nxn matrix of uniformly distributed (0,1) random numbersSeed updated after call to avoid repeating the same number. See Matlab help on how to change seed (state).If we want repeatable runs must control seed.Need to transform random numbers to values of alleles (possible gene values).

Initial population is usually random. With Matlab we typically use the rand function. Need to transform to possible values of alleles (gene values). For example, if for stacking sequence design we have four angles, we will assign values in [0,0.25) to first angle, [0.25,0.5) to second angle, and so forth.

The random number generator uses a seed to select the first number and then updates it for the second, and so forth. The initial seed may reflect some internal computer state, time of day, or some other data available to the generator. It is selected so that it is practically random, and that means that every time you run a genetic algorithm you will bet a different result. If you want runs to be repeatable, you have to set the seed yourself.8FitnessAugmented objective f*=f + pv-bm+sign(v) .v = max violation m = min marginAs we get nearer the optimum, difference in f* between individuals gets smaller.To keep evolutionary pressure, fitness is normalized objective or ns+1-rank

The penalty function that is commonly used for genetic algorithms typically consists of three terms as shown in the equation. First there is penalty proportional to a measure of the constraint violation, which is often selected to be the maximum violation. This does nost of the work. Then there is a small penalty (delta) if there is any violation, to give preference to designs that satisfy the constraints over those that have very small violatons.

Finally there is a term that rewards margin with respect the constraint with a bonus. This is important when there are multiple designs that have the same objective function, but some satisfy the constraint with a larger margin. This is common in laminate design optimization. The objective function is often the weight, and all laminates with the same number of plies may have the same weight, if he geometry is fixed.

The augmented objective is not the same as the fitness. The fitness is often selected so that the difference between the best design and poorest design is large even if their objective function values are close. This prevents stagnation in the evolution as we near the optimum.Accentuating the difference may be done by normalizing. For example, if we subtract the value of poor9SelectionRoulette wheel and tournament based selectionElitist strategiesSelection pressures versus explorationNo twin rule

The two most common ways of selecting parents are roulette wheel and tournament. The roulette wheel approach will be shown in the next slide. Tournament selection is based on selecting randomly two individuals from the population and picking the best one as one parent, then repeating to select the second parent.

Some genetic algorithms pursue elitist strategies, where the top design in a generation is always selected to be moved to the next generation. This guarantees monotonic progress, but it has not been proven to lead to faster convergence.When we intensify selection pressures we favor exploitation versus exploration, so one has to be careful not to do that too early.

Finally, often genetic algorithms have a no twin rule, in that both parents cannot be identical.10Roulette wheelExample fitnesses

In a roulette wheel approach, each individual gets a slice of the roulette wheel that is proportional to its fitness. Spinning the roulette wheel is simulated by generating a random number in [0,1].

In the example we see a set of six fitnesses that are based directly on the augmented objective without normalization and they are very close. Consequently, the slices allocated to the six designs are close in size.If, on the other hand, the fitness is made proportional to the reverse rank, then the top design will get a slice of 6/21 of the wheel, the second best 5/21, and the poorest design 1/21.The figure also shows the effect of generating 6 random numbers and selecting individuals based on these numbers. With the original fitnesses, each design is selected once. With the rank based fitness, the first and third best designs get selected twice, while the fourth and sixth not once.

11Single Point CrossoverParent designs [04/452/902]s and [454/02]s

Parent 1 [1/1/2/2/3]Parent 2 [2/2/2/2/1]One child [1/1/2/2/1]That is: [04/452/02]s

The simplest way of mating two designs to create a child design is the single point crossover. We randomly select a point in the string and take all the genes to the left from parent 1 and all the genes to the right from parent 2. This is illustrated for two composite laminates where each gene describe a pair of plies.12Other kinds of crossoverMultiple point crossoverUniform crossover Bell-curve crossover for real numbersMulti-parent crossover

Other kind of crossovers include multiple point crossover, including the extreme version where we randomly assign each gene to one parent or the other. For real numbers we may do the crossover by generating a normal random number r and using r and (1-r) as the weighted combination of the two parents.

I tried three parent crossover, did not seem to make a difference. 13Mutation and stack swap[1/1/2/2/3]=> [1/1/2/3/3][04/452/902]s => [04/45/904]s

[1/1/2/2/3]=> [1/2/1/2/3][04/452/902]s => [(02/45)2/902]s

Mutation is a common genetic operator, and here it is illustrated for a laminate where we select a gene at random (here the fourth) and replace it randomly with another allele (here 2 becomes 3).

For laminates there is also permutation or swap. Here we select a pair of genes and switch their positions (1/2 becoming 2/1).14Questions GA Global optimization balances exploration and exploitation. How is that reflected in genetic algorithms? SolutionWhat are all possible balanced and symmetric child designs of [02/45/90]s and [452/0]s with uniform cross-over? SolutionWhen we breed plants and animals we do not introduce randomness on purpose into the selection procedure. Why do we do that with GAs? Solution on notes page.

When we breed plants and animals we do not introduce randomness on purpose into the selection procedure. Why do we do that with GAs?

Because there is enough randomness through natural causes, like differences that are due to chance events in the course of the development (e.g. one plant happened to be in a plot that got more water or more nutrients).15ReliabilityGenetic algorithm is random search with random outcome.Reliability can be estimated from multiple runs for similar problems with known solutionVariance of reliability, r, from n runs

When we want to compare algorithms that have random component this is difficult because each time they may have a different outcome. We often compare them by running n times and comparing what fraction of the time they ended up close enough to the global optimum.

However, because of the randomness even r is a matter of chance. The equation gives the standard deviation of the observed r from n runs. So for example, if we observe that 80 out of 100 runs were successful, the standard deviation is sqrt(0.8*0.2/100)=0.04, which is 5% of the observed value. 16Reliability curves

Here is a comparison between four global search algorithm that shows their reliabilities as a function of the number of function evaluations (analyses).. The curves were generated on the basis of 100 runs of each algorithms.

We ask ourselves whether the differences between these algorithms are meaningful or not. So for example, after 200 analyses, the four reliabilities are 0.2 (blue), 0.6 (yellow), 0.75(aqua) and 0.85 (magenta). If we use the equation for the standard deviation on the previous slide we get for the standard deviations 0.04, 0.049, 0.043, and 0.036. This tells us that the blue is certainly inferior to the others, and the magenta is better than the yellow, but for comparing the aqua to the yellow and magenta the difference may still be a matter of chance.17

Chart110101010000000000000000000.00333333330.00333333330.00666666670.00333333330.010.00666666670.020.00666666670.030.010.03333333330.010.05666666670.020.06666666670.010.130.03333333330.11333333330.01333333330.22333333330.080.170.02333333330.310.13333333330.230.03333333330.43666666670.18333333330.280.050.560.22666666670.340.05333333330.650.29666666670.44333333330.06666666670.70666666670.370.520.09666666670.75666666670.440.59333333330.120.830.53333333330.680.190.86666666670.59666666670.75333333330.21666666670.880.640.780.28333333330.90666666670.70333333330.83333333330.360.92666666670.770.86666666670.40666666670.940.80333333330.89333333330.43333333330.95333333330.83666666670.91333333330.48333333330.96333333330.87333333330.92666666670.530.97333333330.890.93333333330.60.97666666670.91666666670.94666666670.650.980.930.96333333330.68666666670.98333333330.940.96333333330.71333333330.98666666670.950.96666666670.73333333330.990.95333333330.96666666670.790.99333333330.960.97333333330.81666666670.99333333330.970.980.85333333330.99333333330.97666666670.98333333330.863333333310.97666666670.98333333330.893333333310.980.98666666670.9110.98333333330.99333333330.926666666710.990.99666666670.933333333310.99333333330.99666666670.95110.99666666670.951110.95666666671110.971110.97333333331110.97666666671110.981110.98333333331110.98333333331110.98333333331110.98666666671110.9866666667111

GAhalfrankrankhalfanalysesreliabilityall zero-basic algorithms

Sheet1analysesGAhalfrankrankhalf102000003000004000005000006000.00333333330.00333333330.0066666667700.00333333330.010.00666666670.02800.00666666670.030.010.0333333333900.010.05666666670.020.06666666671000.010.130.03333333330.11333333331100.01333333330.22333333330.080.171200.02333333330.310.13333333330.231300.03333333330.43666666670.18333333330.281400.050.560.22666666670.341500.05333333330.650.29666666670.44333333331600.06666666670.70666666670.370.521700.09666666670.75666666670.440.59333333331800.120.830.53333333330.681900.190.86666666670.59666666670.75333333332000.21666666670.880.640.782100.28333333330.90666666670.70333333330.83333333332200.360.92666666670.770.86666666672300.40666666670.940.80333333330.89333333332400.43333333330.95333333330.83666666670.91333333332500.48333333330.96333333330.87333333330.92666666672600.530.97333333330.890.93333333332700.60.97666666670.91666666670.94666666672800.650.980.930.96333333332900.68666666670.98333333330.940.96333333333000.71333333330.98666666670.950.96666666673100.73333333330.990.95333333330.96666666673200.790.99333333330.960.97333333333300.81666666670.99333333330.970.983400.85333333330.99333333330.97666666670.98333333333500.863333333310.97666666670.98333333333600.893333333310.980.98666666673700.9110.98333333330.99333333333800.926666666710.990.99666666673900.933333333310.99333333330.99666666674000.95110.99666666674100.951114200.95666666671114300.971114400.97333333331114500.97666666671114600.981114700.98333333331114800.98333333331114900.98333333331115000.98666666671115100.9866666667111

Sheet10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

GAhalfrankrankhalfanalysesreliabilityall zero-basic algorithms

Sheet2

Sheet3