

def constrain_stationary_multivariate_python(unconstrained, error_variance, transform_variance=False, prefix=None):
    '\n    Transform unconstrained parameters used by the optimizer to constrained\n    parameters used in likelihood evaluation for a vector autoregression.\n\n    Parameters\n    ----------\n    unconstrained : array or list\n        Arbitrary matrices to be transformed to stationary coefficient matrices\n        of the VAR. If a list, should be a list of length `order`, where each\n        element is an array sized `k_endog` x `k_endog`. If an array, should be\n        the matrices horizontally concatenated and sized\n        `k_endog` x `k_endog * order`.\n    error_variance : array\n        The variance / covariance matrix of the error term. Should be sized\n        `k_endog` x `k_endog`. This is used as input in the algorithm even if\n        is not transformed by it (when `transform_variance` is False). The\n        error term variance is required input when transformation is used\n        either to force an autoregressive component to be stationary or to\n        force a moving average component to be invertible.\n    transform_variance : boolean, optional\n        Whether or not to transform the error variance term. This option is\n        not typically used, and the default is False.\n    prefix : {\'s\',\'d\',\'c\',\'z\'}, optional\n        The appropriate BLAS prefix to use for the passed datatypes. Only\n        use if absolutely sure that the prefix is correct or an error will\n        result.\n\n    Returns\n    -------\n    constrained : array or list\n        Transformed coefficient matrices leading to a stationary VAR\n        representation. Will match the type of the passed `unconstrained`\n        variable (so if a list was passed, a list will be returned).\n\n    Notes\n    -----\n    In the notation of [1]_, the arguments `(variance, unconstrained)` are\n    written as :math:`(\\Sigma, A_1, \\dots, A_p)`, where :math:`p` is the order\n    of the vector autoregression, and is here determined by the length of\n    the `unconstrained` argument.\n\n    There are two steps in the constraining algorithm.\n\n    First, :math:`(A_1, \\dots, A_p)` are transformed into\n    :math:`(P_1, \\dots, P_p)` via Lemma 2.2 of [1]_.\n\n    Second, :math:`(\\Sigma, P_1, \\dots, P_p)` are transformed into\n    :math:`(\\Sigma, \\phi_1, \\dots, \\phi_p)` via Lemmas 2.1 and 2.3 of [1]_.\n\n    If `transform_variance=True`, then only Lemma 2.1 is applied in the second\n    step.\n\n    While this function can be used even in the univariate case, it is much\n    slower, so in that case `constrain_stationary_univariate` is preferred.\n\n    References\n    ----------\n    .. [1] Ansley, Craig F., and Robert Kohn. 1986.\n       "A Note on Reparameterizing a Vector Autoregressive Moving Average Model\n       to Enforce Stationarity."\n       Journal of Statistical Computation and Simulation 24 (2): 99-106.\n    .. [2] Ansley, Craig F, and Paul Newbold. 1979.\n       "Multivariate Partial Autocorrelations."\n       In Proceedings of the Business and Economic Statistics Section, 349-53.\n       American Statistical Association\n\n    '
    use_list = (type(unconstrained) == list)
    if (not use_list):
        (k_endog, order) = unconstrained.shape
        order //= k_endog
        unconstrained = [unconstrained[:k_endog, (i * k_endog):((i + 1) * k_endog)] for i in range(order)]
    order = len(unconstrained)
    k_endog = unconstrained[0].shape[0]
    sv_constrained = _constrain_sv_less_than_one_python(unconstrained, order, k_endog)
    (constrained, var) = _compute_coefficients_from_multivariate_pacf_python(sv_constrained, error_variance, transform_variance, order, k_endog)
    if (not use_list):
        constrained = np.concatenate(constrained, axis=1).reshape(k_endog, (k_endog * order))
    return (constrained, var)

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