.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_advanced_design.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_auto_examples_03_advanced_design.py: Prescribed points, focus and exclusion ====================================== Compose a reactor design from prescribed runs, a focus region and an exclusion zone. A pilot-scale continuous reactor is being mapped in temperature and pressure. Two runs from an earlier campaign are already available and must be reused as-is. The team also wants extra coverage around a suspected optimum, must keep the design away from the high-T / high-P corner for safety reasons, and considers temperature the more critical of the two factors, so separation along that axis should count for more. Parameters ---------- - temperature (100-500 degC, 25-degree steps): the reactor operating window on an explicit grid so the placement points land on nodes. - pressure (0.5-5.0 bar, 0.5-bar steps): a matching discrete grid from sub-atmospheric to the safe upper limit. What to look at --------------- - ``summary()``: the "Prescribed", "Focus" and "Optimised" rows show how the design is composed; two prescribed and four focus points should be present alongside the optimised runs. - ``quality_report()``: scores are computed on the union of all included points, so the min_distance percentile still reflects overall separation despite the placement constraints. - ``plot('pairplot')``: the two prescribed runs should appear at the requested coordinates, the neighbourhood of (300, 2.0) should be visibly denser than elsewhere, and the corner around (500, 5.0) should be empty. Mergen features used -------------------- - add_prescribed for runs already carried out. - add_focus to concentrate additional samples around a critical operating point. - add_exclusion to keep the design away from an unsafe region. - set_dimension_weights to make the temperature axis count more than pressure when distances are computed. Estimated runtime: a few seconds. .. GENERATED FROM PYTHON SOURCE LINES 46-82 .. code-block:: Python from mergen import ParameterSpace, Sampler # 1. Define a two-parameter engineering-style space on an explicit grid # so that prescribed / focus / exclusion points land on grid nodes. space = ParameterSpace({ 'temperature': range(100, 501, 25), # 100, 125, ..., 500 'pressure': [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0], }) # 2. Configure the sampler with all four placement mechanisms. sampler = Sampler(space) # Prescribed points: two runs that must appear verbatim in the design. sampler.add_prescribed([[200, 1.0], [400, 3.0]]) # Focus region: extra samples clustered around a critical operating # point (T = 300 K, P = 2 bar). ``spread`` is the neighbourhood radius # in normalised coordinates. sampler.add_focus(point=[300, 2.0], spread=0.15, n_samples=4) # Exclusion zone: keep the design away from the high-T / high-P corner. sampler.add_exclusion(point=[500, 5.0], spread=0.20) # Dimension weights: temperature matters twice as much as pressure # for separation. Values are relative and do not need to sum to one. sampler.set_dimension_weights({'temperature': 2.0, 'pressure': 1.0}) # 3. Run and inspect. sampler.set_design(n_samples=20) result = sampler.run() result.summary() result.quality_report() result.plot('pairplot', save=True) result.to_csv('advanced_design.csv') .. rst-class:: sphx-glr-script-out .. code-block:: none ════════════════════════════════════════════════════════════ MERGEN — Space-filling Design ════════════════════════════════════════════════════════════ Parameters : 2 Candidates : 170 n_samples : 20 (prescribed_in=2, focus_in=4, optimised_slots=14) Total design : 20 Validation : 4 Criterion : umaxpro Algorithm(s) : sa ──────────────────────────────────────────────────────────── [MERGEN] Sampling focus / exclusion regions... [INFO] ExclusionPoint [500.0, 5.0]: removed from pool. [MERGEN] Preparing anchor points... [MERGEN] Optimising (criterion=umaxpro, algorithm=sa)... [SA] Restart 1/5 [SA] Tuning temperature... [SA] Start log(score)=46.052 T=4.2857e+17 iters=2000 swappable=14 hybrid=0.50 iter 500/2000 T=4.286e+16 best log(score)=28.644 iter 1000/2000 T=4.286e+15 best log(score)=28.644 iter 1500/2000 T=4.286e+14 best log(score)=28.644 iter 2000/2000 T=4.286e+13 best log(score)=28.148 [SA] Done log(score)=28.148 (accepted=1738/2000, rate=86.9%) [SA] Restart 1: new best log(score)=28.148 [SA] Restart 2/5 [SA] Tuning temperature... [SA] Start log(score)=29.374 T=2.8571e+17 iters=2000 swappable=14 hybrid=0.50 iter 500/2000 T=2.857e+16 best log(score)=28.620 iter 1000/2000 T=2.857e+15 best log(score)=28.586 iter 1500/2000 T=2.857e+14 best log(score)=28.579 iter 2000/2000 T=2.857e+13 best log(score)=28.415 [SA] Done log(score)=28.415 (accepted=1800/2000, rate=90.0%) [SA] Restart 3/5 [SA] Tuning temperature... [SA] Start log(score)=29.810 T=1.4286e+17 iters=2000 swappable=14 hybrid=0.50 iter 500/2000 T=1.429e+16 best log(score)=28.490 iter 1000/2000 T=1.429e+15 best log(score)=28.490 iter 1500/2000 T=1.429e+14 best log(score)=28.030 iter 2000/2000 T=1.429e+13 best log(score)=28.030 [SA] Done log(score)=28.030 (accepted=1801/2000, rate=90.0%) [SA] Restart 3: new best log(score)=28.030 [SA] Restart 4/5 [SA] Tuning temperature... [SA] Start log(score)=28.452 T=1.4286e+17 iters=2000 swappable=14 hybrid=0.50 iter 500/2000 T=1.429e+16 best log(score)=28.030 iter 1000/2000 T=1.429e+15 best log(score)=28.030 iter 1500/2000 T=1.429e+14 best log(score)=27.878 iter 2000/2000 T=1.429e+13 best log(score)=27.878 [SA] Done log(score)=27.878 (accepted=1822/2000, rate=91.1%) [SA] Restart 4: new best log(score)=27.878 [SA] Restart 5/5 [SA] Tuning temperature... [SA] Start log(score)=27.878 T=1.4286e+17 iters=2000 swappable=14 hybrid=0.50 iter 500/2000 T=1.429e+16 best log(score)=27.878 iter 1000/2000 T=1.429e+15 best log(score)=27.878 iter 1500/2000 T=1.429e+14 best log(score)=27.878 iter 2000/2000 T=1.429e+13 best log(score)=27.878 [SA] Done log(score)=27.878 (accepted=1727/2000, rate=86.4%) [MERGEN] sa done -- score=1.281e+12 (elapsed 18.5s) ──────────────────────────────────────────────────────────── MERGEN — Final Design ──────────────────────────────────────────────────────────── Prescribed (in) : 2 Prescribed (out) : 0 Focus (in) : 4 Focus (out) : 0 Optimised : 14 Total design : 20 Validation : 4 ════════════════════════════════════════════════════════════ ──────────────────────────────────────────────────── MERGEN Design Summary ──────────────────────────────────────────────────── Prescribed : 2 Focus : 4 Optimised : 14 Total design : 20 Validation : 4 ──────────────────────────────────────────────────── Parameters : 2 Candidates : 170 Criterion : umaxpro Seed : 44 Algorithm : sa ──────────────────────────────────────────────────── [METRICS] Computing MC baseline (300 designs)... [METRICS] MC baseline complete (300 designs). ════════════════════════════════════════════════════════════════════════ MERGEN Design Metrics (n=20, d=2) ════════════════════════════════════════════════════════════════════════ Metric Value Baseline Better when Rank ──────────────────────────────────────────────────────────────────────── Min distance 0.0625 0.0625 higher 47th pct Minimax distance 0.2562 0.3391 lower 97th pct * Max |correlation| 0.3860 0.1569 lower 5th pct * 2D projection CD2 0.0693 0.1347 lower 100th pct * CV distances 0.4587 0.4601 lower 52th pct Mean distance 0.5426 0.5709 higher 23th pct ──────────────────────────────────────────────────────────────────────── Criterion scores ──────────────────────────────────────────────────────────────────────── UMAXPRO 6.0296e+12 1.5550e+13 100th pct lower ──────────────────────────────────────────────────────────────────────── * = primarily optimised by 'umaxpro' For other priorities, see: mergen.criteria.list_criteria() ──────────────────────────────────────────────────────────────────────── Baseline: 300 MC designs from feasible space | Rank = percentile among baseline designs ════════════════════════════════════════════════════════════════════════ Saved: outputs/pairplot_3.png Saved: outputs/advanced_design.csv (24 rows) .. image-sg:: /auto_examples/images/sphx_glr_03_advanced_design_001.png :alt: 03 advanced design :srcset: /auto_examples/images/sphx_glr_03_advanced_design_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-46 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 20.181 seconds) .. _sphx_glr_download_auto_examples_03_advanced_design.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_advanced_design.ipynb <03_advanced_design.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_advanced_design.py <03_advanced_design.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_advanced_design.zip <03_advanced_design.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_