aimclub / BAMT

Repository of a data modeling and analysis tool based on Bayesian networks
https://bamt.readthedocs.io
BSD 3-Clause "New" or "Revised" License
116 stars 17 forks source link

How can I use BIC instead of K2 score? #117

Open EsqYu opened 5 days ago

EsqYu commented 5 days ago

Hi.

I wonder how I can use BIC score instead of K2 score in the add_edges method. I executed the code below, changing scoring function since K2 score seems to be used only in a case that all the variables are discretized. However, it didn't work and the error message says "Hybrid BN does not support continuous data".

from pgmpy.estimators import BicScore hybrid_bn = HybridBN(has_logit=False, use_mixture=True) hybrid_bn.add_edges(data, scoring_function=("Bic",BicScore)) hybrid_bn.fit_parameters(data)

Anaxagor commented 5 days ago

BicScore also only works with discretized data. Currently, structural learning can only be done on discretized data, while parameters learning can be done on initial data without discretization.

EsqYu commented 5 days ago

Thank you for your reply. Then, if I want to apply BAMT on mixed or continuous data without discretization, all I can do is parameters learning? When I only do parameters learning, just execute bn.fit_parameters()?

Anaxagor commented 5 days ago

Yes, parameters learning you can apply without discretization via function bn.fit_parameters().

EsqYu commented 4 days ago

Thank you. I'm just wondering how I can do parameters learning without structure learning. In that case, should I use other algorithm and determine the structure and then use this bn.fit_parameters?

Anaxagor commented 3 days ago

The structure must be specified anyway in a Bayesian network, this can be done by simply passing a list of edges to the method bn.set_structure(edges=structure). Parametric training can then be run as before bn.fit_parameters. There is an example in the documentation https://bamt.readthedocs.io/en/latest/examples/read_structure_param_learning.html