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

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
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.

3D surface

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

function for 20 dimensions

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]

sales chat
sales chat