Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linalg Error during fit with Newton's Method #94

Open
bantin opened this issue Mar 13, 2020 · 1 comment
Open

Linalg Error during fit with Newton's Method #94

bantin opened this issue Mar 13, 2020 · 1 comment

Comments

@bantin
Copy link
Collaborator

bantin commented Mar 13, 2020

Certain parameter settings seem to give LinalgErrors when using Newton's method for the Continuous parameter update. This happens even with a simple gaussian LDS, for which Laplace-EM with Newton's method should be exact. This reproduces the error for me:

import ssm
import numpy as np
N, K, D, T = 10, 1, 30, 100
np.random.seed(seed=123)
true_slds = ssm.LDS(N, D, dynamics="gaussian", emissions="gaussian")
x, y = true_slds.sample(T)
fit_lds = ssm.LDS(N, D, dynamics="gaussian", emissions="gaussian")
fit_lds.fit(y, num_iters=20)

And the resulting error:

 File "/Users/bantin/Documents/Linderman-Shenoy/ssm/ssm/lds.py", line 618, in _fit_laplace_em_continuous_state_update
    tolerance=continuous_tolerance, maxiter=continuous_maxiter)
  File "/Users/bantin/Documents/Linderman-Shenoy/ssm/ssm/optimizers.py", line 162, in newtons_method_block_tridiag_hessian
    dx = -1.0 * solve_symm_block_tridiag(H_diag, H_lower_diag, g)
  File "/Users/bantin/Documents/Linderman-Shenoy/ssm/ssm/primitives.py", line 240, in solve_symm_block_tridiag
    x_flat = solveh_banded(J_banded, np.ravel(v), lower=True)
  File "/Users/Bantin/anaconda3/lib/python3.7/site-packages/autograd/tracer.py", line 48, in f_wrapped
    return f_raw(*args, **kwargs)
  File "/Users/Bantin/anaconda3/lib/python3.7/site-packages/scipy/linalg/basic.py", line 587, in solveh_banded
    raise LinAlgError("%d-th leading minor not positive definite" % info)
numpy.linalg.LinAlgError: 51-th leading minor not positive definite

This means that somehow the Hessian here is not PSD.

@bantin
Copy link
Collaborator Author

bantin commented Mar 14, 2020

Per discussion with Scott (@slinderman) we've partially addressed this in 7e5deb2 by increasing the regularization for the dynamics covariance matrix update. For now, we'll switch the default continuous_optimizer to "lbfgs".

When debugging we also found the Newton's method is not always solving the resulting quadratic problem in a single step (as would be expected for a vanilla LDS where the expected log-joint is quadratic in x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant