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

Can't pickle Poisson Emissions posterior object #106

Open
bantin opened this issue May 27, 2020 · 0 comments
Open

Can't pickle Poisson Emissions posterior object #106

bantin opened this issue May 27, 2020 · 0 comments

Comments

@bantin
Copy link
Collaborator

bantin commented May 27, 2020

If I create and fit an LDS with Poisson emissions, I can't pickle the resulting posterior object:

AttributeError: Can't pickle local object '_PoissonEmissionsMixin.__init__.<locals>.<lambda>'

This is bad-news-bears because we need a way of saving the output after fitting models. I think the cause is that you can't pickle lambda functions. Currently we use lambda functions in the init:

def __init__(self, N, K, D, M=0, single_subspace=True, link="softplus", bin_size=1.0, **kwargs):
        super(_PoissonEmissionsMixin, self).__init__(N, K, D, M, single_subspace=single_subspace, **kwargs)

        self.link_name = link
        self.bin_size = bin_size
        mean_functions = dict(
            log=lambda x: np.exp(x) * self.bin_size,
            softplus= lambda x: softplus(x) * self.bin_size
            )
        self.mean = mean_functions[link]

        link_functions = dict(
            log=lambda rate: np.log(rate) - np.log(self.bin_size),
            softplus=lambda rate: inv_softplus(rate / self.bin_size)
            )
        self.link = link_functions[link]

The solution here is probably to define the link/inverse links via def.

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