'Transform unconstrained parameters used by the optimizer to constrained
parameters used in likelihood evaluation
Parameters
unconstrained : array_like
Array of unconstrained parameters used by the optimizer, to be
transformed.
Returns
constrained : array_like
Array of constrained parameters which may be used in likelihood
evalation.
Notes
Constrains the factor transition to be stationary and variances to be
positive.'

def transform_params(self, unconstrained):

    unconstrained = np.array(unconstrained, ndmin=1)
    constrained = np.zeros(unconstrained.shape, dtype=unconstrained.dtype)
    constrained[self._params_trend] = unconstrained[self._params_trend]
    if ((self.k_ar > 0) and self.enforce_stationarity):
        if (self.error_cov_type == 'diagonal'):
            state_cov = np.diag((unconstrained[self._params_state_cov] ** 2))
        elif (self.error_cov_type == 'unstructured'):
            state_cov_lower = np.zeros(self.ssm['state_cov'].shape, dtype=unconstrained.dtype)
            state_cov_lower[self._idx_lower_state_cov] = unconstrained[self._params_state_cov]
            state_cov = np.dot(state_cov_lower, state_cov_lower.T)
        coefficients = unconstrained[self._params_ar].reshape(self.k_endog, (self.k_endog * self.k_ar))
        (coefficient_matrices, variance) = constrain_stationary_multivariate(coefficients, state_cov)
        constrained[self._params_ar] = coefficient_matrices.ravel()
    else:
        constrained[self._params_ar] = unconstrained[self._params_ar]
    if ((self.k_ma > 0) and self.enforce_invertibility):
        state_cov = np.eye(self.k_endog, dtype=unconstrained.dtype)
        coefficients = unconstrained[self._params_ma].reshape(self.k_endog, (self.k_endog * self.k_ma))
        (coefficient_matrices, variance) = constrain_stationary_multivariate(coefficients, state_cov)
        constrained[self._params_ma] = coefficient_matrices.ravel()
    else:
        constrained[self._params_ma] = unconstrained[self._params_ma]
    constrained[self._params_regression] = unconstrained[self._params_regression]
    if (self.error_cov_type == 'diagonal'):
        constrained[self._params_state_cov] = (unconstrained[self._params_state_cov] ** 2)
    elif (self.error_cov_type == 'unstructured'):
        constrained[self._params_state_cov] = unconstrained[self._params_state_cov]
    if self.measurement_error:
        constrained[self._params_obs_cov] = (unconstrained[self._params_obs_cov] ** 2)
    return constrained
