

def solve_discrete_lyapunov(a, q, complex_step=False):
    '\n    Solves the discrete Lyapunov equation using a bilinear transformation.\n\n    Notes\n    -----\n    This is a modification of the version in Scipy (see\n    https://github.com/scipy/scipy/blob/master/scipy/linalg/_solvers.py)\n    which allows passing through the complex numbers in the matrix a\n    (usually the transition matrix) in order to allow complex step\n    differentiation.\n    '
    eye = np.eye(a.shape[0])
    if (not complex_step):
        aH = a.conj().transpose()
        aHI_inv = np.linalg.inv((aH + eye))
        b = np.dot((aH - eye), aHI_inv)
        c = (2 * np.dot(np.dot(np.linalg.inv((a + eye)), q), aHI_inv))
        return solve_sylvester(b.conj().transpose(), b, (- c))
    else:
        aH = a.transpose()
        aHI_inv = np.linalg.inv((aH + eye))
        b = np.dot((aH - eye), aHI_inv)
        c = (2 * np.dot(np.dot(np.linalg.inv((a + eye)), q), aHI_inv))
        return solve_sylvester(b.transpose(), b, (- c))

dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/statespace/tools.py solve_discrete_lyapunov/original