jmschrei / pomegranate

Fast, flexible and easy to use probabilistic modelling in Python.
http://pomegranate.readthedocs.org/en/latest/
MIT License
3.38k stars 590 forks source link

Bayesian Network from_samples #1116

Closed janluca-drs closed 2 months ago

janluca-drs commented 3 months ago

Hi,

Thank you for your work on the package! I am currently updating a project to v1.0 and am having some troubles with Bayesian networks. The documentation here talks about inference from structure being possible and then references a tutorial for that, which I am unable to find.

I would like to replace a call of bn.from_samples(), I guess I can somehow use fit() for that? I'm afraid I am not the most knowledgeable in the topic and the machine learning is more of a sub-module of the project.

I have tried replacing bn_model = pomegranateBN.from_samples( samples, state_names=keys, algorithm=self.algorithm ) with bn_model = BayesianNetwork(algorithm=self.algorithm) bn_model.fit(samples). Is there a way to replace state_namesas well as to_dict() with this solution?

Any and all help appreciated, thank you so much!

Best, Luca

jmschrei commented 3 months ago

Hi Luca

Yes, you should be able to use fit just like you previously used from_samples. There is no need to use state_names as well because the models in v1.0.0 no longer keep track of their names. You would just keep track of what index corresponded to what variable name on your end. This change (having everything internally only be indexes as opposed to also trying to keep track of strings) made things significantly simpler internally.

If you want to save the model, you can use torch.save just like you would with any PyTorch model.