'Transform unconstrained parameters used by the optimizer to constrained
parameters used in likelihood evaluation.
Used primarily to enforce stationarity of the autoregressive lag
polynomial, invertibility of the moving average lag polynomial, and
positive variance parameters.
Parameters
unconstrained : array_like
Unconstrained parameters used by the optimizer.
Returns
constrained : array_like
Constrained parameters used in likelihood evaluation.
Notes
If the lag polynomial has non-consecutive powers (so that the
coefficient is zero on some element of the polynomial), then the
constraint function is not onto the entire space of invertible
polynomials, although it only excludes a very small portion very close
to the invertibility boundary.'

def transform_params(self, unconstrained):

    unconstrained = np.array(unconstrained, ndmin=1)
    constrained = np.zeros(unconstrained.shape, unconstrained.dtype)
    start = end = 0
    if (self.k_trend > 0):
        end += self.k_trend
        constrained[start:end] = unconstrained[start:end]
        start += self.k_trend
    if self.mle_regression:
        end += self.k_exog
        constrained[start:end] = unconstrained[start:end]
        start += self.k_exog
    if (self.k_ar_params > 0):
        end += self.k_ar_params
        if self.enforce_stationarity:
            constrained[start:end] = constrain_stationary_univariate(unconstrained[start:end])
        else:
            constrained[start:end] = unconstrained[start:end]
        start += self.k_ar_params
    if (self.k_ma_params > 0):
        end += self.k_ma_params
        if self.enforce_invertibility:
            constrained[start:end] = (- constrain_stationary_univariate(unconstrained[start:end]))
        else:
            constrained[start:end] = unconstrained[start:end]
        start += self.k_ma_params
    if (self.k_seasonal_ar > 0):
        end += self.k_seasonal_ar_params
        if self.enforce_stationarity:
            constrained[start:end] = constrain_stationary_univariate(unconstrained[start:end])
        else:
            constrained[start:end] = unconstrained[start:end]
        start += self.k_seasonal_ar_params
    if (self.k_seasonal_ma_params > 0):
        end += self.k_seasonal_ma_params
        if self.enforce_invertibility:
            constrained[start:end] = (- constrain_stationary_univariate(unconstrained[start:end]))
        else:
            constrained[start:end] = unconstrained[start:end]
        start += self.k_seasonal_ma_params
    if (self.state_regression and self.time_varying_regression):
        end += self.k_exog
        constrained[start:end] = (unconstrained[start:end] ** 2)
        start += self.k_exog
    if self.measurement_error:
        constrained[start] = (unconstrained[start] ** 2)
        start += 1
        end += 1
    if self.state_error:
        constrained[start] = (unconstrained[start] ** 2)
    return constrained
