.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_latent_segmentation/plot_05_fisher_mma.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_03_latent_segmentation_plot_05_fisher_mma.py: Informative segments for parameter estimation (MMA polymerization) ================================================================== Which parts of a long operating record are worth using to identify a process model? Dobos, Bankó and Abonyi (2009) answer it with optimal experiment design: the Fisher information matrix of a time window, built from the output sensitivities with respect to the model parameters, tells how much the window says about the parameters. The criterion series is segmented, and the segments are ranked by information. The case study is the isothermal free-radical polymerization of methyl methacrylate in a CSTR (Doyle, Ogunnaike and Pearson, 1995). .. GENERATED FROM PYTHON SOURCE LINES 14-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mvtsa import segmentation as sg from mvtsa.datasets import MMA_PARAMETERS, simulate_mma_cstr .. GENERATED FROM PYTHON SOURCE LINES 22-26 An operating record ------------------- Constant operation, a grade change, excitation by random steps, and constant operation again (sampling time 0.05 h). .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python rng = np.random.default_rng(0) FI = np.r_[ np.full(100, 0.016783), np.full(100, 0.025), 0.02 + 0.006 * np.repeat(rng.choice([-1, 1], 20), 5), np.full(100, 0.016783), ] y = simulate_mma_cstr(FI) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Sensitivities and Fisher-information segmentation ------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-54 .. code-block:: Python names = ["kp", "kI", "kfm"] p0 = np.array([MMA_PARAMETERS[k] for k in names]) def simulate(p): return simulate_mma_cstr(FI, params=dict(zip(names, p, strict=True))) S = sg.finite_difference_sensitivities( simulate, p0, rel_step=1e-4 ) # (T, 1, 3), scaled fs = sg.FisherSegmenter( n_segments=5, criterion="logD", window=20, initial_size=10 ).fit(S) print(fs.segmentation_.change_points) print(fs.ranking_[["segment", "start", "stop", "logD", "E"]].round(2)) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 90 120 200 320] segment start stop logD E 0 3 200 320 39.27 1.482217e+06 1 1 90 120 38.18 2.106185e+06 2 0 0 90 25.57 2.505726e+10 3 2 120 200 9.52 1.264131e+11 4 4 320 400 9.52 8.854159e+11 .. GENERATED FROM PYTHON SOURCE LINES 55-58 The excitation period and the transient of the grade change carry the information; the constant operating periods add almost nothing, so they can be left out of the identification data set. .. GENERATED FROM PYTHON SOURCE LINES 58-71 .. code-block:: Python fig, axes = plt.subplots(3, 1, figsize=(7, 5.5), sharex=True) axes[0].step(np.arange(len(FI)), FI, color="#285780", where="post") axes[0].set_ylabel("$F_I$ (m³/h)") axes[1].plot(y / 1000, color="#E69F00") axes[1].set_ylabel("$M_n$ (kg/mol)") axes[2].plot(fs.criterion_, color="#009E73") axes[2].set_ylabel("log det $F$") axes[2].set_xlabel("sample") for ax in axes: for c in fs.segmentation_.change_points: ax.axvline(c, color="gray", ls=":", lw=1) .. image-sg:: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_05_fisher_mma_001.png :alt: plot 05 fisher mma :srcset: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_05_fisher_mma_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 72-76 Parameter study: the window of the criterion series --------------------------------------------------- A short window localizes the transients sharply but splits the excitation period; a long one blurs the boundaries. .. GENERATED FROM PYTHON SOURCE LINES 76-85 .. code-block:: Python for w in (10, 20, 40): f = sg.FisherSegmenter( n_segments=5, criterion="logD", window=w, initial_size=10 ).fit(S) best = f.ranking_.iloc[0] print( f"window {w}: change points {f.segmentation_.change_points}, most informative {int(best.start)}-{int(best.stop)}" ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none window 10: change points [100 120 200 260], most informative 200-260 window 20: change points [ 90 120 200 320], most informative 200-320 window 40: change points [ 80 130 180 330], most informative 180-330 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.273 seconds) .. _sphx_glr_download_auto_examples_03_latent_segmentation_plot_05_fisher_mma.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/mvtsa/main?urlpath=lab/tree/notebooks/auto_examples/03_latent_segmentation/plot_05_fisher_mma.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_fisher_mma.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_fisher_mma.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_fisher_mma.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_