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

How to sample from the posterior distribution using the Bayesian module? #73

Open
sgbaird opened this issue Jan 7, 2022 · 3 comments
Open

Comments

@sgbaird
Copy link
Contributor

sgbaird commented Jan 7, 2022

I didn't notice anything obvious within modnet/models/bayesian.py

@ppdebreuck
Copy link
Owner

The Bayesian module is somewhat deprecated, as the results didn't turn out as good as hoped and the EnsembleMODNetModel should be preferred.

Nevertheless, sampling can be done using model.predict(x) (single outcome, should be repeated to form Monte-Carlo experiment) or model(x) giving a tensorflow_probability.distributions.Distribution. With model the Keras model (not the MODNet one). Currently the BayesianMODNetModel takes 1000 samples and computes the mean and std.

for i in range(1000):
p = self.model.predict(x)
if len(self.targets_flatten) == 1:
p = np.array([p])
all_predictions.append(p)

Anyway, if you have some ideas to improve, or successful applications with this module, I would be happy to discuss !

@sgbaird
Copy link
Contributor Author

sgbaird commented Jan 8, 2022

Ah, gotcha. Thank you! That's too bad about the results. I've been looking into converting (my fork of) CrabNet into a Bayesian transformer network via e.g. BayesFormers, but it seems like it could be pretty involved, so I was pleased to see MODNet had some Bayesian facilities already in place.

Have you thought about trying bayesian.py, ensemble.py, and FitGenetic under a single routine (i.e. "ensemble of genetically optimized Bayesian models")? In this case, sampling from the posterior might just look like taking the average of a single posterior sample from each model within the ensemble.

@ppdebreuck
Copy link
Owner

No, I haven't spent much time on the Bayesian model to be honest. Might be something to explore in the future ...

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