Network-Based Controllability and Observability Analysis in PythonThe nocad toolbox

Chapter 4
Visualizing controllability and observability

A force-directed drawing of a network shows its density and its clusters, but it does not show whether the network is controllable, where its inputs must go, or why a given design works. This chapter develops drawings in which the geometry carries the theory: a layered layout of the strongly connected components that turns accessibility into height, a bipartite layout that turns a matching into horizontal lines, a decomposition of a design into Lin’s cacti with a tree layout that makes the proof of controllability readable, a block-triangular view of the system matrix, and depth maps and an operability plane that show how far the states are from the inputs and outputs. Each view is introduced with the condition it certifies and the algorithm that produces it.

4.1 Problem and idea

General-purpose layouts place nodes so that edges have similar lengths and few crossings: spring embedders [34] and stress minimization [35] are the defaults of network software. They are good at showing clusters and poor at showing direction: whether a node can be reached from another, which nodes have no predecessors, and which edges a matching uses are invisible in them. The questions an engineer asks about an input–output configuration are of exactly this kind:

1.
Where must the inputs and outputs go? Every source component needs a driver node and every sink component a sensor node (accessibility, condition (i) of Lin’s theorem).
2.
Why is a configuration sufficient? A matching assigns a parent to every state and the cacti of Lin’s theorem cover the network; a reader should be able to check this certificate on the picture.
3.
How well does it work? The relative degree of a state with respect to an input is the length of the shortest path plus one; long paths mean slow, poorly conditioned control [18, 20].
4.
How robust is it? Which edges and nodes are indispensable, and which are interchangeable (chapter 5).

The idea of the chapter is to let each question decide the layout, and to encode the answer in the most effective visual channel, position [36]: accessibility becomes height in a layered drawing, a matching becomes a set of horizontal lines, a cactus becomes a tree, a block-triangular structure becomes a staircase, and the depth of a state becomes its color and its coordinate in a plane (fig. 4.1). The same colors are used in every view and throughout the book: driver nodes blue, sensor nodes vermilion, nodes that are both purple, matched edges green, from the colorblind-safe palette of Okabe and Ito [37].

Figure 4.1

Figure 4.1. The questions about an input–output configuration, the conditions or quantities that answer them, and the views of this chapter that show them.

4.2 Theory

4.2.1 The SCC hierarchy

The condensation of 𝒢 is acyclic, so its components can be drawn on horizontal levels with all edges pointing downward, as in the layered drawing method of Sugiyama, Tagawa and Toda [38]. Three choices adapt the method to controllability.

Layering. Component 𝒞 is put on level λ(𝒞)=0 if it has no predecessor and on level λ(𝒞)=1+max𝒞′→𝒞λ(𝒞′) otherwise (longest-path layering [39]). The top level then consists of exactly the source components: every component drawn on top needs a driver node, every component below receives the influence of some component above it. For observability the levels are counted upward from the sink components, which then form the bottom level and need the sensor nodes. The level of a component is the number of components on the longest chain above it; it bounds how many component boundaries a signal has to cross, not the length of the shortest path, which the depth maps of section 4.2.5 show.

Order within the levels. The components of a level are reordered by alternating downward and upward barycenter sweeps [38, 40]: a component moves to the mean position of its neighbors on the previous level. Horizontal coordinates are then assigned by packing the components with their widths and pulling each toward the barycenter of all its neighbors under separation constraints, a simple variant of the priority method of Sugiyama et al.; Brandes and Köpf [41] give a more elaborate linear-time alternative.

Components as circles. A nontrivial component is drawn as a circle of radius growing with the square root of its size, its nodes in the order of a greedy walk along its edges, so that consecutive nodes on the circle are mostly joined by edges and the cycles that make the component strongly connected show as arcs. The vertical gap between two levels adapts to the largest circles on them, so that circles of adjacent levels never overlap. Algorithm 4.1 summarizes the layout; with Tarjan’s algorithm for the components [42] it takes O(N+|E|) time plus O(s|Ec|) for s sweeps over the |Ec| edges of the condensation.

Algorithm\special {t4ht^+}

4.2.2 The bipartite view

In the bipartite representation B(𝒢) (section 3.2.1) the out-copies xj+ are drawn in a left column, the in-copies xi− in a right column. The out-copies keep the natural order; the in-copy of every matched node xi is placed level with the out-copy of its matching partner, and the in-copies of the unmatched nodes fill the remaining rows. Because a matching pairs distinct out-copies with distinct in-copies, this is a valid placement, and it makes every matched edge horizontal: the matching reads as a stack of parallel lines, and the unmatched in-copies, the driver nodes, are the right-hand ends without a horizontal line. A dilation, a set S of states with fewer distinct parents T(S) than members, appears as a fan: few out-copies joined to many in-copies, at least |S|−|T(S)| of which stay unmatched by Hall’s theorem. Edges are colored by their class (critical, ordinary, redundant; section 5.2.2), so the view also shows which horizontal lines could be exchanged for others.

4.2.3 Control cacti

Lin’s proof of his theorem constructs a spanning subgraph of a special shape [5]. A stem is a directed path that starts at an input; a bud is a directed cycle together with one extra edge, the distinguished edge, that enters the cycle; a cactus is a stem to which buds are attached recursively, the distinguished edge of every bud starting at a node of the stem (other than its last node) or of a bud attached earlier. A system is structurally controllable iff its graph is spanned by a disjoint union of cacti. A design matching provides almost all of this: the matched edges form paths that start at the driver nodes (the stems) and cycles (the buds without their distinguished edges). What is missing is the choice of the distinguished edges. Algorithm 4.2 chooses them by a breadth-first search over the cycles.

Algorithm\special {t4ht^+}

Proposition 4.1. Let M be a matching of 𝒢, 𝒟 its unmatched nodes and 𝒮sh the nodes that receive a shared input. Algorithm 4.2 attaches every bud iff every node of 𝒢 is reachable from 𝒟∪𝒮sh. The attached stems and buds then form a spanning set of disjoint cacti, and the depth of every bud is the smallest number of buds through which it can be reached from a stem or a shared input.

Proof. If all buds are attached, every node lies on a stem or on a bud that is reached through a chain of distinguished edges from a stem or from a shared input, so it is reachable. Conversely, suppose the algorithm stops with a nonempty set X of nodes on unattached buds. No edge leads from an attached node into X, otherwise the loop would continue; all nodes outside X are attached, because stems are attached from the start. Hence no edge enters X from outside, and X contains no node of 𝒟 (stems are attached) and no node of 𝒮sh (buds with a shared node are attached first): the nodes of X are not reachable. For the depths, the depths of the anchors chosen in successive steps never decrease: an anchor of smaller depth that was available earlier would have been chosen earlier, because the bud it leads to was unattached then. The search is therefore a breadth-first search on the graph of buds, which assigns shortest distances. □

For a design that makes the system controllable (every source component contains a driver node or a shared node), every node is reachable, so the decomposition always succeeds and the picture of the cacti is a certificate of controllability that a reader can check edge by edge. Buds left unattached by an arbitrary matching mark exactly the inaccessible part of the network. Observation cacti are the control cacti of the reversed network; drawn mirrored, their stems end at the sensors.

Cactus layout. Every cactus is drawn as a horizontal tree (fig. 4.2). The input is the root, at the left; the stem is the spine, one node per step to the right. The children of a stem node are the next stem node and the buds whose distinguished edges start at it; the children of a bud are the buds attached to any of its nodes. The first child continues the row of its parent, further children are stacked alternately above and below. Every subtree is measured first (the height it needs above and below its row), and every child is given its own horizontal band, so siblings never overlap; this is a banded simplification of the tidy-tree algorithms of Reingold and Tilford [43] and Walker [44], sufficient because cacti are shallow. A bud is drawn as a circle whose node on the distinguished edge faces the anchor, the others following along the cycle. The cacti of different inputs are stacked vertically, buds fed by a shared input hang below the first cactus, and unattached buds go to the bottom row. The layout takes O(N) time after the decomposition.

Figure 4.2

Figure 4.2. The cactus layout. The stem u1→x1→x2→x3→x4 (blue) is the spine; the bud {x5,x6} is attached by the distinguished edge x2→x5 (dashed orange) and carries the bud {x7,x8} in its own row; the self-loop bud x9 hangs from x3. Each subtree gets a band (shaded) whose height is computed before placement, so subtrees never overlap.

4.2.4 The structure matrix

The same conditions read in matrix language. Write the zero pattern of the system matrix [ 𝐀 𝐁 𝐂 0 ]with rows for the equations ẋi and columns for the states xj; the non-zero aij is the edge xj→xi. Ordering the states by a topological order of the strongly connected components, source components first, makes 𝐀 block lower triangular: an edge between components runs from an earlier to a later component, so its entry lies below the diagonal blocks, which are the components themselves (the Frobenius normal form; the Dulmage–Mendelsohn decomposition refines it [8, 29, 30]). The rows of a source block have non-zeros only inside the block, so at least one of them needs a non-zero in 𝐁: this is accessibility. The entries of the control matching are a transversal, non-zeros in distinct rows and columns; the rows they leave uncovered are the rows of the driver nodes, which the entries of 𝐁 cover, so [𝐀𝐁] has full generic rank. Dually, the columns of a sink block have non-zeros only inside the block, so 𝐂 needs a non-zero in one of them.

4.2.5 Depth maps and regions

For a set 𝒟 of driver nodes, the control depth of state xi is its distance from the nearest driver node and its control region is that driver,

ρiC=mind∈𝒟ℓdi,RC(i)=arg⁡mind∈𝒟ℓdi,(4.1)

with ties broken in favor of the smaller index. Both follow from one breadth-first search started from all driver nodes at once, in O(N+|E|) time; the regions are the cells of the graph Voronoi diagram of the driver nodes [45]. The observation depth ρiO and region RO(i) are the same quantities for the sensor nodes on the reversed network. For generic parameters, a state xi at distance ℓdi from the driver node of input uk has relative degree ℓdi+1 with respect to uk [18]: the input appears in the (ℓdi+1)-th time derivative of xi and not earlier. The largest depth maxiρiC is the relative order of the configuration used by the placement methods of chapter 8. A depth map colors every state by its depth on a discrete sequential scale (blues for control, oranges for observation), outlines the regions by padded convex hulls of their nodes, and marks states that no driver reaches with an empty vermilion circle. The same numbers in matrix form, states sorted by region and depth against the configured nodes, give the distance matrix (the controlling and observing matrices of the MATLAB toolbox).

4.2.6 The operability plane

The operability plane places every state at the point (ρiC,ρiO). Because the minima in eq. (4.1) separate,

ρiC+ρiO=mind∈𝒟,s∈𝒮(ℓdi+ℓis),(4.2)

the length of the shortest walk from a driver node to a sensor node through xi; the dotted anti-diagonals of the plane are its level lines. States in the lower left corner are close to both an input and an output; states to the right are slow to steer, states at the top slow to see, and the largest coordinates are the relative orders of the input and the output configuration. Marginal bar charts count the states at each depth. Many states share integer coordinates, so coincident points are spread on a small sunflower spiral [46], which separates them deterministically without moving any point across a cell boundary. The plane compares configurations at a glance: adding drivers moves the cloud to the left, adding sensors moves it down.

In a nutshell: Views of controllability and observability

  • SCC hierarchy: longest-path layering of the condensation; the top level is exactly the set of source components (the bottom level the sinks in the observation view).
  • Bipartite view: matched edges horizontal; the free in-copies are the driver nodes, dilations are fans.
  • Control cacti: stems from the matching, buds attached by breadth-first search; succeeds iff every node is reachable from the inputs, giving a checkable certificate of controllability with buds as shallow as possible.
  • Structure matrix: block-triangular order; source blocks need 𝐁, sink blocks need 𝐂, the matching is a transversal.
  • Depth maps and the operability plane: distances from the nearest driver and to the nearest sensor (relative degree minus one), regions as graph Voronoi cells.

4.3 Using it in nocad

All views live in nocad.viz; each plotting function takes the network and optionally the driver and sensor nodes or a matching, designs them with InputOutputDesign when they are omitted, draws into a given ax and returns it.

layouts in nocad.viz

hierarchy_layout(adj, direction) returns pos, level, center, radius, levels and the condensation; bipartite_layout(adj, matching) returns out_pos and in_pos; control_cacti(adj, method, matching, shared) returns stems, buds, attach, owner, depth, unattached; cactus_layout(cacti, n_states) returns pos, inputs, bud_center, bud_radius.

plots in nocad.viz

plot_scc_hierarchy, plot_bipartite_matching, plot_control_cacti(kind="control"|"observation"), plot_structure_matrix(order="scc"|"natural"), plot_depth_map(adj, nodes, kind), plot_distance_matrix, plot_operability_plane(adj, drivers, sensors, r_max), plot_operability_summary(adj, method), and plot_annotation(adj, column), which colors the nodes by any column of the annotation table (section 2.3.1); the role and robustness maps of chapter 5 complete the set. Every view accepts NetworkX graphs, whose node names become the labels, and NetworkX pos dictionaries; nocad.plotting.as_pos_dict turns the layouts of this chapter into such dictionaries, and nocad.io.to_dot hands the hierarchy to Graphviz.

The hierarchy of the nine-state example of the NOCAD manual:

adj = load_nocad_example().adj 
design = nocad.InputOutputDesign().fit(adj) 
layout = hierarchy_layout(adj, direction="control") 
print("components per level:", [[(layout.condensation.members[c] + 1).tolist() for c in lv] for lv in layout.levels]) 
ax = plot_scc_hierarchy(adj, design.driver_nodes_, design.sensor_nodes_, matching=design.control_matching_)
   

Its control cactus, as lists:

cacti = control_cacti(adj, method="path_finding") 
for k, stem in enumerate(cacti.stems): 
    print(f"u{k + 1}: stem", [f"x{v + 1}" for v in stem]) 
for bud, (u, v), owner in zip(cacti.buds, cacti.attach, cacti.owner, strict=True): 
    print("bud", [f"x{w + 1}" for w in bud], f"attached by x{u + 1}->x{v + 1} to the cactus of u{owner + 1}")
   

Depths and regions:

rho_c = nocad.control_depth(adj, design.driver_nodes_) 
rho_o = nocad.observation_depth(adj, design.sensor_nodes_) 
print("control depth    ", rho_c.astype(int)) 
print("observation depth", rho_o.astype(int)) 
print("regions of the sensors", nocad.observation_regions(adj, design.sensor_nodes_) + 1)
   

The block-triangular matrix, the operability plane and the four-panel summary are one call each:

plot_structure_matrix(adj, order="scc", ax=axes[1], title="SCC (block-triangular) order")
                                                                     

                                                                     
   
axes = plot_operability_plane(hen.adj, design.driver_nodes_, design.sensor_nodes_, labels=hen.labels)
   
fig = plot_operability_summary(net.adj, method="path_finding", title="scale-free network, 40 states")
   

4.4 Examples

4.4.1 The SCC hierarchy

The nine-state example has five components (fig. 4.3): the source {x8} on top, the cycle {x4,x5,x6} below it, the cycle {x1,x2,x3} and the node x7 on the third level and the sink x9 at the bottom. The single driver node x8 sits on the only source component; the green matched edges run from it down through all levels. The observation view (fig. 4.4) counts the levels from the sinks, {x1,x2,x3} and {x9}, which carry the two sensor nodes x1 and x9.

Figure 4.3

Figure 4.3. Control view of the SCC hierarchy of the NOCAD example: the source component (blue halo) on top carries the driver node x8; matched edges in green.

Open in ColabExample plot_01_scc_hierarchy.py in the gallery

Figure 4.4

Figure 4.4. Observation view of the same network: levels are counted upward from the sink components (vermilion halos), which carry the sensor nodes x1 and x9.

A sparse random network with 30 nodes and mean degree 1.4 decomposes into 28 components on nine levels (fig. 4.5); its nine source and eleven sink components explain most of the twelve driver and twelve sensor nodes, the rest come from dilations. The parameter study of fig. 4.6 shows how the condensation of random networks changes with the density: the share of components and of source components falls steeply once a giant strongly connected component forms, and the number of levels peaks near mean degree one, where long chains of small components are most frequent.

Figure 4.5

Figure 4.5. SCC hierarchy of a sparse random network (30 nodes, mean degree 1.4): many trivial source components on top, each with its own driver node.

Figure 4.6

Figure 4.6. Number of components, source components and levels of the condensation of random networks (100 nodes, five networks per point) against the mean degree, relative to N.

4.4.2 The bipartite view

In the bipartite view of the NOCAD example (fig. 4.7) eight of the nine rows carry a horizontal matched edge; the remaining in-copy x8− has no edge at all, because x8 has no parent. The edge classes on the network show which matched edges are indispensable: x1→x2, x2→x3, x3→x1, x4→x5, x7→x9 and x8→x6 are critical, x5→x4, x5→x7, x6→x4 and x6→x7 ordinary, and the remaining five edges redundant. A star x1→{x2,x3,x4} is the smallest dilation (fig. 4.8): one out-copy and three in-copies form a fan, two leaves stay unmatched, and since any leaf may be the matched one, all three edges are ordinary. Across random networks (fig. 4.9) critical edges are frequent only in very sparse networks, redundant edges peak at intermediate densities, and dense networks consist almost entirely of ordinary, interchangeable edges.

Figure 4.7

Figure 4.7. Bipartite view of the NOCAD example with matched edges horizontal (left) and the edge classes on the network (right).

Open in ColabExample plot_02_bipartite_view.py in the gallery

Figure 4.8

Figure 4.8. A dilation in the bipartite view: the out-copy x1+ fans out to three in-copies, two of which remain unmatched in every maximum matching.

Figure 4.9

Figure 4.9. Shares of critical, ordinary and redundant edges of Erdős–Rényi networks with 150 nodes against the mean degree.

4.4.3 Control cacti

The control cactus of the NOCAD example (fig. 4.10) has the stem u1→x8→x6→x7→x9 and two buds: {x4,x5}, attached by x6→x4, and {x1,x2,x3}, attached by x4→x2 to the first bud, at depth two, because no edge leads to it from the stem. The observation cacti (fig. 4.11) mirror the picture: two stems end at the sensors, x2→x3→x1 and x8→x6→x7→x9, and the bud {x4,x5} is seen through the edge x4→x2.

Figure 4.10

Figure 4.10. Control cactus of the NOCAD example: the stem (blue) starts at the input u1, buds (green cycles) hang from distinguished edges (dashed orange); the other edges of the network in light gray.

Open in ColabExample plot_03_control_cacti.py in the gallery

Figure 4.11

Figure 4.11. Observation cacti of the NOCAD example, drawn mirrored: the stems end at the outputs y1 and y2.

The two designs of the cycle with a tail differ visibly (fig. 4.12): with signal sharing the cycle {x1,x2} stays a bud fed directly by the shared input, with path finding it has been opened into the stem. In the heat exchanger network of chapter 9 every exchanger contributes a two-node cycle and every unit a self-loop; one input controls the whole network through one stem carrying 21 buds, the deepest of them seven buds away from the stem (fig. 4.13). Path finding and the exact minimum give the same cactus structure here.

Figure 4.12

Figure 4.12. The cycle with a tail: with signal sharing (left) the matched source cycle is a bud on the shared input (dotted), with path finding (right) it is part of the stem.

Figure 4.13

Figure 4.13. Control cactus of the heat exchanger network (cactus edges only): one stem, 21 buds formed by exchanger cycles and self-loops, the deepest at depth seven.

4.4.4 The structure matrix

In natural order the non-zeros of the NOCAD example are scattered (fig. 4.14, left); in SCC order (right) they form a block lower triangular pattern whose diagonal blocks are the five components. The single non-zero of 𝐁 lies in the row of the source block {x8}, the two non-zeros of 𝐂 in columns of the sink blocks, and the matched entries (green rings) cover every row except that of x8. For the heat exchanger network (fig. 4.15) the design methods differ in 𝐂: path finding uses three outputs, one per sink component, signal sharing one output that reads the three sinks together.

Figure 4.14

Figure 4.14. Zero pattern of [ 𝐀 𝐁 𝐂 0 ] of the NOCAD example in natural order (left) and in block-triangular SCC order (right); source blocks outlined blue, sink blocks vermilion, matched entries ringed green.

Open in ColabExample plot_04_structure_matrix.py in the gallery

Figure 4.15

Figure 4.15. Structure matrix of the heat exchanger network for the path finding (left) and signal sharing (right) designs: the same 𝐁, different 𝐂.

4.4.5 Depth maps and the distance matrix

With the single driver x8 the control depths of the NOCAD example are (4,3,4,2,3,1,2,0,3) for x1,…,x9 (fig. 4.16): the states of the cycle {x1,x2,x3} are reached only after four edges, so their relative degree is five. The observation depths are (0,1,1,2,2,2,1,3,0); the sensor x1 is responsible for x1,…,x5, the sensor x9 for x6,…,x9. The distance matrix (fig. 4.17) shows the same numbers per driver; adding the driver x4 takes over all states except x8 and lowers the largest depth from four to two.

Figure 4.16

Figure 4.16. Control depth map with the driver x8 (left) and observation depth map with the sensors x1 and x9 (right); shaded hulls are the regions.

Open in ColabExample plot_05_depth_maps.py in the gallery

Figure 4.17

Figure 4.17. Distance matrices (number of derivations ℓ+1) for one driver, x8 (left), and for the drivers x4 and x8 (right); rows sorted by region and depth.

On the heat exchanger network (fig. 4.18) the single driver E9.h controls all 22 states, but the farthest only after seven edges (mean depth 3.95). Two drivers added by the GDFCMSA placement of chapter 8 lower the largest depth to four (mean 1.82), four added drivers to three (mean 1.14); the regions show which driver serves which part of the network.

Figure 4.18

Figure 4.18. Control depth maps of the heat exchanger network with one, three and five driver nodes.

4.4.6 The operability plane and the dashboard

The minimal design of the heat exchanger network, one driver and three sensors, spreads the states over the whole plane (fig. 4.19): control depths reach seven, observation depths six, and the longest shortest input–output walk through a state has nine edges. Requiring control and observation depths of at most two (dashed lines) needs six drivers and seven sensors; the cloud then collapses into the lower left corner (fig. 4.20).

Figure 4.19

Figure 4.19. Operability plane of the minimal design of the heat exchanger network: every state at its control and observation depth, with marginal counts.

Open in ColabExample plot_06_operability_plane.py in the gallery

Figure 4.20

Figure 4.20. Operability plane after GDFCMSA placement with depth bound two (dashed lines): six driver and seven sensor nodes.

The dashboard combines the views for a scale-free network with 40 states (fig. 4.21). The network has 38 components, 14 of them sources and 8 sinks. Path finding needs 14 driver and 11 sensor nodes: the hierarchy shows that every driver node sits on a source component and eight of the sensor nodes on sink components, the depth maps and the plane that all but two states lie within two edges of a driver node and of a sensor node.

Figure 4.21

Figure 4.21. Operability dashboard of a scale-free network with 40 states: SCC hierarchy with the designed inputs and outputs, control and observation depth maps, and the operability plane.

Open in ColabExample plot_07_dashboard.py in the gallery

4.5 Further reading

Layered drawing goes back to Sugiyama, Tagawa and Toda [38]; Gansner and co-authors [39] refined layering and coordinate assignment, Eades and Wormald [40] analyzed the barycenter and median heuristics, and Brandes and Köpf [41] gave a fast coordinate assignment. Tidy trees are due to Reingold and Tilford [43] and Walker [44]; the textbook of Di Battista, Eades, Tamassia and Tollis [47] covers all of these. Graph Voronoi diagrams were introduced by Erwig [45]. Lin’s cacti are in [5]; Liu, Slotine and Barabási [10] used them to explain the minimum input theorem, and the relation between distances and relative degrees is due to Daoutidis and Kravaris [18]. Munzner [36] discusses the effectiveness of visual channels that guided the design of the views.