lindermanlab / ssm

Bayesian learning and inference for state space models
MIT License
540 stars 196 forks source link

emissions: smooth functions fail when you don't pass in any inputs #122

Closed bantin closed 3 years ago

bantin commented 3 years ago

The following doesn't work with poisson emissions:

lds = ssm.LDS(N, K, D, emissions=poisson)
elbos, posterior = lds.fit(data)

expected_states = posterior.mean_discrete_states[0]
variational_mean = posterior.mean_continuous_states[0]
lambdas = lds.emissions.smooth(expected_states, variational_mean, y)
/Users/bantin/Documents/Linderman-Shenoy/ssm/ssm/emissions.py in forward(self, x, input, tag)
    172         return np.matmul(self.Cs[None, ...], x[:, None, :, None])[:, :, :, 0] \
    173             + np.matmul(self.Fs[None, ...], input[:, None, :, None])[:, :, :, 0] \
--> 174             + self.ds
    175 
    176     @ensure_args_are_lists

TypeError: 'NoneType' object is not subscriptable

The problem is that the smooth function defaults to setting input=None but then later, in self.forward we try to index into the input. Should be an easy fix: we can either redefine forward so that it doesn't require input to be an array, or we could make a dummy input that's all zeros.

I ran into this with Poisson emissions, but I'd guess it would crop up other places as well.