MOEA
Contents
MOEA#
This section is an example for MultiObjective Optimization using Evolutionary Algorithm
!wget https://raw.githubusercontent.com/cfteach/modules/master/detector2.py
!pip install pymoo
!pip install plotly
!pip install ipyvolume
!pip install altair
%load_ext autoreload
%autoreload 2
import ipyvolume as ipv
import ipywidgets as widgets
from IPython.display import display, Math, Latex
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#import AI4NP_detector_opt.sol2.detector2 as detector2
import detector2
import re
import pickle
import dill
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.core.problem import Problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
from pymoo.factory import get_visualization, get_decomposition
from pymoo.util.display import Display
from pymoo.factory import get_performance_indicator
from pymoo.factory import get_decision_making, get_reference_directions
from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting
Create detector geometry and simulate tracks#
The module detector creates a simple 2D geometry of a wire based tracker made by 4 planes.
The adjustable parameters are the radius of each wire, the pitch (along the y axis), and the shift along y and z of a plane with respect to the previous one.
A total of 8 parameters can be tuned.
The goal of this toy model, is to tune the detector design so to optimize the efficiency (fraction of tracks which are detected) as well as the cost for its realization. As a proxy for the cost, we use the material/volume (the surface in 2D) of the detector. For a track to be detetected, in the efficiency definition we require at least two wires hit by the track.
So we want to maximize the efficiency (defined in detector.py) and minimize the cost.
LIST OF PARAMETERS#
(baseline values)
R = .5 [cm]
pitch = 4.0 [cm]
y1 = 0.0, y2 = 0.0, y3 = 0.0, z1 = 2.0, z2 = 4.0, z3 = 6.0 [cm]
# CONSTANT PARAMETERS
#------ define mother region ------#
y_min=-10.1
y_max=10.1
N_tracks = 1000
print("::::: BASELINE PARAMETERS :::::")
R = .5
pitch = 4.0
y1 = 0.0
y2 = 0.0
y3 = 0.0
z1 = 2.0
z2 = 4.0
z3 = 6.0
print("R, pitch, y1, y2, y3, z1, z2, z3: ", R, pitch, y1, y2, y3, z1, z2, z3,"\n")
#------------- GEOMETRY ---------------#
print(":::: INITIAL GEOMETRY ::::")
tr = detector2.Tracker(R, pitch, y1, y2, y3, z1, z2, z3)
Z, Y = tr.create_geometry()
num_wires = detector2.calculate_wires(Y, y_min, y_max)
volume = detector2.wires_volume(Y, y_min, y_max,R)
detector2.geometry_display(Z, Y, R, y_min=y_min, y_max=y_max,block=False,pause=5) #5
print("# of wires: ", num_wires, ", volume: ", volume)
#------------- TRACK GENERATION -----------#
print(":::: TRACK GENERATION ::::")
t = detector2.Tracks(b_min=y_min, b_max=y_max, alpha_mean=0, alpha_std=0.2)
tracks = t.generate(N_tracks)
detector2.geometry_display(Z, Y, R, y_min=y_min, y_max=y_max,block=False, pause=-1)
detector2.tracks_display(tracks, Z,block=False,pause=-1)
#a track is detected if at least two wires have been hit
score = detector2.get_score(Z, Y, tracks, R)
frac_detected = score[0]
resolution = score[1]
print("fraction of tracks detected: ",frac_detected)
print("resolution: ",resolution)
::::: BASELINE PARAMETERS :::::
R, pitch, y1, y2, y3, z1, z2, z3: 0.5 4.0 0.0 0.0 0.0 2.0 4.0 6.0
:::: INITIAL GEOMETRY ::::
# of wires: 20 , volume: 62.800000000000004
:::: TRACK GENERATION ::::
fraction of tracks detected: 0.264
resolution: 0.24613882479204957
Define Objectives#
Defines a class for the objectives of the problem that can be used in the MOO.
class objectives():
def __init__(self,tracks,y_min,y_max):
self.tracks = tracks
self.y_min = y_min
self.y_max = y_max
def wrapper_geometry(fun):
def inner(self):
R, pitch, y1, y2, y3, z1, z2, z3 = self.X
self.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
return fun(self)
return inner
def update_tracks(self, new_tracks):
self.tracks = new_tracks
def update_design_point(self,X):
self.X = X
def geometry(self,R, pitch, y1, y2, y3, z1, z2, z3):
tr = detector2.Tracker(R, pitch, y1, y2, y3, z1, z2, z3)
self.R = R
self.Z, self.Y = tr.create_geometry()
@wrapper_geometry
def calc_score(self):
res = detector2.get_score(self.Z, self.Y, self.tracks, self.R)
assert res[0] >= 0 and res[1] >= 0,"Fraction or Resolution negative."
return res
def get_score(self,X):
R, pitch, y1, y2, y3, z1, z2, z3 = X
self.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
res = detector2.get_score(self.Z, self.Y, self.tracks, self.R)
return res
def get_volume(self):
volume = detector2.wires_volume(self.Y, self.y_min, self.y_max,self.R)
return volume
res = objectives(tracks,y_min,y_max)
#res.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
X = R, pitch, y1, y2, y3, z1, z2, z3
#fscore = res.get_score(X)
res.update_design_point(X)
fscore = res.calc_score()[0]
fvolume = res.get_volume()
print("...check: ", fvolume, fscore)
...check: 62.800000000000004 0.264
Multi-Objective Optimization#
We will be using pymoo (https://pymoo.org/getting_started.html).
In the constructor method we specify number of variables N, objectives M, and constraint functions, as well as the lower and upper boundaries of each variable. In our toy model, these boundaries are taken in such a way that all solutions are feasible and no constraint function is needed. You can try to change this and introduce some constraint.
The _evaluate method takes a one-dimensional NumPy array x number of entries equal to n_var. This behavior is enabled by setting elementwise_evaluation=True while calling the super() method.
Notice that every function is minimized. Our efficiency is defined as an tracking inefficiency = 1 - efficiency
We add the resolution as a third objective. The average residual of the track hit from the wire centre is used as a proxy for the resolution for this toy-model
from pymoo.core.problem import ElementwiseProblem
class MyProblem(ElementwiseProblem):
#--------- vectorized ---------#
def __init__(self):
super().__init__(n_var=8,
n_obj=3, #<------------
n_constr=0,
xl=np.array([0.5,2.5,0.,0.,0.,2.,2.,2.]),
xu=np.array([1.0,5.0,4.,4.,4.,10.,10.,10.]))
def _evaluate(self, x, out, *args, **kwargs):
f1 = 1.-res.get_score(x)[0]
f2 = res.get_volume()
f3 = res.get_score(x)[1]
out["F"] = [f1, f2, f3]
Creation of Problem and choice of optimization algorithm.#
We will use NSGA-II, as explained in the lectures. You can decide the population size and the number of offsprings, based on what we discussed.
Pymoo offers different algorithms that can be used which are highly customizable and can be easily extended. https://pymoo.org/algorithms/index.html
Before dealing with a problem, it’s useful to compare with a list of test problems reported in https://pymoo.org/problems/index.html, where different scenarios in terms of Variables, Objectives, Constraints are described.
problem = MyProblem()
algorithm = NSGA2(pop_size=100,n_offsprings=20) #n_offsprings=10
res = minimize(problem,
algorithm,
("n_gen", 500),
verbose=True,
seed=1,
save_history=True)
=======================================================
n_gen | n_eval | n_nds | eps | indicator
=======================================================
1 | 100 | 18 | - | -
2 | 120 | 23 | 0.060606061 | ideal
3 | 140 | 24 | 0.005479452 | ideal
4 | 160 | 30 | 0.015591598 | f
5 | 180 | 33 | 0.010882192 | f
6 | 200 | 33 | 0.047701144 | ideal
7 | 220 | 40 | 0.014804845 | ideal
8 | 240 | 40 | 0.005354752 | ideal
9 | 260 | 43 | 0.014511873 | ideal
10 | 280 | 42 | 0.005249344 | ideal
11 | 300 | 41 | 0.003791277 | f
12 | 320 | 47 | 0.009923126 | f
13 | 340 | 50 | 0.005221932 | ideal
14 | 360 | 48 | 0.004564563 | f
15 | 380 | 48 | 0.009994316 | ideal
16 | 400 | 51 | 0.001948492 | f
17 | 420 | 54 | 0.011950084 | nadir
18 | 440 | 56 | 0.002995010 | f
19 | 460 | 53 | 0.025940337 | nadir
20 | 480 | 55 | 0.004359628 | f
21 | 500 | 57 | 0.002878162 | f
22 | 520 | 58 | 0.010269576 | ideal
23 | 540 | 65 | 0.006377551 | nadir
24 | 560 | 72 | 0.008849558 | nadir
25 | 580 | 75 | 0.002231464 | f
26 | 600 | 79 | 0.001173671 | f
27 | 620 | 81 | 0.001681010 | f
28 | 640 | 81 | 0.002534854 | nadir
29 | 660 | 82 | 0.003305912 | f
30 | 680 | 88 | 0.014981273 | ideal
31 | 700 | 93 | 0.001176990 | f
32 | 720 | 97 | 0.004962779 | nadir
33 | 740 | 97 | 0.001053223 | f
34 | 760 | 97 | 0.001710659 | f
35 | 780 | 97 | 0.001353161 | f
36 | 800 | 100 | 0.001899862 | f
37 | 820 | 100 | 0.013463892 | ideal
38 | 840 | 100 | 0.001969711 | f
39 | 860 | 100 | 0.001044084 | f
40 | 880 | 100 | 0.001728638 | f
41 | 900 | 100 | 0.015453495 | ideal
42 | 920 | 100 | 0.000973316 | f
43 | 940 | 100 | 0.001225701 | f
44 | 960 | 97 | 0.008781198 | nadir
45 | 980 | 98 | 0.002872938 | f
46 | 1000 | 99 | 0.002182545 | f
47 | 1020 | 100 | 0.026329000 | nadir
48 | 1040 | 100 | 0.001506978 | f
49 | 1060 | 100 | 0.001926131 | f
50 | 1080 | 100 | 0.003658537 | ideal
51 | 1100 | 100 | 0.045722526 | nadir
52 | 1120 | 100 | 0.000582946 | f
53 | 1140 | 100 | 0.031735857 | ideal
54 | 1160 | 100 | 0.001152865 | f
55 | 1180 | 100 | 0.000557773 | f
56 | 1200 | 100 | 0.004848485 | ideal
57 | 1220 | 100 | 0.059564202 | nadir
58 | 1240 | 100 | 0.005326781 | nadir
59 | 1260 | 100 | 0.000661136 | f
60 | 1280 | 100 | 0.000865983 | f
61 | 1300 | 100 | 0.001660212 | f
62 | 1320 | 100 | 0.000882659 | f
63 | 1340 | 100 | 0.010579421 | nadir
64 | 1360 | 100 | 0.000562982 | f
65 | 1380 | 100 | 0.001184569 | f
66 | 1400 | 100 | 0.001158106 | f
67 | 1420 | 100 | 0.000823965 | f
68 | 1440 | 100 | 0.001255386 | f
69 | 1460 | 100 | 0.000587375 | f
70 | 1480 | 100 | 0.009401108 | nadir
71 | 1500 | 98 | 0.000822356 | f
72 | 1520 | 99 | 0.001016247 | f
73 | 1540 | 100 | 0.001219319 | f
74 | 1560 | 100 | 0.000965244 | f
75 | 1580 | 100 | 0.000392902 | f
76 | 1600 | 100 | 0.000733493 | f
77 | 1620 | 100 | 0.003267623 | nadir
78 | 1640 | 100 | 0.001190971 | f
79 | 1660 | 98 | 0.000639287 | f
80 | 1680 | 100 | 0.000601419 | f
81 | 1700 | 100 | 0.000781317 | f
82 | 1720 | 95 | 0.122116689 | nadir
83 | 1740 | 97 | 0.000304212 | f
84 | 1760 | 96 | 0.076691432 | nadir
85 | 1780 | 98 | 0.000489460 | f
86 | 1800 | 100 | 0.000784106 | f
87 | 1820 | 100 | 0.000958987 | f
88 | 1840 | 97 | 0.000615789 | f
89 | 1860 | 100 | 0.001102105 | f
90 | 1880 | 92 | 0.000800129 | f
91 | 1900 | 96 | 0.001038195 | f
92 | 1920 | 96 | 0.000559711 | f
93 | 1940 | 98 | 0.000990975 | f
94 | 1960 | 100 | 0.000546921 | f
95 | 1980 | 100 | 0.001003704 | f
96 | 2000 | 100 | 0.000779554 | f
97 | 2020 | 100 | 0.000301777 | f
98 | 2040 | 100 | 0.000259450 | f
99 | 2060 | 100 | 0.000860308 | f
100 | 2080 | 100 | 0.000382423 | f
101 | 2100 | 100 | 0.000660467 | f
102 | 2120 | 98 | 0.000206990 | f
103 | 2140 | 99 | 0.000349985 | f
104 | 2160 | 100 | 0.000287059 | f
105 | 2180 | 100 | 0.000163211 | f
106 | 2200 | 100 | 0.000345664 | f
107 | 2220 | 100 | 0.000696205 | f
108 | 2240 | 100 | 0.000555697 | f
109 | 2260 | 100 | 0.000605353 | f
110 | 2280 | 100 | 0.000299281 | f
111 | 2300 | 100 | 0.000657091 | f
112 | 2320 | 100 | 0.000214363 | f
113 | 2340 | 100 | 0.000450088 | f
114 | 2360 | 98 | 0.059234117 | nadir
115 | 2380 | 100 | 0.001169622 | f
116 | 2400 | 100 | 0.001126468 | f
117 | 2420 | 100 | 0.000339740 | f
118 | 2440 | 100 | 0.000487355 | f
119 | 2460 | 100 | 0.000434009 | f
120 | 2480 | 100 | 0.000715316 | f
121 | 2500 | 100 | 0.000842087 | f
122 | 2520 | 100 | 0.000529245 | f
123 | 2540 | 100 | 0.000561446 | f
124 | 2560 | 100 | 0.000821567 | f
125 | 2580 | 100 | 0.001528654 | f
126 | 2600 | 100 | 0.000960449 | f
127 | 2620 | 100 | 0.001113142 | f
128 | 2640 | 100 | 0.004389256 | ideal
129 | 2660 | 100 | 0.000936717 | f
130 | 2680 | 98 | 0.002228817 | f
131 | 2700 | 95 | 0.000948385 | f
132 | 2720 | 100 | 0.000999771 | f
133 | 2740 | 100 | 0.006114298 | nadir
134 | 2760 | 100 | 0.000976144 | f
135 | 2780 | 100 | 0.000218638 | f
136 | 2800 | 100 | 0.137689615 | nadir
137 | 2820 | 100 | 0.000357287 | f
138 | 2840 | 100 | 0.000027469 | f
139 | 2860 | 100 | 0.000678869 | f
140 | 2880 | 100 | 0.000821152 | f
141 | 2900 | 100 | 0.002508369 | ideal
142 | 2920 | 100 | 0.001649835 | f
143 | 2940 | 100 | 0.000739590 | f
144 | 2960 | 100 | 0.001300933 | f
145 | 2980 | 94 | 0.001000068 | f
146 | 3000 | 95 | 0.000491503 | f
147 | 3020 | 100 | 0.000746663 | f
148 | 3040 | 100 | 0.037484885 | nadir
149 | 3060 | 100 | 0.001116515 | f
150 | 3080 | 100 | 0.000691219 | f
151 | 3100 | 98 | 0.001136365 | f
152 | 3120 | 98 | 0.000701043 | f
153 | 3140 | 100 | 0.001243052 | f
154 | 3160 | 97 | 0.001265149 | f
155 | 3180 | 99 | 0.001057048 | f
156 | 3200 | 99 | 0.000948989 | f
157 | 3220 | 100 | 0.000507667 | f
158 | 3240 | 100 | 0.000634130 | f
159 | 3260 | 96 | 0.000764077 | f
160 | 3280 | 100 | 0.001434286 | f
161 | 3300 | 100 | 0.003614458 | nadir
162 | 3320 | 100 | 0.000314912 | f
163 | 3340 | 100 | 0.001283948 | f
164 | 3360 | 93 | 0.000842965 | f
165 | 3380 | 96 | 0.000581135 | f
166 | 3400 | 96 | 0.000643122 | f
167 | 3420 | 99 | 0.000726525 | f
168 | 3440 | 100 | 0.000976851 | f
169 | 3460 | 100 | 0.001147808 | f
170 | 3480 | 100 | 0.001521815 | f
171 | 3500 | 100 | 0.000340853 | f
172 | 3520 | 100 | 0.000424019 | f
173 | 3540 | 100 | 0.001979869 | f
174 | 3560 | 100 | 0.001457661 | f
175 | 3580 | 100 | 0.000895635 | f
176 | 3600 | 100 | 0.000766665 | f
177 | 3620 | 100 | 0.001948360 | f
178 | 3640 | 100 | 0.000381111 | f
179 | 3660 | 100 | 0.001230465 | f
180 | 3680 | 100 | 0.053976580 | nadir
181 | 3700 | 100 | 0.000675371 | f
182 | 3720 | 100 | 0.021201413 | nadir
183 | 3740 | 100 | 0.000637638 | f
184 | 3760 | 100 | 0.107461451 | nadir
185 | 3780 | 100 | 0.000778096 | f
186 | 3800 | 100 | 0.000726960 | f
187 | 3820 | 100 | 0.000811258 | f
188 | 3840 | 100 | 0.042358757 | nadir
189 | 3860 | 100 | 0.000328828 | f
190 | 3880 | 100 | 0.000471843 | f
191 | 3900 | 100 | 0.001097256 | f
192 | 3920 | 99 | 0.001193984 | f
193 | 3940 | 100 | 0.000495944 | f
194 | 3960 | 100 | 0.001160362 | f
195 | 3980 | 100 | 0.021024416 | nadir
196 | 4000 | 100 | 0.000784220 | f
197 | 4020 | 100 | 0.000304064 | f
198 | 4040 | 100 | 0.001032753 | f
199 | 4060 | 100 | 0.073122905 | nadir
200 | 4080 | 100 | 0.000188457 | f
201 | 4100 | 100 | 0.000888685 | f
202 | 4120 | 100 | 0.000909739 | f
203 | 4140 | 100 | 0.000107857 | f
204 | 4160 | 100 | 0.001226552 | f
205 | 4180 | 100 | 0.000427102 | f
206 | 4200 | 100 | 0.000758752 | f
207 | 4220 | 100 | 0.000823454 | f
208 | 4240 | 100 | 0.000442841 | f
209 | 4260 | 100 | 0.000501230 | f
210 | 4280 | 100 | 0.000731034 | f
211 | 4300 | 100 | 0.000842652 | f
212 | 4320 | 100 | 0.000694503 | f
213 | 4340 | 100 | 0.001207483 | f
214 | 4360 | 99 | 0.000500356 | f
215 | 4380 | 100 | 0.019669880 | nadir
216 | 4400 | 100 | 0.000452047 | f
217 | 4420 | 100 | 0.020064548 | nadir
218 | 4440 | 100 | 0.001059340 | f
219 | 4460 | 100 | 0.000823949 | f
220 | 4480 | 100 | 0.000757838 | f
221 | 4500 | 100 | 0.000279271 | f
222 | 4520 | 100 | 0.000811291 | f
223 | 4540 | 100 | 0.000990428 | f
224 | 4560 | 100 | 0.006368620 | nadir
225 | 4580 | 100 | 0.000708305 | f
226 | 4600 | 100 | 0.000171082 | f
227 | 4620 | 100 | 0.000587708 | f
228 | 4640 | 100 | 0.000177181 | f
229 | 4660 | 100 | 0.000511301 | f
230 | 4680 | 100 | 0.000459558 | f
231 | 4700 | 100 | 0.000975762 | f
232 | 4720 | 100 | 0.000672124 | f
233 | 4740 | 100 | 0.000613319 | f
234 | 4760 | 100 | 0.001584025 | f
235 | 4780 | 100 | 0.000226302 | f
236 | 4800 | 100 | 0.000400640 | f
237 | 4820 | 100 | 0.000881828 | f
238 | 4840 | 100 | 0.000330251 | f
239 | 4860 | 100 | 0.000816243 | f
240 | 4880 | 100 | 0.000448049 | f
241 | 4900 | 100 | 0.000783455 | f
242 | 4920 | 100 | 0.000656175 | f
243 | 4940 | 100 | 0.000807686 | f
244 | 4960 | 100 | 0.000808847 | f
245 | 4980 | 100 | 0.000409731 | f
246 | 5000 | 100 | 0.000619882 | f
247 | 5020 | 100 | 0.000723134 | f
248 | 5040 | 100 | 0.000986554 | f
249 | 5060 | 100 | 0.000706122 | f
250 | 5080 | 100 | 0.000736364 | f
251 | 5100 | 100 | 0.000753179 | f
252 | 5120 | 100 | 0.000577701 | f
253 | 5140 | 100 | 0.000979913 | f
254 | 5160 | 100 | 0.000594743 | f
255 | 5180 | 100 | 0.000234516 | f
256 | 5200 | 100 | 0.000940966 | f
257 | 5220 | 100 | 0.000523114 | f
258 | 5240 | 100 | 0.000485342 | f
259 | 5260 | 100 | 0.001094789 | f
260 | 5280 | 100 | 0.000345976 | f
261 | 5300 | 100 | 0.000549822 | f
262 | 5320 | 100 | 0.000460264 | f
263 | 5340 | 100 | 0.000553710 | f
264 | 5360 | 100 | 0.000904993 | f
265 | 5380 | 100 | 0.000837525 | f
266 | 5400 | 100 | 0.000724272 | f
267 | 5420 | 100 | 0.000345929 | f
268 | 5440 | 100 | 0.001799982 | f
269 | 5460 | 100 | 0.000686947 | f
270 | 5480 | 100 | 0.000708909 | f
271 | 5500 | 100 | 0.000647892 | f
272 | 5520 | 98 | 0.001589624 | f
273 | 5540 | 100 | 0.000402986 | f
274 | 5560 | 100 | 0.000761791 | f
275 | 5580 | 100 | 0.000459431 | f
276 | 5600 | 100 | 0.000933269 | f
277 | 5620 | 100 | 0.000822857 | f
278 | 5640 | 100 | 0.000982144 | f
279 | 5660 | 100 | 0.000667880 | f
280 | 5680 | 100 | 0.000487947 | f
281 | 5700 | 100 | 0.000841709 | f
282 | 5720 | 100 | 0.000623327 | f
283 | 5740 | 100 | 0.000857315 | f
284 | 5760 | 100 | 0.001310954 | f
285 | 5780 | 100 | 0.000154190 | f
286 | 5800 | 100 | 0.001077828 | f
287 | 5820 | 100 | 0.000710870 | f
288 | 5840 | 100 | 0.001255673 | f
289 | 5860 | 100 | 0.000295909 | f
290 | 5880 | 100 | 0.000185719 | f
291 | 5900 | 100 | 0.000317480 | f
292 | 5920 | 100 | 0.000918314 | f
293 | 5940 | 100 | 0.000868771 | f
294 | 5960 | 100 | 0.000989706 | f
295 | 5980 | 100 | 0.000549612 | f
296 | 6000 | 100 | 0.000681666 | f
297 | 6020 | 100 | 0.000337687 | f
298 | 6040 | 100 | 0.000731385 | f
299 | 6060 | 100 | 0.001404449 | f
300 | 6080 | 100 | 0.000701937 | f
301 | 6100 | 100 | 0.000679543 | f
302 | 6120 | 100 | 0.000528722 | f
303 | 6140 | 100 | 0.000460163 | f
304 | 6160 | 100 | 0.000561215 | f
305 | 6180 | 100 | 0.000688570 | f
306 | 6200 | 100 | 0.000801894 | f
307 | 6220 | 100 | 0.000893508 | f
308 | 6240 | 100 | 0.000311220 | f
309 | 6260 | 100 | 0.001313793 | f
310 | 6280 | 100 | 0.000440326 | f
311 | 6300 | 100 | 0.000695100 | f
312 | 6320 | 100 | 0.000813016 | f
313 | 6340 | 100 | 0.000622768 | f
314 | 6360 | 100 | 0.000784734 | f
315 | 6380 | 100 | 0.000926269 | f
316 | 6400 | 100 | 0.005290653 | ideal
317 | 6420 | 100 | 0.000688227 | f
318 | 6440 | 100 | 0.000433189 | f
319 | 6460 | 100 | 0.000778103 | f
320 | 6480 | 100 | 0.000029716 | f
321 | 6500 | 100 | 0.000448141 | f
322 | 6520 | 100 | 0.000519426 | f
323 | 6540 | 100 | 0.000930921 | f
324 | 6560 | 100 | 0.000770095 | f
325 | 6580 | 100 | 0.000172124 | f
326 | 6600 | 100 | 0.000624719 | f
327 | 6620 | 100 | 0.000214232 | f
328 | 6640 | 100 | 0.000310066 | f
329 | 6660 | 100 | 0.000428408 | f
330 | 6680 | 100 | 0.000343301 | f
331 | 6700 | 100 | 0.001321234 | f
332 | 6720 | 100 | 0.000312082 | f
333 | 6740 | 100 | 0.000235000 | f
334 | 6760 | 100 | 0.001015909 | f
335 | 6780 | 100 | 0.000303460 | f
336 | 6800 | 100 | 0.000938002 | f
337 | 6820 | 100 | 0.000210448 | f
338 | 6840 | 100 | 0.000011747 | f
339 | 6860 | 100 | 0.000641002 | f
340 | 6880 | 100 | 0.000724896 | f
341 | 6900 | 100 | 0.000484753 | f
342 | 6920 | 100 | 0.000737436 | f
343 | 6940 | 100 | 0.000327627 | f
344 | 6960 | 100 | 0.001450300 | f
345 | 6980 | 100 | 0.000453762 | f
346 | 7000 | 100 | 0.000942305 | f
347 | 7020 | 100 | 0.000257252 | f
348 | 7040 | 100 | 0.000536342 | f
349 | 7060 | 100 | 0.000025764 | f
350 | 7080 | 100 | 0.003191720 | nadir
351 | 7100 | 100 | 0.000797608 | f
352 | 7120 | 100 | 0.000495855 | f
353 | 7140 | 100 | 0.000274419 | f
354 | 7160 | 100 | 0.000743158 | f
355 | 7180 | 100 | 0.010180697 | nadir
356 | 7200 | 100 | 0.010156969 | nadir
357 | 7220 | 100 | 0.000376654 | f
358 | 7240 | 100 | 0.000509267 | f
359 | 7260 | 100 | 0.000986011 | f
360 | 7280 | 100 | 0.000781868 | f
361 | 7300 | 100 | 0.000963385 | f
362 | 7320 | 100 | 0.000252878 | f
363 | 7340 | 100 | 0.000293268 | f
364 | 7360 | 100 | 0.000439788 | f
365 | 7380 | 100 | 0.000477854 | f
366 | 7400 | 100 | 0.000604061 | f
367 | 7420 | 100 | 0.000149081 | f
368 | 7440 | 100 | 0.000292162 | f
369 | 7460 | 100 | 0.000252922 | f
370 | 7480 | 100 | 0.002218235 | f
371 | 7500 | 100 | 0.000544093 | f
372 | 7520 | 100 | 0.015028902 | nadir
373 | 7540 | 100 | 0.000432405 | f
374 | 7560 | 100 | 0.015240328 | nadir
375 | 7580 | 100 | 0.000366533 | f
376 | 7600 | 100 | 0.001016458 | f
377 | 7620 | 100 | 0.000263883 | f
378 | 7640 | 100 | 0.000691629 | f
379 | 7660 | 100 | 0.000278018 | f
380 | 7680 | 100 | 0.000507566 | f
381 | 7700 | 100 | 0.000536655 | f
382 | 7720 | 100 | 0.001247906 | f
383 | 7740 | 100 | 0.000167869 | f
384 | 7760 | 100 | 0.000382613 | f
385 | 7780 | 100 | 0.006281746 | nadir
386 | 7800 | 100 | 0.000101172 | f
387 | 7820 | 100 | 0.000919632 | f
388 | 7840 | 100 | 0.000364123 | f
389 | 7860 | 100 | 0.000659702 | f
390 | 7880 | 100 | 0.000712256 | f
391 | 7900 | 100 | 0.000463364 | f
392 | 7920 | 100 | 0.000385390 | f
393 | 7940 | 100 | 0.000213541 | f
394 | 7960 | 100 | 0.000119071 | f
395 | 7980 | 100 | 0.000682622 | f
396 | 8000 | 100 | 0.000509774 | f
397 | 8020 | 100 | 0.000560552 | f
398 | 8040 | 100 | 0.001047960 | f
399 | 8060 | 100 | 0.000248306 | f
400 | 8080 | 100 | 0.000385527 | f
401 | 8100 | 100 | 0.000092919 | f
402 | 8120 | 100 | 0.000919471 | f
403 | 8140 | 100 | 0.000481338 | f
404 | 8160 | 100 | 0.000489613 | f
405 | 8180 | 100 | 0.000854553 | f
406 | 8200 | 100 | 0.000451107 | f
407 | 8220 | 100 | 0.000447243 | f
408 | 8240 | 100 | 0.000266780 | f
409 | 8260 | 100 | 0.000972743 | f
410 | 8280 | 100 | 0.000751167 | f
411 | 8300 | 100 | 0.000546767 | f
412 | 8320 | 100 | 0.000998969 | f
413 | 8340 | 100 | 0.000935105 | f
414 | 8360 | 100 | 0.000423563 | f
415 | 8380 | 100 | 0.001109087 | f
416 | 8400 | 100 | 0.025240385 | nadir
417 | 8420 | 100 | 0.000192172 | f
418 | 8440 | 100 | 0.000596428 | f
419 | 8460 | 100 | 0.000764286 | f
420 | 8480 | 100 | 0.000154335 | f
421 | 8500 | 100 | 0.000544750 | f
422 | 8520 | 100 | 0.000586355 | f
423 | 8540 | 100 | 0.001222310 | f
424 | 8560 | 100 | 0.000286514 | f
425 | 8580 | 100 | 0.000415359 | f
426 | 8600 | 100 | 0.014855020 | ideal
427 | 8620 | 100 | 0.003256856 | ideal
428 | 8640 | 100 | 0.000167060 | f
429 | 8660 | 100 | 0.000316712 | f
430 | 8680 | 100 | 0.000507912 | f
431 | 8700 | 100 | 0.000460628 | f
432 | 8720 | 100 | 0.000324049 | f
433 | 8740 | 100 | 0.000722018 | f
434 | 8760 | 100 | 0.000473630 | f
435 | 8780 | 100 | 0.001393554 | f
436 | 8800 | 100 | 0.001461250 | f
437 | 8820 | 100 | 0.000782093 | f
438 | 8840 | 100 | 0.000521061 | f
439 | 8860 | 100 | 0.000324151 | f
440 | 8880 | 100 | 0.001411808 | f
441 | 8900 | 100 | 0.001224727 | f
442 | 8920 | 100 | 0.000750489 | f
443 | 8940 | 100 | 0.001032756 | f
444 | 8960 | 100 | 0.000651918 | f
445 | 8980 | 100 | 0.000490226 | f
446 | 9000 | 100 | 0.000583000 | f
447 | 9020 | 100 | 0.000364665 | f
448 | 9040 | 100 | 0.000909428 | f
449 | 9060 | 100 | 0.000415654 | f
450 | 9080 | 100 | 0.001113354 | f
451 | 9100 | 100 | 0.000567151 | f
452 | 9120 | 100 | 0.000833758 | f
453 | 9140 | 100 | 0.000741335 | f
454 | 9160 | 100 | 0.001243914 | f
455 | 9180 | 100 | 0.000682354 | f
456 | 9200 | 100 | 0.001013863 | f
457 | 9220 | 100 | 0.001196714 | f
458 | 9240 | 100 | 0.000703129 | f
459 | 9260 | 100 | 0.000256003 | f
460 | 9280 | 100 | 0.000461510 | f
461 | 9300 | 100 | 0.000947500 | f
462 | 9320 | 100 | 0.000578778 | f
463 | 9340 | 100 | 0.000319514 | f
464 | 9360 | 100 | 0.000245729 | f
465 | 9380 | 100 | 0.000937210 | f
466 | 9400 | 100 | 0.000544928 | f
467 | 9420 | 100 | 0.000264998 | f
468 | 9440 | 100 | 0.000557535 | f
469 | 9460 | 100 | 0.000467677 | f
470 | 9480 | 100 | 0.000971584 | f
471 | 9500 | 100 | 0.000859148 | f
472 | 9520 | 100 | 0.000508178 | f
473 | 9540 | 100 | 0.000973854 | f
474 | 9560 | 100 | 0.000668919 | f
475 | 9580 | 100 | 0.001406928 | f
476 | 9600 | 100 | 0.000857123 | f
477 | 9620 | 100 | 0.001532952 | f
478 | 9640 | 99 | 0.001197693 | f
479 | 9660 | 100 | 0.042577675 | nadir
480 | 9680 | 100 | 0.000555370 | f
481 | 9700 | 100 | 0.000486215 | f
482 | 9720 | 100 | 0.000735920 | f
483 | 9740 | 100 | 0.000715867 | f
484 | 9760 | 100 | 0.000403358 | f
485 | 9780 | 100 | 0.001108298 | f
486 | 9800 | 100 | 0.000232343 | f
487 | 9820 | 100 | 0.000815201 | f
488 | 9840 | 100 | 0.000713803 | f
489 | 9860 | 100 | 0.000502301 | f
490 | 9880 | 100 | 0.000827421 | f
491 | 9900 | 100 | 0.000830072 | f
492 | 9920 | 100 | 0.001080234 | f
493 | 9940 | 100 | 0.000121988 | f
494 | 9960 | 100 | 0.000303076 | f
495 | 9980 | 100 | 0.000538624 | f
496 | 10000 | 100 | 0.000017164 | f
497 | 10020 | 100 | 0.000399657 | f
498 | 10040 | 100 | 0.000217668 | f
499 | 10060 | 100 | 0.000859524 | f
500 | 10080 | 100 | 0.001315360 | f
Analysis of Results#
import plotly.express as px
fig = px.scatter_3d(x = res.F[:, 0], y = res.F[:, 1], z = res.F[:, 2], labels={
"x": "InEfficiency",
"y": "Volume",
"z": "Resolution"
},width = 800, height = 800, title = "Final Call feasible solutions")
fig.update_traces(marker=dict(size=8,
line=dict(width=2,
color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.show()
# Making a animation of evolution
import pandas as pd
obj1 = []
obj2 = []
obj3 = []
calls = []
for r in res.history:
objs = r.pop.get("F")
obj1.extend(objs[:, 0])
obj2.extend(objs[:, 1])
obj3.extend(objs[:, 2])
calls.extend([r.n_gen]*len(objs))
df = pd.DataFrame(data = {"InEfficiency": obj1, "Volume": obj2,
"Resolution": obj3, "n_gen": calls})
obj_fig = px.scatter_3d(df, x="InEfficiency", y="Volume", z = "Resolution",
animation_frame="n_gen", color="n_gen",
range_x=[0., 0.6], range_y=[0. , 400.], range_z=[0., 0.6],
hover_data = df.columns,
width = 800, height = 800)
obj_fig.update(layout_coloraxis_showscale=False)
obj_fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 10
obj_fig.update_layout(transition = {'duration': 0.001})
obj_fig.show()
len(res.F[:,0])
55
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (12, 10))
ax = fig.add_subplot(projection='3d')
ax.scatter(res.F[:, 0], res.F[:, 1], res.F[:, 2], marker = "o", s = 55)
ax.set_xlabel('Ineff', fontsize = 15)
ax.set_ylabel('Vol', fontsize = 15)
ax.set_zlabel('Res', fontsize = 15)
plt.show()
Exercise 3#
Determine the Pareto set from the 3D front and choose an optimal point
Plot the optimal configuration of the tracker corresponding to that point
Do analysis of convergence
Visualize the point with a radar or petal diagram, following https://pymoo.org/visualization/index.html