.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scalable/plot_diagonal_doe.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_scalable_plot_diagonal_doe.py: Diagonal design of experiments ============================== Here is an illustration of the diagonal design of experiments (DOE) implemented by the :class:`.DiagonalDOE` class and used by the :class:`.ScalableDiagonalModel`. The idea is to sample the discipline by varying its inputs proportionally on one of the diagonals of its input space. .. GENERATED FROM PYTHON SOURCE LINES 31-43 .. code-block:: Python 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() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-49 Create the discipline --------------------- First, we create an :class:`.AnalyticDiscipline` implementing the function: :math:`f(x)=2x-3\sin(2\pi y)` and set its cache policy to ``"MemoryFullCache"``. .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. code-block:: Python discipline = create_discipline( "AnalyticDiscipline", expressions={"z": "2*x-3*sin(2*pi*y)"} ) .. GENERATED FROM PYTHON SOURCE LINES 55-59 Create the design space ----------------------- Then, we create a :class:`.DesignSpace` where :math:`x` and :math:`y` vary between 0 and 1. .. GENERATED FROM PYTHON SOURCE LINES 59-63 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 64-72 Sample with the default mode ---------------------------- Lastly, we create a :class:`.DOEScenario` and execute it with the :class:`.DiagonalDOE` algorithm to get 10 evaluations of :math:`f`. Note that we use the default configuration: all the disciplinary inputs vary proportionally from their lower bounds to their upper bounds. .. GENERATED FROM PYTHON SOURCE LINES 72-79 .. code-block:: Python 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) .. image-sg:: /examples/scalable/images/sphx_glr_plot_diagonal_doe_001.png :alt: plot diagonal doe :srcset: /examples/scalable/images/sphx_glr_plot_diagonal_doe_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 10:53:51: INFO - 10:53:51: *** Start DOEScenario execution *** INFO - 10:53:51: DOEScenario INFO - 10:53:51: Disciplines: AnalyticDiscipline INFO - 10:53:51: MDO formulation: DisciplinaryOpt INFO - 10:53:51: Optimization problem: INFO - 10:53:51: minimize z(x, y) INFO - 10:53:51: with respect to x, y INFO - 10:53:51: over the design space: INFO - 10:53:51: +------+-------------+-------+-------------+-------+ INFO - 10:53:51: | Name | Lower bound | Value | Upper bound | Type | INFO - 10:53:51: +------+-------------+-------+-------------+-------+ INFO - 10:53:51: | x | 0 | None | 1 | float | INFO - 10:53:51: | y | 0 | None | 1 | float | INFO - 10:53:51: +------+-------------+-------+-------------+-------+ INFO - 10:53:51: Solving optimization problem with algorithm DiagonalDOE: INFO - 10:53:51: 10%|█ | 1/10 [00:00<00:00, 343.15 it/sec, obj=0] INFO - 10:53:51: 20%|██ | 2/10 [00:00<00:00, 543.48 it/sec, obj=-1.71] INFO - 10:53:51: 30%|███ | 3/10 [00:00<00:00, 691.03 it/sec, obj=-2.51] INFO - 10:53:51: 40%|████ | 4/10 [00:00<00:00, 806.21 it/sec, obj=-1.93] INFO - 10:53:51: 50%|█████ | 5/10 [00:00<00:00, 895.87 it/sec, obj=-.137] INFO - 10:53:51: 60%|██████ | 6/10 [00:00<00:00, 967.47 it/sec, obj=2.14] INFO - 10:53:51: 70%|███████ | 7/10 [00:00<00:00, 1023.43 it/sec, obj=3.93] INFO - 10:53:51: 80%|████████ | 8/10 [00:00<00:00, 1072.03 it/sec, obj=4.51] INFO - 10:53:51: 90%|█████████ | 9/10 [00:00<00:00, 1108.59 it/sec, obj=3.71] INFO - 10:53:51: 100%|██████████| 10/10 [00:00<00:00, 1145.01 it/sec, obj=2] INFO - 10:53:51: Optimization result: INFO - 10:53:51: Optimizer info: INFO - 10:53:51: Status: None INFO - 10:53:51: Message: None INFO - 10:53:51: Number of calls to the objective function by the optimizer: 10 INFO - 10:53:51: Solution: INFO - 10:53:51: Objective: -2.5099788145921798 INFO - 10:53:51: Design space: INFO - 10:53:51: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:51: | Name | Lower bound | Value | Upper bound | Type | INFO - 10:53:51: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:51: | x | 0 | 0.2222222222222222 | 1 | float | INFO - 10:53:51: | y | 0 | 0.2222222222222222 | 1 | float | INFO - 10:53:51: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:51: *** End DOEScenario execution (time: 0:00:00.020183) *** [
] .. GENERATED FROM PYTHON SOURCE LINES 80-89 Sample with reverse mode for :math:`y` -------------------------------------- We can also change the configuration in order to select another diagonal of the input space, e.g. increasing :math:`x` and decreasing :math:`y`. This configuration is illustrated in the new :class:`.ScatterMatrix` plot where the :math:`(x,y)` points follow the :math:`t\mapsto -t` line while the :math:`(x,y)` points follow the :math:`t\mapsto t` line with the default configuration. .. GENERATED FROM PYTHON SOURCE LINES 89-99 .. code-block:: Python 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) .. image-sg:: /examples/scalable/images/sphx_glr_plot_diagonal_doe_002.png :alt: plot diagonal doe :srcset: /examples/scalable/images/sphx_glr_plot_diagonal_doe_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 10:53:52: INFO - 10:53:52: *** Start DOEScenario execution *** INFO - 10:53:52: DOEScenario INFO - 10:53:52: Disciplines: AnalyticDiscipline INFO - 10:53:52: MDO formulation: DisciplinaryOpt INFO - 10:53:52: Optimization problem: INFO - 10:53:52: minimize z(x, y) INFO - 10:53:52: with respect to x, y INFO - 10:53:52: over the design space: INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: | Name | Lower bound | Value | Upper bound | Type | INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: | x | 0 | 0.2222222222222222 | 1 | float | INFO - 10:53:52: | y | 0 | 0.2222222222222222 | 1 | float | INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: Solving optimization problem with algorithm DiagonalDOE: INFO - 10:53:52: 10%|█ | 1/10 [00:00<00:00, 1390.22 it/sec, obj=7.35e-16] INFO - 10:53:52: 20%|██ | 2/10 [00:00<00:00, 1378.57 it/sec, obj=2.15] INFO - 10:53:52: 30%|███ | 3/10 [00:00<00:00, 1429.06 it/sec, obj=3.4] INFO - 10:53:52: 40%|████ | 4/10 [00:00<00:00, 1509.69 it/sec, obj=3.26] INFO - 10:53:52: 50%|█████ | 5/10 [00:00<00:00, 1526.76 it/sec, obj=1.91] INFO - 10:53:52: 60%|██████ | 6/10 [00:00<00:00, 1543.92 it/sec, obj=0.0851] INFO - 10:53:52: 70%|███████ | 7/10 [00:00<00:00, 1556.08 it/sec, obj=-1.26] INFO - 10:53:52: 80%|████████ | 8/10 [00:00<00:00, 1557.99 it/sec, obj=-1.4] INFO - 10:53:52: 90%|█████████ | 9/10 [00:00<00:00, 1549.24 it/sec, obj=-.151] INFO - 10:53:52: 100%|██████████| 10/10 [00:00<00:00, 1572.96 it/sec, obj=2] INFO - 10:53:52: Optimization result: INFO - 10:53:52: Optimizer info: INFO - 10:53:52: Status: None INFO - 10:53:52: Message: None INFO - 10:53:52: Number of calls to the objective function by the optimizer: 10 INFO - 10:53:52: Solution: INFO - 10:53:52: Objective: -1.398867703481069 INFO - 10:53:52: Design space: INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: | Name | Lower bound | Value | Upper bound | Type | INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: | x | 0 | 0.7777777777777777 | 1 | float | INFO - 10:53:52: | y | 0 | 0.2222222222222223 | 1 | float | INFO - 10:53:52: +------+-------------+--------------------+-------------+-------+ INFO - 10:53:52: *** End DOEScenario execution (time: 0:00:00.017072) *** [
] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.834 seconds) .. _sphx_glr_download_examples_scalable_plot_diagonal_doe.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_diagonal_doe.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_diagonal_doe.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_