# Multiobjective optimization with Pareto front mapping¶

One way to do multiobjective optimization is with Pareto optimization, which explores the set of Pareto-efficient points. A point is Pareto-efficient if there are no other valid points that are better at every objective: it shows the “trade-off” between several objectives.

[1]:

from blop.utils import prepare_re_env

%run -i \$prepare_re_env.__file__ --db-type=temp

[2]:

from blop import DOF, Objective, Agent
from blop.utils import functions
from blop.dofs import BrownianMotion

import numpy as np

def digestion(df):
for index, entry in df.iterrows():
x1, x2 = entry.x1, entry.x2

df.loc[index, "f1"] = (x1 - 2) ** 2 + (x2 - 1) + 2
df.loc[index, "f2"] = 9 * x1 - (x2 - 1) + 2
df.loc[index, "c1"] = x1**2 + x2**2
df.loc[index, "c2"] = x1 - 3 * x2 + 10

return df

dofs = [
DOF(name="x1", search_domain=(-20, 20)),
DOF(name="x2", search_domain=(-20, 20)),
]

objectives = [
Objective(name="f1", target="min"),
Objective(name="f2", target="min"),
Objective(name="c1", target=(-np.inf, 225)),
Objective(name="c2", target=(-np.inf, 0)),
]

agent = Agent(
dofs=dofs,
objectives=objectives,
digestion=digestion,
db=db,
)

(uid,) = RE(agent.learn("qr", n=64))



Transient Scan ID: 1     Time: 2024-05-13 18:02:02
Persistent Unique Scan ID: '3f29bbc9-b01f-42ac-ae3a-68c58e9a69ba'
New stream: 'primary'
+-----------+------------+------------+------------+
|   seq_num |       time |         x1 |         x2 |
+-----------+------------+------------+------------+
|         1 | 18:02:02.7 |     -1.291 |      1.237 |
|         2 | 18:02:02.7 |     -0.761 |     -3.612 |
|         3 | 18:02:02.7 |      0.993 |     -6.580 |
|         4 | 18:02:02.7 |     -2.469 |    -10.573 |
|         5 | 18:02:02.7 |     -3.371 |     -8.541 |
|         6 | 18:02:02.7 |     -5.658 |     -7.195 |
|         7 | 18:02:02.7 |     -8.357 |     -2.459 |
|         8 | 18:02:02.7 |    -12.943 |      1.993 |
|         9 | 18:02:02.7 |    -15.540 |      3.186 |
|        10 | 18:02:02.7 |    -17.489 |     -0.715 |
|        11 | 18:02:02.7 |    -14.734 |     -4.408 |
|        12 | 18:02:02.7 |    -19.787 |     -5.803 |
|        13 | 18:02:02.7 |    -18.389 |    -17.747 |
|        14 | 18:02:02.7 |    -15.780 |    -12.521 |
|        15 | 18:02:02.7 |    -13.335 |    -11.330 |
|        16 | 18:02:02.7 |    -12.348 |     -9.611 |
|        17 | 18:02:02.7 |     -9.751 |    -14.225 |
|        18 | 18:02:02.7 |    -10.638 |    -16.438 |
|        19 | 18:02:02.7 |     -7.367 |    -19.178 |
|        20 | 18:02:02.7 |     -4.766 |    -15.330 |
|        21 | 18:02:02.7 |      2.076 |    -19.792 |
|        22 | 18:02:02.7 |      4.378 |    -14.861 |
|        23 | 18:02:02.7 |      7.130 |    -11.209 |
|        24 | 18:02:02.7 |     11.026 |    -13.157 |
|        25 | 18:02:02.7 |      9.519 |    -15.944 |
|        26 | 18:02:02.8 |     13.728 |    -18.361 |
|        27 | 18:02:02.8 |     16.012 |    -17.053 |
|        28 | 18:02:02.8 |     18.626 |    -11.966 |
|        29 | 18:02:02.8 |     17.096 |     -8.998 |
|        30 | 18:02:02.8 |     19.399 |     -3.771 |
|        31 | 18:02:02.8 |     17.614 |      1.380 |
|        32 | 18:02:02.8 |     12.111 |     -0.080 |
|        33 | 18:02:02.8 |     14.502 |     -5.188 |
|        34 | 18:02:02.8 |      8.750 |     -7.928 |
|        35 | 18:02:02.8 |      6.047 |     -2.975 |
|        36 | 18:02:02.8 |      3.608 |     -1.824 |
|        37 | 18:02:02.8 |      6.591 |      0.624 |
|        38 | 18:02:02.8 |      4.304 |      4.275 |
|        39 | 18:02:02.8 |      9.279 |      5.358 |
|        40 | 18:02:02.8 |     10.175 |      2.571 |
|        41 | 18:02:02.8 |     15.307 |      6.466 |
|        42 | 18:02:02.8 |     12.550 |      7.776 |
|        43 | 18:02:02.8 |     11.570 |     10.744 |
|        44 | 18:02:02.8 |     14.259 |     15.853 |
|        45 | 18:02:02.8 |     19.322 |     14.435 |
|        46 | 18:02:02.8 |     16.702 |     19.661 |
|        47 | 18:02:02.8 |      7.570 |     18.592 |
|        48 | 18:02:02.8 |      5.193 |     13.640 |
|        49 | 18:02:02.8 |      2.594 |     12.487 |
+-----------+------------+------------+------------+
|   seq_num |       time |         x1 |         x2 |
+-----------+------------+------------+------------+
|        50 | 18:02:02.8 |      1.685 |      9.206 |
|        51 | 18:02:02.8 |     -0.518 |     13.025 |
|        52 | 18:02:02.8 |      0.286 |     17.244 |
|        53 | 18:02:02.8 |     -2.830 |     17.956 |
|        54 | 18:02:02.8 |     -5.581 |     16.608 |
|        55 | 18:02:02.8 |     -7.962 |     11.873 |
|        56 | 18:02:02.8 |     -6.355 |      9.841 |
|        57 | 18:02:02.8 |     -3.915 |      5.995 |
|        58 | 18:02:02.8 |     -9.047 |      4.890 |
|        59 | 18:02:02.8 |    -10.564 |      7.103 |
|        60 | 18:02:02.8 |    -17.851 |      8.411 |
|        61 | 18:02:02.8 |    -16.309 |     10.130 |
|        62 | 18:02:02.8 |    -18.934 |     15.216 |
|        63 | 18:02:02.8 |    -14.027 |     13.821 |
|        64 | 18:02:02.8 |    -11.334 |     19.025 |
+-----------+------------+------------+------------+
generator list_scan ['3f29bbc9'] (scan num: 1)



We can plot our fitness and constraint objectives to see their models:

[3]:

agent.plot_objectives()


We can plot the Pareto front (the set of all Pareto-efficient points), which shows the trade-off between the two fitnesses. The points in blue comprise the Pareto front, while the points in red are either not Pareto efficient or are invalidated by one of the constraints.

[4]:

agent.plot_pareto_front()


We can explore the Pareto front by choosing a random point on the Pareto front and computing the expected improvement in the hypervolume of all fitness objectives with respect to that point (called the “reference point”). All this is done automatically with the qnehvi acquisition function:

[5]:

# this is broken now but is fixed in the next PR
# RE(agent.learn("qnehvi", n=4))