Controllability and Observability¶
Kalman-tests¶
Typical checks for controllability and observability are included in the functions listed below.
Warning
Note that these operations are numerically potentially
ill-conditioned due to the increasing powers in the tests. Hence
here included for completeness. However, for numerical purposes
harold
does not use these (see next section).
-
harold.
kalman_controllability
(G, compress=False)¶ Computes the Kalman controllability related quantities. The algorithm is the literal computation of the controllability matrix with increasing powers of A. Numerically, this test is not robust and prone to errors if the A matrix is not well-conditioned or its entries have varying order of magnitude as at each additional power of A the entries blow up or converge to zero rapidly.
Parameters: - G (State() or tuple of {(n,n),(n,m)} array_like matrices) – System or matrices to be tested
- compress (Boolean) – If set to True, then the returned controllability matrix is row compressed, and in case of uncontrollable modes, has that many zero rows.
Returns: - Cc ({(n,nxm)} 2D numpy array) – Kalman Controllability Matrix
- T ((n,n) 2D numpy arrays) – The transformation matrix such that T^T * Cc is row compressed and the number of zero rows at the bottom corresponds to the number of uncontrollable modes.
- r (integer) – Numerical rank of the controllability matrix
-
harold.
kalman_observability
(G, compress=False)¶ Computes the Kalman observability related objects. The algorithm is the literal computation of the observability matrix with increasing powers of A. Numerically, this test is not robust and prone to errors if the A matrix is not well-conditioned or too big as at each additional power of A the entries blow up or converge to zero rapidly.
Parameters: - G (State() or {(n,n),(n,m)} array_like matrices) – System or matrices to be tested
- compress (Boolean) – If set to True, then the returned observability matrix is row compressed, and in case of unobservability modes, has that many zero rows.
Returns: - Co ({(n,nxm)} 2D numpy array) – Kalman observability matrix
- T ((n,n) 2D numpy arrays) – The transformation matrix such that T^T * Cc is row compressed and the number of zero rows on the right corresponds to the number of unobservable modes.
- r (integer) – Numerical rank of the observability matrix
-
harold.
kalman_decomposition
(G, compute_T=False, output='system', cleanup_threshold=1e-09)¶ By performing a sequence of similarity transformations the State representation is transformed into a special structure such that if the system has uncontrollable/unobservable modes, the corresponding rows/columns of the B/C matrices have zero blocks and the modes are isolated in the A matrix. That is to say, there is no contribution of the controllable/observable states on the dynamics of these modes.
Note that, Kalman operations are numerically not robust. Hence the resulting decomposition might miss some ‘almost’ pole-zero cancellations. Hence, this should be used as a rough assesment tool but not as actual minimality check or maybe to demonstrate the concepts academic purposes to show the modal decomposition. Use cancellation_distance() and minimal_realization() functions instead with better numerical properties.
Example usage and verification :
G = State([[2,1,1],[5,3,6],[-5,-1,-4]],[[1],[0],[0]],[[1,0,0]],0) print('Is it Kalman Cont'ble ? ',is_kalman_controllable(G)) print('Is it Kalman Obsv'ble ? ',is_kalman_observable(G)) F = kalman_decomposition(G) print(F.a,F.b,F.c) H = minimal_realization(F.a,F.b,F.c) print('The minimal system matrices are:',*H)
Expected output :
Is it Kalman Cont'ble ? False Is it Kalman Obsv'ble ? False [[ 2. 0. -1.41421356] [ 7.07106781 -3. -7. ] [ 0. 0. 2. ]] [[-1.] [ 0.] [ 0.]] [[-1. 0. 0.]] The minimal system matrices are: [[ 2.]] [[ 1.]] [[ 1.]]
Warning
Kalman decomposition is often described in an ambigous fashion in the literature. I would like to thank Joaquin Carrasco for his generous help on this matter for his lucid argument as to why this is probably happening. This is going to be reimplemented with better tests on pathological models.
Parameters: - G (State()) – The state representation that is to be converted into the block triangular form such that unobservable/uncontrollable modes corresponds to zero blocks in B/C matrices
- compute_T (boolean) – Selects whether the similarity transformation matrix will be returned.
- output ({'system','matrices'}) – Selects whether a State() object or individual state matrices will be returned.
- cleanup_threshold (float) – After the similarity transformation, the matrix entries smaller than this threshold in absolute value would be zeroed. Setting this value to zero turns this behavior off.
Returns: Gk (State() or if output = ‘matrices’ is selected (A,B,C,D) tuple) – Returns a state representation or its matrices as a tuple
T ((nxn) 2D-numpy array) – If compute_T is True, returns the similarity transform matrix that brings the state representation in the resulting decomposed form such that
Gk.a = inv(T)*G.a*T Gk.b = inv(T)*G.b Gk.c = G.c*T Gk.d = G.d
-
harold.
is_kalman_controllable
(G)¶ Tests the rank of the Kalman controllability matrix and compares it with the A matrix size, returns a boolean depending on the outcome.
Parameters: G (State() or tuple of {(nxn),(nxm)} array_like matrices) – The system or the (A,B) matrix tuple Returns: test_bool – Returns True if the input is Kalman controllable Return type: Boolean
-
harold.
is_kalman_observable
(G)¶ Tests the rank of the Kalman observability matrix and compares it with the A matrix size, returns a boolean depending on the outcome.
Parameters: G (State() or tuple of {(nxn),(pxn)} array_like matrices) – The system or the (A,C) matrix tuple Returns: test_bool – Returns True if the input is Kalman observable Return type: Boolean
Cancellation Distance¶
Instead of checking a numerically ill-conditioned rank property, we use the metric of how small a perturbation is needed for the pencil \(\begin{bmatrix} \lambda I - A &B \end{bmatrix}\). If this quantity is less than a threshold we assume cancellation.
Minimal realization for state representations uses this metric. The method is implemented as described in [1].
-
harold.
cancellation_distance
(F, G)¶ Given matrices \(F,G\), computes the upper and lower bounds of the perturbation needed to render the pencil \(\left[ \begin{array}{c|c}F-pI & G\end{array}\right]\) rank deficient. It is used for assessing the controllability/observability degenerate distance and hence for minimality assessment.
Implements the algorithm given in D.Boley SIMAX vol.11(4) 1990.
Parameters: F,G (2D arrays) – Pencil matrices to be checked for rank deficiency distance Returns: - upper2 (float) – Upper bound on the norm of the perturbation \(\left[\begin{array}{c|c}dF & dG\end{array}\right]\) such that \(\left[\begin{array}{c|c}F+dF-pI & G+dG \end{array} \right]\) is rank deficient.
- upper1 (float) – A theoretically softer upper bound than the upper2 for the same quantity.
- lower0 (float) – Lower bound on the same quantity given in upper2
- e_f (complex) – Indicates the eigenvalue that renders [F + dF - pI | G + dG ] rank deficient i.e. equals to the p value at the closest rank deficiency.
- radius (float) – The perturbation with the norm bound “upper2” is located within a disk in the complex plane whose center is on “e_f” and whose radius is bounded by this output.
[1] | D. Boley, Estimating the Sensitivity of the Algebraic Structure of Pencils with Simple Eigenvalue Estimates, SIMAX 11-4 (1990), DOI |