Skip to content

BUG: Kalman filter fails with 1-D complex Z_mat, T_mat, R_mat #3098

Closed

Description

@bashtage

This has been happening silently during test_arma_order_select_ic due to the broad except inside model.py. I found this when looking at the Hinv issue. The solution seems to be to ensure P is fortran contiguous

dcomplex[::1,:] P = asfortranarray(dot(pinv(identity(r**2)-kron(T_mat, T_mat)), 
                                   dot(R_mat,R_mat.T).ravel('F')).reshape(r,r, order='F'))

The ValueError was occurring during the attempt to compute the hessian, and was caught.

The traceback is

Traceback (most recent call last):
  File "C:\git\statsmodels\statsmodels\base\model.py", line 447, in fit
    H = -1 * self.hessian(xopt)
  File "C:\git\statsmodels\statsmodels\tsa\arima_model.py", line 593, in hessian
    return approx_hess_cs(params, self.loglike, args=(False,))
  File "C:\git\statsmodels\statsmodels\tools\numdiff.py", line 243, in approx_hess_cs
    **kwargs)).imag/2./hess[i, j]
  File "C:\git\statsmodels\statsmodels\tsa\arima_model.py", line 776, in loglike
    return self.loglike_kalman(params, set_sigma2)
  File "C:\git\statsmodels\statsmodels\tsa\arima_model.py", line 786, in loglike_kalman
    return KalmanFilter.loglike(params, self, set_sigma2)
  File "C:\git\statsmodels\statsmodels\tsa\kalmanf\kalmanfilter.py", line 666, in loglike
    R_mat, T_mat)
  File "statsmodels\tsa\kalmanf\kalman_loglike.pyx", line 359, in statsmodels.tsa.kalmanf.kalman_loglike.kalman_loglike_complex (statsmodels/tsa/kalmanf/kalman_loglike.c:6432)
    v, F, loglikelihood = kalman_filter_complex(y,k,p,q,r,nobs,Z_mat,R_mat,T_mat)
  File "statsmodels\tsa\kalmanf\kalman_loglike.pyx", line 229, in statsmodels.tsa.kalmanf.kalman_loglike.kalman_filter_complex (statsmodels/tsa/kalmanf/kalman_loglike.c:4956)
    dot(R_mat,R_mat.T).ravel('F')).reshape(r,r, order='F'))
  File "statsmodels\tsa\kalmanf\stringsource", line 644, in View.MemoryView.memoryview_cwrapper (statsmodels/tsa/kalmanf/kalman_loglike.c:14545)
  File "statsmodels\tsa\kalmanf\stringsource", line 345, in View.MemoryView.memoryview.__cinit__ (statsmodels/tsa/kalmanf/kalman_loglike.c:10820)
ValueError: ndarray is not Fortran contiguous

Activity

  1. bashtage commented on Jul 6, 2016

    @bashtage
    MemberAuthor

    @ChadFulton This might be up your alley to verify.

  2. added a commit that references this issue on Jul 6, 2016
    1a3a981
  3. ChadFulton commented on Jul 6, 2016

    @ChadFulton
    Member

    What you have looks right to me. I guess the original code had a misunderstanding about the effect of order='F' in reshape.

  4. ChadFulton commented on Jul 6, 2016

    @ChadFulton
    Member

    Yes, I see that the problem is fixed in the # initial variance computation (lines 73-74) in the same way that you have there.

  5. added a commit that references this issue on Jul 11, 2016
    7b24850
  6. added a commit that references this issue on Aug 10, 2016
    f793d5b
  7. added a commit that references this issue on Jan 27, 2017
    6c481f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions