.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_basics/plot_04_structural_vs_numeric.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_01_basics_plot_04_structural_vs_numeric.py: Structural and numerical controllability ======================================== Kalman's criterion tests a numerical pair :math:`(\mathbf{A},\mathbf{B})`; Lin's theorem tests a zero pattern: a structured system is structurally controllable iff every state is reachable from an input and the generic rank of :math:`[\mathbf{A},\mathbf{B}]` is :math:`N` (no dilation). A star driven from its hub shows both conditions: without self-loops the leaves form a dilation; with self-loops the pattern is structurally controllable, yet a realization with *identical* leaf dynamics is not, because two leaves that behave the same cannot be told apart by one input. Almost every other realization is controllable. .. GENERATED FROM PYTHON SOURCE LINES 16-18 A star driven from its hub -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-52 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import nocad from nocad.plotting import draw_network from nocad.structural import controllable_subspace_dimension, is_structurally_controllable, random_realization n_leaves = 3 star = np.zeros((n_leaves + 1, n_leaves + 1)) star[0, 1:] = 1 # hub x1 -> leaves loops = star + np.diag(np.r_[0, np.ones(n_leaves)]) # leaves with self-loops b = np.zeros((n_leaves + 1, 1)) b[0] = 1 # [snippet:lin] for name, net in (("star", star), ("star with self-loops", loops)): A = net.T # state matrix of the network print(f"{name:22s} structurally controllable: {is_structurally_controllable(A, b)}") A_same = loops.T.copy() A_same[np.arange(1, n_leaves + 1), np.arange(1, n_leaves + 1)] = -1.0 # identical leaves print("identical leaves, Kalman dimension:", controllable_subspace_dimension(A_same, b)) A_diff = A_same.copy() A_diff[np.arange(1, n_leaves + 1), np.arange(1, n_leaves + 1)] = [-1.0, -2.0, -3.0] print("distinct leaves, Kalman dimension:", controllable_subspace_dimension(A_diff, b)) # [/snippet:lin] pos = np.array([[0.0, 0.0]] + [[np.cos(t), np.sin(t)] for t in np.pi / 2 + 2 * np.pi * np.arange(n_leaves) / n_leaves]) fig, axes = plt.subplots(1, 2, figsize=(7.0, 3.3)) draw_network(star, pos, ax=axes[0], drivers=[0], node_size=420, font_size=9) axes[0].set_title("star: dilation, not controllable\nfrom the hub", fontsize=9) draw_network(loops, pos, ax=axes[1], drivers=[0], node_size=420, font_size=9, draw_loops="arc") axes[1].set_title("star with self-loops: structurally\ncontrollable from the hub", fontsize=9) fig.tight_layout() .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_04_structural_vs_numeric_001.png :alt: star: dilation, not controllable from the hub, star with self-loops: structurally controllable from the hub :srcset: /auto_examples/01_basics/images/sphx_glr_plot_04_structural_vs_numeric_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none star structurally controllable: False star with self-loops structurally controllable: True identical leaves, Kalman dimension: 2 distinct leaves, Kalman dimension: 4 .. GENERATED FROM PYTHON SOURCE LINES 53-59 Parameter study: how often is a realization controllable? --------------------------------------------------------- Random realizations of the self-looped star with leaf dynamics drawn from a finite set of values: when two leaves get the same value the realization is uncontrollable. The fewer distinct values, the more often this happens; with continuous values (the last point) every realization is controllable, as Lin's theorem promises "almost always". .. GENERATED FROM PYTHON SOURCE LINES 59-84 .. code-block:: Python rng = np.random.default_rng(0) levels = [1, 2, 3, 5, 10, 50] share = [] for k in levels: ok = 0 for _ in range(300): A = random_realization(loops.T, rng).toarray() A[np.arange(1, n_leaves + 1), np.arange(1, n_leaves + 1)] = -rng.integers(1, k + 1, n_leaves) ok += controllable_subspace_dimension(A, b) == n_leaves + 1 share.append(ok / 300) cont = np.mean([controllable_subspace_dimension(random_realization(loops.T, rng), b) == n_leaves + 1 for _ in range(300)]) fig, ax = plt.subplots(figsize=(5.0, 3.2)) ax.plot(range(len(levels)), share, marker="o", color=nocad.plotting.PALETTE[0], label="leaf values from a finite set") ax.axhline(cont, color=nocad.plotting.PALETTE[2], ls="--", label="continuous random values") ax.set_xticks(range(len(levels))) ax.set_xticklabels(levels) ax.set_xlabel("number of possible leaf values") ax.set_ylabel("controllable realizations") ax.set_ylim(0, 1.05) ax.set_title("structurally controllable, numerically not always", fontsize=10) ax.grid(True, color="0.9") ax.legend(frameon=False, fontsize=8, loc="lower right") fig.tight_layout() .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_04_structural_vs_numeric_002.png :alt: structurally controllable, numerically not always :srcset: /auto_examples/01_basics/images/sphx_glr_plot_04_structural_vs_numeric_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 85-88 **Take-away.** Structural controllability is a property of the pattern that holds for almost all parameter values; symmetries of the actual parameters (identical units) can still destroy controllability, which only a numerical test detects. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.552 seconds) .. _sphx_glr_download_auto_examples_01_basics_plot_04_structural_vs_numeric.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/nocad/main?urlpath=lab/tree/notebooks/auto_examples/01_basics/plot_04_structural_vs_numeric.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_structural_vs_numeric.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_structural_vs_numeric.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_structural_vs_numeric.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_