Diagonal design of experiments

Here is an illustration of the diagonal design of experiments (DOE) implemented by the DiagonalDOE class and used by the ScalableDiagonalModel. The idea is to sample the discipline by varying its inputs proportionally on one of the diagonals of its input space.

from __future__ import annotations

from gemseo import configure_logger
from gemseo import create_design_space
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo.post.dataset.scatter_plot_matrix import ScatterMatrix

configure_logger()
<RootLogger root (INFO)>

Create the discipline

First, we create an AnalyticDiscipline implementing the function: \(f(x)=2x-3\sin(2\pi y)\) and set its cache policy to "MemoryFullCache".

discipline = create_discipline(
    "AnalyticDiscipline", expressions={"z": "2*x-3*sin(2*pi*y)"}
)

Create the design space

Then, we create a DesignSpace where \(x\) and \(y\) vary between 0 and 1.

design_space = create_design_space()
design_space.add_variable("x", l_b=0.0, u_b=1.0)
design_space.add_variable("y", l_b=0.0, u_b=1.0)

Sample with the default mode

Lastly, we create a DOEScenario and execute it with the DiagonalDOE algorithm to get 10 evaluations of \(f\). Note that we use the default configuration: all the disciplinary inputs vary proportionally from their lower bounds to their upper bounds.

scenario = create_scenario(
    discipline, "DisciplinaryOpt", "z", design_space, scenario_type="DOE"
)
scenario.execute({"algo": "DiagonalDOE", "n_samples": 10})
dataset = scenario.to_dataset(opt_naming=False)
ScatterMatrix(dataset).execute(save=False, show=True)
plot diagonal doe
    INFO - 01:02:20:
    INFO - 01:02:20: *** Start DOEScenario execution ***
    INFO - 01:02:20: DOEScenario
    INFO - 01:02:20:    Disciplines: AnalyticDiscipline
    INFO - 01:02:20:    MDO formulation: DisciplinaryOpt
    INFO - 01:02:20: Optimization problem:
    INFO - 01:02:20:    minimize z(x, y)
    INFO - 01:02:20:    with respect to x, y
    INFO - 01:02:20:    over the design space:
    INFO - 01:02:20:       +------+-------------+-------+-------------+-------+
    INFO - 01:02:20:       | Name | Lower bound | Value | Upper bound | Type  |
    INFO - 01:02:20:       +------+-------------+-------+-------------+-------+
    INFO - 01:02:20:       | x    |      0      |  None |      1      | float |
    INFO - 01:02:20:       | y    |      0      |  None |      1      | float |
    INFO - 01:02:20:       +------+-------------+-------+-------------+-------+
    INFO - 01:02:20: Solving optimization problem with algorithm DiagonalDOE:
    INFO - 01:02:20:     10%|█         | 1/10 [00:00<00:00, 457.59 it/sec, obj=0]
    INFO - 01:02:20:     20%|██        | 2/10 [00:00<00:00, 712.59 it/sec, obj=-1.71]
    INFO - 01:02:20:     30%|███       | 3/10 [00:00<00:00, 892.98 it/sec, obj=-2.51]
    INFO - 01:02:20:     40%|████      | 4/10 [00:00<00:00, 1019.58 it/sec, obj=-1.93]
    INFO - 01:02:20:     50%|█████     | 5/10 [00:00<00:00, 1120.93 it/sec, obj=-0.137]
    INFO - 01:02:20:     60%|██████    | 6/10 [00:00<00:00, 1202.67 it/sec, obj=2.14]
    INFO - 01:02:20:     70%|███████   | 7/10 [00:00<00:00, 1269.85 it/sec, obj=3.93]
    INFO - 01:02:20:     80%|████████  | 8/10 [00:00<00:00, 1325.11 it/sec, obj=4.51]
    INFO - 01:02:20:     90%|█████████ | 9/10 [00:00<00:00, 1371.38 it/sec, obj=3.71]
    INFO - 01:02:20:    100%|██████████| 10/10 [00:00<00:00, 1411.65 it/sec, obj=2]
    INFO - 01:02:20: Optimization result:
    INFO - 01:02:20:    Optimizer info:
    INFO - 01:02:20:       Status: None
    INFO - 01:02:20:       Message: None
    INFO - 01:02:20:       Number of calls to the objective function by the optimizer: 10
    INFO - 01:02:20:    Solution:
    INFO - 01:02:20:       Objective: -2.5099788145921798
    INFO - 01:02:20:       Design space:
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:          | Name | Lower bound |       Value        | Upper bound | Type  |
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:          | x    |      0      | 0.2222222222222222 |      1      | float |
    INFO - 01:02:20:          | y    |      0      | 0.2222222222222222 |      1      | float |
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20: *** End DOEScenario execution (time: 0:00:00.016674) ***

[<Figure size 640x480 with 9 Axes>]

Sample with reverse mode for \(y\)

We can also change the configuration in order to select another diagonal of the input space, e.g. increasing \(x\) and decreasing \(y\). This configuration is illustrated in the new ScatterMatrix plot where the \((x,y)\) points follow the \(t\mapsto -t\) line while the \((x,y)\) points follow the \(t\mapsto t\) line with the default configuration.

scenario = create_scenario(
    discipline, "DisciplinaryOpt", "z", design_space, scenario_type="DOE"
)
scenario.execute({
    "algo": "DiagonalDOE",
    "n_samples": 10,
    "algo_options": {"reverse": ["y"]},
})
dataset = scenario.to_dataset(opt_naming=False)
ScatterMatrix(dataset).execute(save=False, show=True)
plot diagonal doe
    INFO - 01:02:20:
    INFO - 01:02:20: *** Start DOEScenario execution ***
    INFO - 01:02:20: DOEScenario
    INFO - 01:02:20:    Disciplines: AnalyticDiscipline
    INFO - 01:02:20:    MDO formulation: DisciplinaryOpt
    INFO - 01:02:20: Optimization problem:
    INFO - 01:02:20:    minimize z(x, y)
    INFO - 01:02:20:    with respect to x, y
    INFO - 01:02:20:    over the design space:
    INFO - 01:02:20:       +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:       | Name | Lower bound |       Value        | Upper bound | Type  |
    INFO - 01:02:20:       +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:       | x    |      0      | 0.2222222222222222 |      1      | float |
    INFO - 01:02:20:       | y    |      0      | 0.2222222222222222 |      1      | float |
    INFO - 01:02:20:       +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20: Solving optimization problem with algorithm DiagonalDOE:
    INFO - 01:02:20:     10%|█         | 1/10 [00:00<00:00, 1758.62 it/sec, obj=7.35e-16]
    INFO - 01:02:20:     20%|██        | 2/10 [00:00<00:00, 1758.62 it/sec, obj=2.15]
    INFO - 01:02:20:     30%|███       | 3/10 [00:00<00:00, 1798.84 it/sec, obj=3.4]
    INFO - 01:02:20:     40%|████      | 4/10 [00:00<00:00, 1807.89 it/sec, obj=3.26]
    INFO - 01:02:20:     50%|█████     | 5/10 [00:00<00:00, 1799.82 it/sec, obj=1.91]
    INFO - 01:02:20:     60%|██████    | 6/10 [00:00<00:00, 1814.54 it/sec, obj=0.0851]
    INFO - 01:02:20:     70%|███████   | 7/10 [00:00<00:00, 1826.67 it/sec, obj=-1.26]
    INFO - 01:02:20:     80%|████████  | 8/10 [00:00<00:00, 1837.49 it/sec, obj=-1.4]
    INFO - 01:02:20:     90%|█████████ | 9/10 [00:00<00:00, 1845.00 it/sec, obj=-0.151]
    INFO - 01:02:20:    100%|██████████| 10/10 [00:00<00:00, 1851.71 it/sec, obj=2]
    INFO - 01:02:20: Optimization result:
    INFO - 01:02:20:    Optimizer info:
    INFO - 01:02:20:       Status: None
    INFO - 01:02:20:       Message: None
    INFO - 01:02:20:       Number of calls to the objective function by the optimizer: 10
    INFO - 01:02:20:    Solution:
    INFO - 01:02:20:       Objective: -1.398867703481069
    INFO - 01:02:20:       Design space:
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:          | Name | Lower bound |       Value        | Upper bound | Type  |
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20:          | x    |      0      | 0.7777777777777777 |      1      | float |
    INFO - 01:02:20:          | y    |      0      | 0.2222222222222223 |      1      | float |
    INFO - 01:02:20:          +------+-------------+--------------------+-------------+-------+
    INFO - 01:02:20: *** End DOEScenario execution (time: 0:00:00.014878) ***

[<Figure size 640x480 with 9 Axes>]

Total running time of the script: (0 minutes 0.754 seconds)

Gallery generated by Sphinx-Gallery