Get Instant Help From 5000+ Experts For

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Optimization using Genetic Algorithms and Particle Swarm Optimization

## Genetic Algorithm Optimization of a Multivariable Function

Your report should be single-spaced, double-column (but tables or figures are allowed to span two columns if you wish).Ã¯Â¿Â½Ã¯Â¿Â½

Submit a single PDF file. The code you used to produce the results should be appended at the end of the report (appendix). The appendix may be in single column format. Include a heading for each program in the appendix, i.e. one program for Q1.1, one program for Q1.2, etc. Everything should be pasted into one document, do not submit code as separate files.

Explain important hyperparameter settings you used, or any important changes to code that you needed to make.

1. For the following function: Ã¯Â¿Â½

Ã¯Â¿Â½ Ã¯Â¿Â½ fÃ¯Â¿Â½(x1,Ã¯Â¿Â½x2) = 2 + 4.1 x12Ã¯Â¿Â½- 2.1 x14 Ã¯Â¿Â½+ 1Ã¯Â¿Â½x16Ã¯Â¿Â½+ x1Ã¯Â¿Â½x2Ã¯Â¿Â½Ã¯Â¿Â½ 4 (x2 - 0.05)2Ã¯Â¿Â½+ 4 x24Ã¯Â¿Â½Ã¯Â¿Â½

1.1 Use a genetic algorithm to find the minimum of the function. Use 30 bits per chromosome and allow x1andÃ¯Â¿Â½x2Ã¯Â¿Â½to range from -5 to 5. Other hyperparameters may be the same as the example from Week 2. In your report you must show:

a. The fitness of the fittest individual after 100 generations, and its decoded values for x1andÃ¯Â¿Â½x2. Remember that if you are using the inverse of the fitness within the algorithm then you will need to convert this back to actual function value. [5 marks]

Ã¯Â¿Â½

b. A plot of the fitness of the fittest individual across the generations. [3 marks]

Ã¯Â¿Â½

c. A 3D surface plot of the function facross the range -2.1 < x1Ã¯Â¿Â½< 2.1, Ã¯Â¿Â½and -1.1 < x2Ã¯Â¿Â½< 1.1 (note this is just the scale of the plot. It is not asking you to change the bounds on x1,Ã¯Â¿Â½x2Ã¯Â¿Â½in the GA), and a series of the fittest individual in each generation drawn on top of this plot, in black, with the final fittest individual in red.

Here are examples of the expected output:

It is important to use a suitable viewing angle so that the points can be clearly seen (see Week 1 example). Note that due to the random nature of GAs it is possible that the initial population already has a best individual extremely close to the minimum (which means that the problem is already almost solved at generation zero). If this happens then run the GA again until you obtain a solution which shows a clearly visible improvement across generations, as in the above examples. [5 marks]

1.2 Write code to implement gradient descent for the same function f. Show the equations you derived for the slope of the function in each direction x1,x2. You do not need to spend a lot of time on formatting maths in your report; you could do it on paper and include a photo in the report, or do it with simple formatting like Q.3 below. Show a 3D surface plot of the function, with the Ã¯Â¿Â½series of improving solutions found during the descent (as in Week 1), from a suitable starting point (suitably far from the minimum). Show a second 3D plot to illustrate that a different starting point can lead to a different final solution. Ã¯Â¿Â½ [5 marks]

## Gradient Descent Implementation for the Same Function

Ã¯Â¿Â½

2. Find the minimum of the following function for 20 dimensions (n=20), using particle swarm optimisation

In your report you must show:

a. The fitness of the fittest individual after 400 generations, and its decoded value for x1, using the canonical PSO. [5 marks]

Ã¯Â¿Â½

b. A plot of the fitness of the global best individual across the generations, using the canonical PSO. [3 marks]

Ã¯Â¿Â½

c. A plot of the fitness of the global best individual across the generations, using the social learning PSO (SL-PSO). [5 marks]

Ã¯Â¿Â½

3. This task is to solve the following multi-objective optimisation problem using the elitist nondominated sorting genetic algorithm (NSGA-II), using a programming language of your choice. Ã¯Â¿Â½min{ f1, f2}

Ã¯Â¿Â½ Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½f1Ã¯Â¿Â½= [((x1-0.6)/1.6)2Ã¯Â¿Â½+ (x2/3.4)2Ã¯Â¿Â½+ (x3-1.3)2] / 2.0Ã¯Â¿Â½ Ã¯Â¿Â½ Ã¯Â¿Â½ Ã¯Â¿Â½ Ã¯Â¿Â½

Ã¯Â¿Â½f2Ã¯Â¿Â½= [(x1/1.9 Ã¯Â¿Â½- 2.3)2Ã¯Â¿Â½+ (x2/3.3 Ã¯Â¿Â½- 7.1)2Ã¯Â¿Â½+ (x3 Ã¯Â¿Â½+ 4.3)2] / 3.0

Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½ -4.0 Ã¯Â¿Â½Ã¯Â¿Â½x1, x2, x3Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½4.0

3.1 Encode the decision variables using Gray coding, each using 10 bits. Set the population size to 24 and randomly generate an initial population. List the 24 initial solutions in a table in the following format: [3 marks]

x1, x2, x3, f1, f2Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½(for the xiÃ¯Â¿Â½give decoded values, not bit-strings) Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½

3.2 Sort the solutions in the initial generation using the efficient non-dominated sorting. Ã¯Â¿Â½NOTE: Deap does not implement the efficient non-dominated sorting; to get full marks you need to code this yourself using the algorithm specified in the lecture (Week 4). List the solutions together with their front number in a table in the following format and sort them according to the front number in an ascending order. Print out the sorted individuals in objective values and front number. Also show a 2D plot of the solutions in objective space, indicating which belong on the same fronts. In your table highlight the worst objective value inf1: f1* = max{f1iÃ¯Â¿Â½}, i = 1, Ã¯Â¿Â½, 24, and the worst objective value in f2: f2* = max{ f2i }, i=1, Ã¯Â¿Â½, 24. [5 marks] Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½f1, f2, front number

3.3 Calculate the crowding distance of each individual in the initial population. Add the resulting crowding distance of each individual to your table of 3.2 in the following format. [3 marks]Ã¯Â¿Â½ f1, f2, front number, crowding distance Ã¯Â¿Â½Ã¯Â¿Â½

3.4 Apply tournament selection to select parent individuals for reproduction. Consider dominance and crowding distance in the selection. Create 24 offspring individuals. Select individuals for crossover at a probability of 0.9 and apply uniform crossover. Apply flip mutation at a probability that is inversely proportional tothe length of the chromosome for each bit. Plot the 24 offspring individuals together with the parents in the objective space.

Visualize the parent and offspring individuals using different colours. [3 marks] Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½

3.5 Combine the 24 offspring individuals with the 24 parent individuals. Then select 24 individuals from the combined population using the crowded non-dominated sorting method. Plot the combined population (48 individuals) in the objective space. Highlight the

24 selected solutions using a different colour. [2 marks]

3.6 Run the evolution for 30 generations by repeating the above steps. Calculate the hypervolume using the worst objective values ( f1*, f2*) obtained in Question 3.2 as the reference point (i.e. keep this as reference point for all generations) and plot the hypervolume of the non-dominated solutions over the generations. Note that hypervolume is a scalar value, so you are just plotting a scalar hypervolume value (y-axis) versus generation (x-axis), you are not asked to draw the hypervolume in f1, f2 Ã¯Â¿Â½space. Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½

Also plot (in a separate plot) the final generation of solutions in objective space, along with the reference point in a different colour. [3 marks]