(Tut 2 - part a) AI-assisted design with MOEA#

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
--2023-06-14 15:45:04--  https://raw.githubusercontent.com/cfteach/modules/master/detector2.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7976 (7.8K) [text/plain]
Saving to: ‘detector2.py’


detector2.py          0%[                    ]       0  --.-KB/s               
detector2.py        100%[===================>]   7.79K  --.-KB/s    in 0s      

2023-06-14 15:45:04 (55.4 MB/s) - ‘detector2.py’ saved [7976/7976]

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting pymoo
  Downloading pymoo-0.6.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 MB 18.4 MB/s eta 0:00:00
?25hRequirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.10/dist-packages (from pymoo) (1.22.4)
Requirement already satisfied: scipy>=1.1 in /usr/local/lib/python3.10/dist-packages (from pymoo) (1.10.1)
Requirement already satisfied: matplotlib>=3 in /usr/local/lib/python3.10/dist-packages (from pymoo) (3.7.1)
Requirement already satisfied: autograd>=1.4 in /usr/local/lib/python3.10/dist-packages (from pymoo) (1.5)
Collecting cma==3.2.2 (from pymoo)
  Downloading cma-3.2.2-py2.py3-none-any.whl (249 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 249.1/249.1 kB 24.4 MB/s eta 0:00:00
?25hCollecting alive-progress (from pymoo)
  Downloading alive_progress-3.1.4-py3-none-any.whl (75 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.9/75.9 kB 9.1 MB/s eta 0:00:00
?25hCollecting dill (from pymoo)
  Downloading dill-0.3.6-py3-none-any.whl (110 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 110.5/110.5 kB 13.0 MB/s eta 0:00:00
?25hCollecting Deprecated (from pymoo)
  Downloading Deprecated-1.2.14-py2.py3-none-any.whl (9.6 kB)
Requirement already satisfied: future>=0.15.2 in /usr/local/lib/python3.10/dist-packages (from autograd>=1.4->pymoo) (0.18.3)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (4.39.3)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (23.1)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (8.4.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3->pymoo) (2.8.2)
Collecting about-time==4.2.1 (from alive-progress->pymoo)
  Downloading about_time-4.2.1-py3-none-any.whl (13 kB)
Collecting grapheme==0.6.0 (from alive-progress->pymoo)
  Downloading grapheme-0.6.0.tar.gz (207 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 207.3/207.3 kB 19.4 MB/s eta 0:00:00
?25h  Preparing metadata (setup.py) ... ?25l?25hdone
Requirement already satisfied: wrapt<2,>=1.10 in /usr/local/lib/python3.10/dist-packages (from Deprecated->pymoo) (1.14.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib>=3->pymoo) (1.16.0)
Building wheels for collected packages: grapheme
  Building wheel for grapheme (setup.py) ... ?25l?25hdone
  Created wheel for grapheme: filename=grapheme-0.6.0-py3-none-any.whl size=210079 sha256=bfeb4b7863e5a19b8f4cd1a88fdfe2a537254abc28f5c4cdff09cf5ea27b831b
  Stored in directory: /root/.cache/pip/wheels/01/e1/49/37e6bde9886439057450c494a79b0bef8bbe897a54aebfc757
Successfully built grapheme
Installing collected packages: grapheme, dill, Deprecated, cma, about-time, alive-progress, pymoo
Successfully installed Deprecated-1.2.14 about-time-4.2.1 alive-progress-3.1.4 cma-3.2.2 dill-0.3.6 grapheme-0.6.0 pymoo-0.6.0.1
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (5.13.1)
Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly) (8.2.2)
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting ipyvolume
  Downloading ipyvolume-0.6.3-py3-none-any.whl (1.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 19.3 MB/s eta 0:00:00
?25hRequirement already satisfied: ipywidgets>=7.0.0 in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (7.7.1)
Collecting bqplot (from ipyvolume)
  Downloading bqplot-0.12.39-py2.py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 69.2 MB/s eta 0:00:00
?25hRequirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (1.22.4)
Collecting traittypes (from ipyvolume)
  Downloading traittypes-0.2.1-py2.py3-none-any.whl (8.6 kB)
Requirement already satisfied: traitlets in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (5.7.1)
Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (8.4.0)
Collecting ipywebrtc (from ipyvolume)
  Downloading ipywebrtc-0.6.0-py2.py3-none-any.whl (260 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 260.7/260.7 kB 22.6 MB/s eta 0:00:00
?25hRequirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (2.27.1)
Collecting ipyvuetify (from ipyvolume)
  Downloading ipyvuetify-1.8.10-py2.py3-none-any.whl (11.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.7/11.7 MB 73.4 MB/s eta 0:00:00
?25hCollecting ipyvue>=1.7.0 (from ipyvolume)
  Downloading ipyvue-1.9.1-py2.py3-none-any.whl (2.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.7/2.7 MB 71.7 MB/s eta 0:00:00
?25hCollecting pythreejs>=2.4.0 (from ipyvolume)
  Downloading pythreejs-2.4.2-py3-none-any.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 45.2 MB/s eta 0:00:00
?25hRequirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from ipyvolume) (3.7.1)
Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.0.0->ipyvolume) (5.5.6)
Requirement already satisfied: ipython-genutils~=0.2.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.0.0->ipyvolume) (0.2.0)
Requirement already satisfied: widgetsnbextension~=3.6.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.0.0->ipyvolume) (3.6.4)
Requirement already satisfied: ipython>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.0.0->ipyvolume) (7.34.0)
Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.0.0->ipyvolume) (3.0.7)
Collecting ipydatawidgets>=1.1.1 (from pythreejs>=2.4.0->ipyvolume)
  Downloading ipydatawidgets-4.3.5-py2.py3-none-any.whl (271 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 271.7/271.7 kB 21.5 MB/s eta 0:00:00
?25hRequirement already satisfied: pandas<3.0.0,>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from bqplot->ipyvolume) (1.5.3)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (4.39.3)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (23.1)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->ipyvolume) (2.8.2)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->ipyvolume) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->ipyvolume) (2022.12.7)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->ipyvolume) (2.0.12)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->ipyvolume) (3.4)
Requirement already satisfied: jupyter-client in /usr/local/lib/python3.10/dist-packages (from ipykernel>=4.5.1->ipywidgets>=7.0.0->ipyvolume) (6.1.12)
Requirement already satisfied: tornado>=4.2 in /usr/local/lib/python3.10/dist-packages (from ipykernel>=4.5.1->ipywidgets>=7.0.0->ipyvolume) (6.3.1)
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (67.7.2)
Collecting jedi>=0.16 (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume)
  Downloading jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 59.5 MB/s eta 0:00:00
?25hRequirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (4.4.2)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.7.5)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (3.0.38)
Requirement already satisfied: pygments in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (2.14.0)
Requirement already satisfied: backcall in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.2.0)
Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.1.6)
Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (4.8.0)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0.0,>=1.0.0->bqplot->ipyvolume) (2022.7.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->ipyvolume) (1.16.0)
Requirement already satisfied: notebook>=4.4.1 in /usr/local/lib/python3.10/dist-packages (from widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (6.4.8)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.8.3)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (3.1.2)
Requirement already satisfied: pyzmq>=17 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (23.2.1)
Requirement already satisfied: argon2-cffi in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (21.3.0)
Requirement already satisfied: jupyter-core>=4.6.1 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (5.3.0)
Requirement already satisfied: nbformat in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (5.8.0)
Requirement already satisfied: nbconvert in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (6.5.4)
Requirement already satisfied: nest-asyncio>=1.5 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (1.5.6)
Requirement already satisfied: Send2Trash>=1.8.0 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (1.8.0)
Requirement already satisfied: terminado>=0.8.3 in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.17.1)
Requirement already satisfied: prometheus-client in /usr/local/lib/python3.10/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.16.0)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=4.0.0->ipywidgets>=7.0.0->ipyvolume) (0.2.6)
Requirement already satisfied: platformdirs>=2.5 in /usr/local/lib/python3.10/dist-packages (from jupyter-core>=4.6.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (3.3.0)
Requirement already satisfied: argon2-cffi-bindings in /usr/local/lib/python3.10/dist-packages (from argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (21.2.0)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (2.1.2)
Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (4.9.2)
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (4.11.2)
Requirement already satisfied: bleach in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (6.0.0)
Requirement already satisfied: defusedxml in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.7.1)
Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.4)
Requirement already satisfied: jupyterlab-pygments in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.2.2)
Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.8.4)
Requirement already satisfied: nbclient>=0.5.0 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.7.4)
Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (1.5.0)
Requirement already satisfied: tinycss2 in /usr/local/lib/python3.10/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (1.2.1)
Requirement already satisfied: fastjsonschema in /usr/local/lib/python3.10/dist-packages (from nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (2.16.3)
Requirement already satisfied: jsonschema>=2.6 in /usr/local/lib/python3.10/dist-packages (from nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (4.3.3)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (23.1.0)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6->nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.19.3)
Requirement already satisfied: cffi>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from argon2-cffi-bindings->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (1.15.1)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (2.4.1)
Requirement already satisfied: webencodings in /usr/local/lib/python3.10/dist-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (0.5.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.10/dist-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->ipyvolume) (2.21)
Installing collected packages: ipywebrtc, traittypes, jedi, ipyvue, ipydatawidgets, bqplot, pythreejs, ipyvuetify, ipyvolume
Successfully installed bqplot-0.12.39 ipydatawidgets-4.3.5 ipyvolume-0.6.3 ipyvue-1.9.1 ipyvuetify-1.8.10 ipywebrtc-0.6.0 jedi-0.18.2 pythreejs-2.4.2 traittypes-0.2.1
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: altair in /usr/local/lib/python3.10/dist-packages (4.2.2)
Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair) (0.4)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from altair) (3.1.2)
Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair) (4.3.3)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from altair) (1.22.4)
Requirement already satisfied: pandas>=0.18 in /usr/local/lib/python3.10/dist-packages (from altair) (1.5.3)
Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair) (0.12.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair) (23.1.0)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair) (0.19.3)
Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.18->altair) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.18->altair) (2022.7.1)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->altair) (2.1.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas>=0.18->altair) (1.16.0)
%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.util.display.column import Column
from pymoo.util.display.output import Output

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
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

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 = 0.5
pitch = 4.0
y1 = 2.0
y2 = 1.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 2.0 1.0 0.0 2.0 4.0 6.0 

:::: INITIAL GEOMETRY ::::
# of wires:  21 , volume:  65.94
:::: TRACK GENERATION ::::
_images/exe3a_moo_EA_3obj_5_1.png _images/exe3a_moo_EA_3obj_5_2.png
fraction of tracks detected:  0.243
resolution:  0.23594329069824552

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:  65.94 0.243

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] # efficiency
        f2 = res.get_volume() # volume
        f3 = res.get_score(x)[1] #resolution

        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 |     16 |  0.0303189989 |             f
     3 |      140 |     23 |  0.0540582311 |         nadir
     4 |      160 |     28 |  0.0080526494 |             f
     5 |      180 |     28 |  0.0014589760 |             f
     6 |      200 |     30 |  0.0093351048 |         ideal
     7 |      220 |     32 |  0.0631001372 |         ideal
     8 |      240 |     31 |  0.0150500440 |         ideal
     9 |      260 |     31 |  0.0250434041 |         nadir
    10 |      280 |     36 |  0.0027359781 |         ideal
    11 |      300 |     42 |  0.0076222677 |             f
    12 |      320 |     44 |  0.0060434951 |         ideal
    13 |      340 |     48 |  0.0046069968 |         nadir
    14 |      360 |     52 |  0.0054421769 |         ideal
    15 |      380 |     53 |  0.0251046025 |         nadir
    16 |      400 |     54 |  0.0027544528 |             f
    17 |      420 |     58 |  0.0027816412 |         ideal
    18 |      440 |     63 |  0.0329490648 |         ideal
    19 |      460 |     66 |  0.0283783784 |         ideal
    20 |      480 |     73 |  0.0224570674 |         ideal
    21 |      500 |     73 |  0.0019421498 |             f
    22 |      520 |     68 |  0.0036241484 |             f
    23 |      540 |     74 |  0.0370204384 |         nadir
    24 |      560 |     67 |  0.0180057434 |         nadir
    25 |      580 |     70 |  0.0169491525 |         ideal
    26 |      600 |     70 |  0.0016470688 |             f
    27 |      620 |     77 |  0.0031819257 |             f
    28 |      640 |     80 |  0.0013290412 |             f
    29 |      660 |     88 |  0.0115979381 |         nadir
    30 |      680 |     82 |  0.0024003395 |             f
    31 |      700 |     86 |  0.0034382915 |             f
    32 |      720 |     83 |  0.0028669424 |             f
    33 |      740 |     82 |  0.0027326566 |             f
    34 |      760 |     86 |  0.0015396233 |             f
    35 |      780 |     85 |  0.0023771709 |             f
    36 |      800 |     91 |  0.0055425223 |             f
    37 |      820 |     90 |  0.0346303234 |         nadir
    38 |      840 |     95 |  0.0012312059 |             f
    39 |      860 |    100 |  0.0023053499 |             f
    40 |      880 |    100 |  0.0358726033 |         nadir
    41 |      900 |    100 |  0.0005409685 |             f
    42 |      920 |     98 |  0.0104166667 |         nadir
    43 |      940 |     99 |  0.0010798928 |             f
    44 |      960 |    100 |  0.0105623452 |         nadir
    45 |      980 |    100 |  0.0009999934 |             f
    46 |     1000 |    100 |  0.0013159659 |             f
    47 |     1020 |    100 |  0.0031293685 |             f
    48 |     1040 |     99 |  0.0730010048 |         nadir
    49 |     1060 |    100 |  0.0021192746 |             f
    50 |     1080 |    100 |  0.0035042832 |             f
    51 |     1100 |    100 |  0.0020713961 |             f
    52 |     1120 |    100 |  0.0032074560 |             f
    53 |     1140 |    100 |  0.0010195352 |             f
    54 |     1160 |    100 |  0.0014179358 |             f
    55 |     1180 |    100 |  0.0030172055 |             f
    56 |     1200 |    100 |  0.0166240409 |         nadir
    57 |     1220 |    100 |  0.0019572448 |             f
    58 |     1240 |    100 |  0.0023781100 |             f
    59 |     1260 |    100 |  0.0507338498 |         nadir
    60 |     1280 |    100 |  0.0182291667 |         nadir
    61 |     1300 |    100 |  0.0012414074 |             f
    62 |     1320 |    100 |  0.0014122545 |             f
    63 |     1340 |     97 |  0.0017297831 |             f
    64 |     1360 |    100 |  0.0558259356 |         nadir
    65 |     1380 |    100 |  0.0009082571 |             f
    66 |     1400 |    100 |  0.0316158016 |         nadir
    67 |     1420 |    100 |  0.0011466478 |             f
    68 |     1440 |    100 |  0.0016866413 |             f
    69 |     1460 |    100 |  0.0038910506 |         ideal
    70 |     1480 |    100 |  0.0002506049 |             f
    71 |     1500 |    100 |  0.0006687342 |             f
    72 |     1520 |    100 |  0.0015675267 |             f
    73 |     1540 |    100 |  0.0029567071 |             f
    74 |     1560 |    100 |  0.0007253434 |             f
    75 |     1580 |     98 |  0.0157594185 |         ideal
    76 |     1600 |    100 |  0.0010300132 |             f
    77 |     1620 |    100 |  0.0017175677 |             f
    78 |     1640 |    100 |  0.0027705912 |             f
    79 |     1660 |     95 |  0.0021199557 |             f
    80 |     1680 |     98 |  0.0161822999 |         nadir
    81 |     1700 |     98 |  0.0011450591 |             f
    82 |     1720 |    100 |  0.0027697180 |             f
    83 |     1740 |    100 |  0.0009880818 |             f
    84 |     1760 |    100 |  0.0023639014 |             f
    85 |     1780 |    100 |  0.0028080752 |             f
    86 |     1800 |    100 |  0.0014396014 |             f
    87 |     1820 |    100 |  0.0024772976 |             f
    88 |     1840 |    100 |  0.0032238254 |             f
    89 |     1860 |    100 |  0.0009297475 |             f
    90 |     1880 |    100 |  0.0021259969 |             f
    91 |     1900 |    100 |  0.0029526869 |             f
    92 |     1920 |    100 |  0.0006003235 |             f
    93 |     1940 |    100 |  0.0027961928 |             f
    94 |     1960 |    100 |  0.0007189946 |             f
    95 |     1980 |    100 |  0.0022355053 |             f
    96 |     2000 |    100 |  0.0038659794 |         ideal
    97 |     2020 |    100 |  0.0013131772 |             f
    98 |     2040 |    100 |  0.0018557844 |             f
    99 |     2060 |    100 |  0.0028751836 |             f
   100 |     2080 |    100 |  0.0005424324 |             f
   101 |     2100 |    100 |  0.0021248553 |             f
   102 |     2120 |    100 |  0.0025897701 |             f
   103 |     2140 |    100 |  0.0012109270 |             f
   104 |     2160 |    100 |  0.0020919436 |             f
   105 |     2180 |    100 |  0.1040759613 |         nadir
   106 |     2200 |    100 |  0.0006479273 |             f
   107 |     2220 |    100 |  0.0019277916 |             f
   108 |     2240 |    100 |  0.0023960677 |             f
   109 |     2260 |    100 |  0.0036251761 |             f
   110 |     2280 |    100 |  0.0148704095 |         nadir
   111 |     2300 |    100 |  0.0013670816 |             f
   112 |     2320 |     94 |  0.0023807666 |             f
   113 |     2340 |     98 |  0.0028030989 |             f
   114 |     2360 |    100 |  0.0011496819 |             f
   115 |     2380 |    100 |  0.0018590145 |             f
   116 |     2400 |    100 |  0.0028201419 |             f
   117 |     2420 |    100 |  0.0006471739 |             f
   118 |     2440 |    100 |  0.0008409826 |             f
   119 |     2460 |    100 |  0.0019335396 |             f
   120 |     2480 |    100 |  0.0026445946 |             f
   121 |     2500 |    100 |  0.0009412576 |             f
   122 |     2520 |    100 |  0.0076726343 |         ideal
   123 |     2540 |    100 |  0.0008107320 |             f
   124 |     2560 |    100 |  0.0009934158 |             f
   125 |     2580 |    100 |  0.0524226821 |         nadir
   126 |     2600 |     98 |  0.0009844465 |             f
   127 |     2620 |     98 |  0.0026966895 |             f
   128 |     2640 |    100 |  0.0008883888 |             f
   129 |     2660 |    100 |  0.0014301705 |             f
   130 |     2680 |    100 |  0.0076142132 |         nadir
   131 |     2700 |    100 |  0.0002017442 |             f
   132 |     2720 |    100 |  0.0007198007 |             f
   133 |     2740 |    100 |  0.0016718224 |             f
   134 |     2760 |    100 |  0.0026728754 |             f
   135 |     2780 |    100 |  0.0016151362 |             f
   136 |     2800 |    100 |  0.0022241025 |             f
   137 |     2820 |    100 |  0.0030336740 |             f
   138 |     2840 |    100 |  0.0050505051 |         ideal
   139 |     2860 |    100 |  0.0268714302 |         nadir
   140 |     2880 |    100 |  0.0010057140 |             f
   141 |     2900 |    100 |  0.0019137692 |             f
   142 |     2920 |     97 |  0.0038635838 |             f
   143 |     2940 |    100 |  0.0015447888 |             f
   144 |     2960 |    100 |  0.0173697270 |         nadir
   145 |     2980 |     98 |  0.0004471039 |             f
   146 |     3000 |    100 |  0.0021637838 |             f
   147 |     3020 |    100 |  0.0206561361 |         nadir
   148 |     3040 |     99 |  0.0011608718 |             f
   149 |     3060 |    100 |  0.0015154446 |             f
   150 |     3080 |    100 |  0.0026167022 |             f
   151 |     3100 |    100 |  0.0010408804 |             f
   152 |     3120 |    100 |  0.0023102329 |             f
   153 |     3140 |    100 |  0.0027312538 |             f
   154 |     3160 |    100 |  0.0008614075 |             f
   155 |     3180 |    100 |  0.0016276810 |             f
   156 |     3200 |    100 |  0.0024373391 |             f
   157 |     3220 |    100 |  0.0034422574 |             f
   158 |     3240 |    100 |  0.0001981024 |             f
   159 |     3260 |     98 |  0.0007960277 |             f
   160 |     3280 |     99 |  0.0081706265 |         nadir
   161 |     3300 |    100 |  0.0197999522 |         ideal
   162 |     3320 |    100 |  0.0008312249 |             f
   163 |     3340 |    100 |  0.0022827738 |             f
   164 |     3360 |    100 |  0.0037392494 |             f
   165 |     3380 |    100 |  0.0001308463 |             f
   166 |     3400 |    100 |  0.0007492723 |             f
   167 |     3420 |    100 |  0.0027083995 |             f
   168 |     3440 |    100 |  0.0006564686 |             f
   169 |     3460 |    100 |  0.0025567741 |             f
   170 |     3480 |    100 |  0.0007499838 |             f
   171 |     3500 |    100 |  0.0110565111 |         nadir
   172 |     3520 |    100 |  0.0001389302 |             f
   173 |     3540 |    100 |  0.0010242965 |             f
   174 |     3560 |    100 |  0.0021465934 |             f
   175 |     3580 |    100 |  0.0029918921 |             f
   176 |     3600 |    100 |  0.0014005300 |             f
   177 |     3620 |    100 |  0.0024915178 |             f
   178 |     3640 |    100 |  0.0048899756 |         ideal
   179 |     3660 |    100 |  0.0015034653 |             f
   180 |     3680 |    100 |  0.0017920622 |             f
   181 |     3700 |    100 |  0.0024183582 |             f
   182 |     3720 |    100 |  0.0027043360 |             f
   183 |     3740 |    100 |  0.0007089840 |             f
   184 |     3760 |    100 |  0.0012138966 |             f
   185 |     3780 |    100 |  0.0025570464 |             f
   186 |     3800 |    100 |  0.0008054274 |             f
   187 |     3820 |    100 |  0.0022882250 |             f
   188 |     3840 |    100 |  0.0035998474 |             f
   189 |     3860 |    100 |  0.0007140725 |             f
   190 |     3880 |    100 |  0.0017662097 |             f
   191 |     3900 |    100 |  0.0029680847 |             f
   192 |     3920 |    100 |  0.0006739590 |             f
   193 |     3940 |    100 |  0.0031285772 |             f
   194 |     3960 |    100 |  0.0005582380 |             f
   195 |     3980 |    100 |  0.0011987784 |             f
   196 |     4000 |    100 |  0.0327880220 |         nadir
   197 |     4020 |    100 |  0.0002695098 |             f
   198 |     4040 |    100 |  0.0003390425 |             f
   199 |     4060 |    100 |  0.0020008973 |             f
   200 |     4080 |    100 |  0.1062312128 |         nadir
   201 |     4100 |    100 |  0.0008695801 |             f
   202 |     4120 |    100 |  0.0019339729 |             f
   203 |     4140 |    100 |  0.0025012805 |             f
   204 |     4160 |    100 |  0.0010486630 |             f
   205 |     4180 |    100 |  0.0028622917 |             f
   206 |     4200 |    100 |  0.0007743133 |             f
   207 |     4220 |    100 |  0.0014922967 |             f
   208 |     4240 |    100 |  0.0018792328 |             f
   209 |     4260 |    100 |  0.0029315013 |             f
   210 |     4280 |    100 |  0.0011491440 |             f
   211 |     4300 |    100 |  0.0020862560 |             f
   212 |     4320 |    100 |  0.0036063690 |             f
   213 |     4340 |    100 |  0.0009308926 |             f
   214 |     4360 |    100 |  0.0017008290 |             f
   215 |     4380 |    100 |  0.0027897897 |             f
   216 |     4400 |    100 |  0.0009931574 |             f
   217 |     4420 |    100 |  0.0015084632 |             f
   218 |     4440 |    100 |  0.0031670529 |             f
   219 |     4460 |    100 |  0.0015754144 |             f
   220 |     4480 |    100 |  0.0024660479 |             f
   221 |     4500 |    100 |  0.0030874370 |             f
   222 |     4520 |    100 |  0.0014035554 |             f
   223 |     4540 |    100 |  0.0022117284 |             f
   224 |     4560 |    100 |  0.0029262107 |             f
   225 |     4580 |    100 |  0.0001492068 |             f
   226 |     4600 |    100 |  0.0005305552 |             f
   227 |     4620 |    100 |  0.0014120512 |             f
   228 |     4640 |    100 |  0.0024328597 |             f
   229 |     4660 |    100 |  0.0031766545 |             f
   230 |     4680 |    100 |  0.0100491928 |         ideal
   231 |     4700 |    100 |  0.0007163366 |             f
   232 |     4720 |    100 |  0.0021459096 |             f
   233 |     4740 |    100 |  0.0025205363 |             f
   234 |     4760 |    100 |  0.0011359025 |             f
   235 |     4780 |    100 |  0.0016903615 |             f
   236 |     4800 |    100 |  0.0021719093 |             f
   237 |     4820 |    100 |  0.0023432097 |             f
   238 |     4840 |    100 |  0.0025366569 |             f
   239 |     4860 |    100 |  0.0009831478 |             f
   240 |     4880 |    100 |  0.0020269592 |             f
   241 |     4900 |    100 |  0.0029445670 |             f
   242 |     4920 |    100 |  0.0014039593 |             f
   243 |     4940 |    100 |  0.0016479206 |             f
   244 |     4960 |    100 |  0.0017432882 |             f
   245 |     4980 |    100 |  0.0024965504 |             f
   246 |     5000 |    100 |  0.0075244161 |         nadir
   247 |     5020 |     98 |  0.0013514014 |             f
   248 |     5040 |    100 |  0.0023657877 |             f
   249 |     5060 |    100 |  0.0075814622 |         nadir
   250 |     5080 |    100 |  0.0008229083 |             f
   251 |     5100 |    100 |  0.0018200126 |             f
   252 |     5120 |    100 |  0.0015781123 |             f
   253 |     5140 |    100 |  0.0023827060 |             f
   254 |     5160 |    100 |  0.0028175156 |             f
   255 |     5180 |    100 |  0.0053076048 |         ideal
   256 |     5200 |    100 |  0.0010024077 |             f
   257 |     5220 |    100 |  0.0024020530 |             f
   258 |     5240 |    100 |  0.0025543578 |             f
   259 |     5260 |    100 |  0.0049140049 |         nadir
   260 |     5280 |    100 |  0.0008210233 |             f
   261 |     5300 |    100 |  0.0014776169 |             f
   262 |     5320 |    100 |  0.0019401038 |             f
   263 |     5340 |     99 |  0.0024339817 |             f
   264 |     5360 |    100 |  0.0488956676 |         nadir
   265 |     5380 |    100 |  0.0003297820 |             f
   266 |     5400 |    100 |  0.0004809948 |             f
   267 |     5420 |    100 |  0.0010137842 |             f
   268 |     5440 |    100 |  0.0018422106 |             f
   269 |     5460 |    100 |  0.0095161543 |         ideal
   270 |     5480 |    100 |  0.0002937348 |             f
   271 |     5500 |    100 |  0.0012896307 |             f
   272 |     5520 |    100 |  0.0016395611 |             f
   273 |     5540 |    100 |  0.0022096387 |             f
   274 |     5560 |    100 |  0.0029115372 |             f
   275 |     5580 |    100 |  0.0003208483 |             f
   276 |     5600 |    100 |  0.0010432496 |             f
   277 |     5620 |    100 |  0.0109090909 |         nadir
   278 |     5640 |    100 |  0.0006380572 |             f
   279 |     5660 |    100 |  0.0012539296 |             f
   280 |     5680 |    100 |  0.0018869736 |             f
   281 |     5700 |    100 |  0.0143516819 |         nadir
   282 |     5720 |    100 |  0.0006321777 |             f
   283 |     5740 |    100 |  0.0019345380 |             f
   284 |     5760 |    100 |  0.0033660764 |             f
   285 |     5780 |    100 |  0.0005689778 |             f
   286 |     5800 |    100 |  0.0018342685 |             f
   287 |     5820 |    100 |  0.0023026366 |             f
   288 |     5840 |    100 |  0.0032465771 |             f
   289 |     5860 |    100 |  0.0003782252 |             f
   290 |     5880 |    100 |  0.0006575345 |             f
   291 |     5900 |    100 |  0.0008099827 |             f
   292 |     5920 |    100 |  0.0021791783 |             f
   293 |     5940 |    100 |  0.0020347038 |             f
   294 |     5960 |    100 |  0.0021456030 |             f
   295 |     5980 |    100 |  0.0110159119 |         nadir
   296 |     6000 |    100 |  0.0042670460 |         ideal
   297 |     6020 |    100 |  0.0003256472 |             f
   298 |     6040 |    100 |  0.0011075836 |             f
   299 |     6060 |    100 |  0.0024431312 |             f
   300 |     6080 |    100 |  0.0029675471 |             f
   301 |     6100 |    100 |  0.0002832823 |             f
   302 |     6120 |    100 |  0.0008196136 |             f
   303 |     6140 |    100 |  0.0015111461 |             f
   304 |     6160 |    100 |  0.0023438304 |             f
   305 |     6180 |    100 |  0.0030117987 |             f
   306 |     6200 |    100 |  0.0006915368 |             f
   307 |     6220 |    100 |  0.0013023618 |             f
   308 |     6240 |    100 |  0.0016467663 |             f
   309 |     6260 |    100 |  0.0028181715 |             f
   310 |     6280 |    100 |  0.0002174903 |             f
   311 |     6300 |    100 |  0.0159094831 |         nadir
   312 |     6320 |    100 |  0.0002233155 |             f
   313 |     6340 |    100 |  0.0016067357 |             f
   314 |     6360 |    100 |  0.0113428872 |         nadir
   315 |     6380 |    100 |  0.0007826532 |             f
   316 |     6400 |    100 |  0.0015021859 |             f
   317 |     6420 |    100 |  0.0021639583 |             f
   318 |     6440 |    100 |  0.0035455709 |             f
   319 |     6460 |    100 |  0.0004408263 |             f
   320 |     6480 |    100 |  0.0009008182 |             f
   321 |     6500 |    100 |  0.0022734879 |             f
   322 |     6520 |    100 |  0.0028305513 |             f
   323 |     6540 |    100 |  0.0009522210 |             f
   324 |     6560 |    100 |  0.0016494359 |             f
   325 |     6580 |    100 |  0.0017040436 |             f
   326 |     6600 |    100 |  0.0077918054 |         nadir
   327 |     6620 |    100 |  0.0011897773 |             f
   328 |     6640 |    100 |  0.0016125463 |             f
   329 |     6660 |    100 |  0.0020910395 |             f
   330 |     6680 |    100 |  0.0025746796 |             f
   331 |     6700 |    100 |  0.0007270686 |             f
   332 |     6720 |    100 |  0.0015195218 |             f
   333 |     6740 |    100 |  0.0278235803 |         nadir
   334 |     6760 |    100 |  0.0003782784 |             f
   335 |     6780 |    100 |  0.0016226059 |             f
   336 |     6800 |    100 |  0.0024017009 |             f
   337 |     6820 |    100 |  0.0090901063 |         nadir
   338 |     6840 |    100 |  0.0005576767 |             f
   339 |     6860 |    100 |  0.0014769350 |             f
   340 |     6880 |    100 |  0.0016449498 |             f
   341 |     6900 |    100 |  0.0024713485 |             f
   342 |     6920 |    100 |  0.0032312052 |             f
   343 |     6940 |    100 |  0.0167410265 |         nadir
   344 |     6960 |    100 |  0.0012996546 |             f
   345 |     6980 |    100 |  0.0170260602 |         nadir
   346 |     7000 |    100 |  0.0011976013 |             f
   347 |     7020 |    100 |  0.0014380863 |             f
   348 |     7040 |    100 |  0.0024877771 |             f
   349 |     7060 |    100 |  0.0024301627 |             f
   350 |     7080 |    100 |  0.0026983284 |             f
   351 |     7100 |    100 |  0.0003606302 |             f
   352 |     7120 |    100 |  0.0011960733 |             f
   353 |     7140 |    100 |  0.0019512087 |             f
   354 |     7160 |    100 |  0.0036031599 |         nadir
   355 |     7180 |    100 |  0.0009421336 |             f
   356 |     7200 |    100 |  0.0014768857 |             f
   357 |     7220 |    100 |  0.0022113209 |             f
   358 |     7240 |    100 |  0.0024686798 |             f
   359 |     7260 |    100 |  0.0041844409 |             f
   360 |     7280 |    100 |  0.0007192559 |             f
   361 |     7300 |    100 |  0.0015899583 |             f
   362 |     7320 |    100 |  0.0026292431 |             f
   363 |     7340 |    100 |  0.0009527065 |             f
   364 |     7360 |    100 |  0.0023277191 |             f
   365 |     7380 |    100 |  0.0025602201 |             f
   366 |     7400 |    100 |  0.0004757329 |             f
   367 |     7420 |    100 |  0.0009509803 |             f
   368 |     7440 |    100 |  0.0012359725 |             f
   369 |     7460 |    100 |  0.0012359725 |             f
   370 |     7480 |    100 |  0.0020690394 |             f
   371 |     7500 |    100 |  0.0030688883 |             f
   372 |     7520 |    100 |  0.0005905618 |             f
   373 |     7540 |    100 |  0.0012236653 |             f
   374 |     7560 |    100 |  0.0021762875 |             f
   375 |     7580 |    100 |  0.0024757225 |             f
   376 |     7600 |    100 |  0.0030260195 |             f
   377 |     7620 |    100 |  0.0010453779 |             f
   378 |     7640 |    100 |  0.0028294560 |             f
   379 |     7660 |    100 |  0.0008431329 |             f
   380 |     7680 |    100 |  0.0011670264 |             f
   381 |     7700 |    100 |  0.0015683880 |             f
   382 |     7720 |    100 |  0.0019416665 |             f
   383 |     7740 |    100 |  0.0026499131 |             f
   384 |     7760 |    100 |  0.0007022859 |             f
   385 |     7780 |    100 |  0.0009237101 |             f
   386 |     7800 |    100 |  0.0021361051 |             f
   387 |     7820 |    100 |  0.0025407571 |             f
   388 |     7840 |    100 |  0.0001308940 |             f
   389 |     7860 |    100 |  0.0008044308 |             f
   390 |     7880 |    100 |  0.0013562003 |             f
   391 |     7900 |    100 |  0.0017308013 |             f
   392 |     7920 |    100 |  0.0024013220 |             f
   393 |     7940 |    100 |  0.0028098044 |             f
   394 |     7960 |    100 |  0.0002567657 |             f
   395 |     7980 |    100 |  0.0006284255 |             f
   396 |     8000 |    100 |  0.0012878252 |             f
   397 |     8020 |    100 |  0.0013628608 |             f
   398 |     8040 |    100 |  0.0055380328 |         nadir
   399 |     8060 |    100 |  0.0006003113 |             f
   400 |     8080 |    100 |  0.0010546091 |             f
   401 |     8100 |    100 |  0.0009835451 |             f
   402 |     8120 |    100 |  0.0012451618 |             f
   403 |     8140 |    100 |  0.0015852418 |             f
   404 |     8160 |    100 |  0.0016876756 |             f
   405 |     8180 |    100 |  0.0021492940 |             f
   406 |     8200 |    100 |  0.0024966693 |             f
   407 |     8220 |    100 |  0.0030337463 |             f
   408 |     8240 |    100 |  0.0018860295 |             f
   409 |     8260 |    100 |  0.0032175246 |             f
   410 |     8280 |    100 |  0.0011029264 |             f
   411 |     8300 |    100 |  0.0015949626 |             f
   412 |     8320 |    100 |  0.0030411376 |             f
   413 |     8340 |    100 |  0.0006455306 |             f
   414 |     8360 |    100 |  0.0010801287 |             f
   415 |     8380 |    100 |  0.0020144444 |             f
   416 |     8400 |    100 |  0.0024073664 |             f
   417 |     8420 |    100 |  0.0031172397 |             f
   418 |     8440 |    100 |  0.0005710727 |             f
   419 |     8460 |    100 |  0.0011122864 |             f
   420 |     8480 |    100 |  0.0022796814 |             f
   421 |     8500 |    100 |  0.0020510317 |             f
   422 |     8520 |    100 |  0.0027308887 |             f
   423 |     8540 |    100 |  0.0014657609 |             f
   424 |     8560 |    100 |  0.0018272361 |             f
   425 |     8580 |    100 |  0.0026311312 |             f
   426 |     8600 |    100 |  0.0165753486 |         ideal
   427 |     8620 |    100 |  0.0054760619 |         nadir
   428 |     8640 |    100 |  0.0005193119 |             f
   429 |     8660 |    100 |  0.0013459088 |             f
   430 |     8680 |    100 |  0.0023148639 |             f
   431 |     8700 |    100 |  0.0025461306 |             f
   432 |     8720 |    100 |  0.0005234013 |             f
   433 |     8740 |    100 |  0.0017194820 |             f
   434 |     8760 |    100 |  0.0023983429 |             f
   435 |     8780 |    100 |  0.0022632854 |             f
   436 |     8800 |    100 |  0.0026650966 |             f
   437 |     8820 |    100 |  0.0005005771 |             f
   438 |     8840 |    100 |  0.0010525363 |             f
   439 |     8860 |    100 |  0.0019397062 |             f
   440 |     8880 |    100 |  0.0025606293 |             f
   441 |     8900 |    100 |  0.0008085914 |             f
   442 |     8920 |    100 |  0.0016483399 |             f
   443 |     8940 |    100 |  0.0020092166 |             f
   444 |     8960 |    100 |  0.0019535993 |             f
   445 |     8980 |    100 |  0.0022133913 |             f
   446 |     9000 |    100 |  0.0021382748 |             f
   447 |     9020 |    100 |  0.0025587124 |             f
   448 |     9040 |    100 |  0.0007370084 |             f
   449 |     9060 |    100 |  0.0014084988 |             f
   450 |     9080 |    100 |  0.0026125291 |             f
   451 |     9100 |    100 |  0.0009579903 |             f
   452 |     9120 |    100 |  0.0017569206 |             f
   453 |     9140 |    100 |  0.0019840558 |             f
   454 |     9160 |    100 |  0.0024002859 |             f
   455 |     9180 |    100 |  0.0030808622 |             f
   456 |     9200 |    100 |  0.0002702860 |             f
   457 |     9220 |    100 |  0.0003230537 |             f
   458 |     9240 |    100 |  0.0011587346 |             f
   459 |     9260 |    100 |  0.0016820211 |             f
   460 |     9280 |    100 |  0.0017063738 |             f
   461 |     9300 |    100 |  0.0021860904 |             f
   462 |     9320 |    100 |  0.0026708949 |             f
   463 |     9340 |    100 |  0.0002090598 |             f
   464 |     9360 |    100 |  0.0007318818 |             f
   465 |     9380 |    100 |  0.0010357947 |             f
   466 |     9400 |    100 |  0.0019644443 |             f
   467 |     9420 |    100 |  0.0023897740 |             f
   468 |     9440 |    100 |  0.0021064322 |             f
   469 |     9460 |    100 |  0.0024230698 |             f
   470 |     9480 |    100 |  0.0028042277 |             f
   471 |     9500 |    100 |  0.0140518375 |         ideal
   472 |     9520 |    100 |  0.0007738034 |             f
   473 |     9540 |    100 |  0.0013821303 |             f
   474 |     9560 |    100 |  0.0018288185 |             f
   475 |     9580 |    100 |  0.0031318476 |             f
   476 |     9600 |    100 |  0.0007011751 |             f
   477 |     9620 |    100 |  0.0009437615 |             f
   478 |     9640 |    100 |  0.0021888502 |             f
   479 |     9660 |    100 |  0.0028657859 |             f
   480 |     9680 |    100 |  0.0012487209 |             f
   481 |     9700 |    100 |  0.0016981918 |             f
   482 |     9720 |    100 |  0.0019895151 |             f
   483 |     9740 |    100 |  0.0021550023 |             f
   484 |     9760 |    100 |  0.0034146478 |             f
   485 |     9780 |    100 |  0.0003210620 |             f
   486 |     9800 |    100 |  0.0011354892 |             f
   487 |     9820 |    100 |  0.0015977890 |             f
   488 |     9840 |    100 |  0.0023210344 |             f
   489 |     9860 |    100 |  0.0031707110 |             f
   490 |     9880 |    100 |  0.0013031596 |             f
   491 |     9900 |    100 |  0.0017447339 |             f
   492 |     9920 |    100 |  0.0021822949 |             f
   493 |     9940 |    100 |  0.0021822949 |             f
   494 |     9960 |    100 |  0.0023521848 |             f
   495 |     9980 |    100 |  0.0033130044 |             f
   496 |    10000 |    100 |  0.0003819641 |             f
   497 |    10020 |    100 |  0.0005206358 |             f
   498 |    10040 |    100 |  0.0010606473 |             f
   499 |    10060 |    100 |  0.0013798210 |             f
   500 |    10080 |    100 |  0.0017984435 |             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()
_images/exe3a_moo_EA_3obj_16_0.png

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