def _get_observability_matrix_decomposition(self) -> Decomposition: """ Calculate the eigenvalue decomposition of the estimate of the observability matrix as per N4SID. """ u_hankel = Utils.block_hankel_matrix(self.u_array, self.num_block_rows) y_hankel = Utils.block_hankel_matrix(self.y_array, self.num_block_rows) u_and_y = np.concatenate([u_hankel, y_hankel]) observability = self.R32 @ np.linalg.pinv(self.R22) @ u_and_y observability_decomposition = Utils.reduce_decomposition( Utils.eigenvalue_decomposition(observability), self.x_dim) return observability_decomposition
def test_eigenvalue_decomposition(self): matrix = np.fliplr(np.diag(range(1, 3))) decomposition = Utils.eigenvalue_decomposition(matrix) self.assertTrue( np.all( np.isclose([[0, -1], [-1, 0]], decomposition.left_orthogonal))) self.assertTrue( np.all(np.isclose([2, 1], np.diagonal(decomposition.eigenvalues)))) self.assertTrue( np.all( np.isclose([[-1, 0], [0, -1]], decomposition.right_orthogonal))) reduced_decomposition = Utils.reduce_decomposition(decomposition, 1) self.assertTrue( np.all( np.isclose([[0], [-1]], reduced_decomposition.left_orthogonal))) self.assertTrue( np.all(np.isclose([[2]], reduced_decomposition.eigenvalues))) self.assertTrue( np.all( np.isclose([[-1, 0]], reduced_decomposition.right_orthogonal)))