statespace mlemodel in statsmodel does not converge I'm trying to estimate the following state-space model:
$$
y_{t} = \begin{bmatrix}1& 1 \end{bmatrix}\begin{bmatrix}\mu_{t}\\v_{t}\end{bmatrix} + \epsilon_{t},\quad \epsilon_{t}\sim N(0,\sigma_{\epsilon})
$$
$$
\begin{bmatrix}\mu_{t+1}\\ v_{t+1} \end{bmatrix} = \begin{bmatrix}1 & 0 \\ 0 & \rho \end{bmatrix} \begin{bmatrix}\mu_{t} \\ v_{t} \end{bmatrix} + w_{t}, \quad w_{t}\sim (0, \begin{bmatrix}\sigma_{\eta_{t}} & 0\\ 0 & \sigma_{\xi_{t}} \end{bmatrix})
$$
The estimated covariance matrix is singular. I'm new to state-space models and many thanks in advance for your suggestions. The codes are attached.
class StateARModel(sm.tsa.statespace.MLEModel):

# Initialize the model
def __init__(self, endog):

    # Define the dimension of states
    super(StateARModel, self).__init__(endog, k_states=2, k_posdef=2)

    # Define matrix
    self.ssm['design'] = np.array([1,1])
    self.ssm['transition'] = np.eye(self.k_states)
    self.ssm['selection'] = np.eye(self.k_states)
    self.ssm['state_cov'] = np.eye(self.k_states)

    # Initialization
    init = initialization.Initialization(self.k_states)
    init.set((0,1), 'stationary')
    init.set((1,4), 'diffuse')
    self.ssm.initialize(init)


# constrain parameters
def transform_params(self, unconstrained):
    constrained = np.zeros_like(unconstrained)
    constrained[:1] = constrain_stationary_univariate(unconstrained[:1])
    constrained[1:] = unconstrained[1:]**2
    return constrained

def untransform_params(self, constrained):
    unconstrained = np.zeros_like(constrained)
    unconstrained[:1] = unconstrain_stationary_univariate(constrained[:1])
    unconstrained[1:] = constrained[1:]**0.5
    return unconstrained

# parameter names
@property
def param_names(self):
    return ['rho', 'sigma2.measurement', 'sigma2.level', 'sigma2.AR']

# start parameters
# @property
def start_params(self):
    y = self.endog[1:]
    X = sm.add_constant(self.endog[:-1])
    ols = sm.OLS(y, X).fit()
    ols_params = ols.params[1]
    return [ols_params] + [np.var(self.endog)]*3

# update parameters
def update(self, params, **kwargs):
    
    params = super().update(params, **kwargs)
    self.ssm['transition', 1, 1] = params[0]
    self.ssm['obs_cov', 0, 0] = params[1]
    # self.ssm['state_cov', 0, 0] = params[2]
    # self.ssm['state_cov', 1, 1] = params[3]
    self['state_cov'] = np.diag([params[2], params[3]])

armodel = ssm_estimate.StateARModel(input_data)
armodel_res = armodel.fit(method='nm', maxiter=5000)

Data can be downloaded here: data


The main issue here seems to be the initialization of the state vector. You have set the first state to be stationary and the second state to be diffuse, but since the autoregressive component is the second state, you likely meant it to be the other way around.
When I use:
init.set((0,1), 'diffuse')
init.set((1,2), 'stationary')

Then estimation converged for me without a problem.
