'Setup the structural time series representation'

def setup(self):

    self.parameters = OrderedDict()
    self.parameters_obs_intercept = OrderedDict()
    self.parameters_obs_cov = OrderedDict()
    self.parameters_transition = OrderedDict()
    self.parameters_state_cov = OrderedDict()
    i = 0
    j = 0
    if self.irregular:
        self.parameters_obs_cov['irregular_var'] = 1
    if self.level:
        self.ssm[('design', 0, i)] = 1.0
        self.ssm[('transition', i, i)] = 1.0
        if self.trend:
            self.ssm[('transition', i, (i + 1))] = 1.0
        if self.stochastic_level:
            self.ssm[('selection', i, j)] = 1.0
            self.parameters_state_cov['level_var'] = 1
            j += 1
        i += 1
    if self.trend:
        self.ssm[('transition', i, i)] = 1.0
        if self.stochastic_trend:
            self.ssm[('selection', i, j)] = 1.0
            self.parameters_state_cov['trend_var'] = 1
            j += 1
        i += 1
    if self.seasonal:
        n = (self.seasonal_periods - 1)
        self.ssm[('design', 0, i)] = 1.0
        self.ssm['transition', i:(i + n), i:(i + n)] = companion_matrix(np.r_[(1, ([1] * n))]).transpose()
        if self.stochastic_seasonal:
            self.ssm[('selection', i, j)] = 1.0
            self.parameters_state_cov['seasonal_var'] = 1
            j += 1
        i += n
    if self.cycle:
        self.ssm[('design', 0, i)] = 1.0
        self.parameters_transition['cycle_freq'] = 1
        if self.damped_cycle:
            self.parameters_transition['cycle_damp'] = 1
        if self.stochastic_cycle:
            self.ssm['selection', i:(i + 2), j:(j + 2)] = np.eye(2)
            self.parameters_state_cov['cycle_var'] = 1
            j += 2
        self._idx_cycle_transition = np.s_['transition', i:(i + 2), i:(i + 2)]
        i += 2
    if self.autoregressive:
        self.ssm[('design', 0, i)] = 1.0
        self.parameters_transition['ar_coeff'] = self.ar_order
        self.parameters_state_cov['ar_var'] = 1
        self.ssm[('selection', i, j)] = 1
        self.ssm['transition', i:(i + self.ar_order), i:(i + self.ar_order)] = companion_matrix(self.ar_order).T
        self._idx_ar_transition = np.s_['transition', i, i:(i + self.ar_order)]
        j += 1
        i += self.ar_order
    if self.regression:
        if self.mle_regression:
            self.parameters_obs_intercept['reg_coeff'] = self.k_exog
        else:
            design = np.repeat(self.ssm['design', :, :, 0], self.nobs, axis=0)
            self.ssm['design'] = design.transpose()[np.newaxis, :, :]
            self.ssm['design', 0, i:(i + self.k_exog), :] = self.exog.transpose()
            self.ssm['transition', i:(i + self.k_exog), i:(i + self.k_exog)] = np.eye(self.k_exog)
            i += self.k_exog
    self.parameters.update(self.parameters_obs_cov)
    self.parameters.update(self.parameters_state_cov)
    self.parameters.update(self.parameters_transition)
    self.parameters.update(self.parameters_obs_intercept)
    self.k_obs_intercept = sum(self.parameters_obs_intercept.values())
    self.k_obs_cov = sum(self.parameters_obs_cov.values())
    self.k_transition = sum(self.parameters_transition.values())
    self.k_state_cov = sum(self.parameters_state_cov.values())
    self.k_params = sum(self.parameters.values())
    idx = np.diag_indices(self.ssm.k_posdef)
    self._idx_state_cov = ('state_cov', idx[0], idx[1])
