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

Numerical instabilities in Laplace EM for Poisson emissions with large spike counts #129

Open
slinderman opened this issue Mar 15, 2021 · 2 comments

Comments

@slinderman
Copy link
Collaborator

@KeAWang and @kochalka and I are trying to debug a bunch of NaNs in the Newton update for the continuous states in Laplace EM. I'll follow up with more details, but it looks like the issues arise in cases where we have large spike counts and Poisson or OrthogonalPoisson emissions. I found a few places where it looked like we could get divide by zero errors in the likelihood and Hessian calculations, but haven't tracked it down yet.

@KeAWang
Copy link

KeAWang commented Mar 15, 2021

I tried a more numerically stable version of inv_softplus (from cornellius-gp/gpytorch#776):

def inv_softplus(y):
    return y + np.log(-np.expm1(-y))

to replace what's in ssm.utils, but still getting errors.

@slinderman
Copy link
Collaborator Author

@KeAWang and @kochalka, as a workaround, it looks like it should work if you use lbfgs instead of newton for the continuous state update.

# Fit the model using Laplace-EM with a structured variational posterior
q_lem_elbos, q_lem = slds.fit(train_data, method="laplace_em",
                              variational_posterior="structured_meanfield",
                              num_iters=num_iters, alpha=0.0,
                              continuous_optimizer="lbfgs")

You might still have to add a little bias to the output of the softplus in order to ensure the rates aren't numerically zero. Otherwise you'll get nan's in the likelihoods.

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

2 participants