erdogant / bnlearn

Python library for learning the graphical structure of Bayesian networks, parameter learning, inference and sampling methods.
https://erdogant.github.io/bnlearn
Other
463 stars 45 forks source link

Structure learning algorithms have very unstable performance #92

Closed itschenxi closed 4 months ago

itschenxi commented 7 months ago

Hi,

I am testing bnlearn and found that the structure learning algorithms are very unstable, sometimes they generate very accurate results, sometimes very inaccurate results. I am testing the asia example and the searching algorithms include hc and cs, scoretype="bic". Could anybody explain why? Is it because of random? Thank you very much indeed.

model_true=bn.import_DAG('asia')
df=bn.sampling(model_true, n=10000)
model_learned=bn.structure_learning.fit(df)
bn.compare_networks(model_true, model_learned)
erdogant commented 6 months ago

This can happen due to the stochastic component thats in the algorithms. The starting position of the search space is (usually) random which means that it can become stuck in a local optimum. In addition, if you would use different algorithms, they would likely also return (slightly) different results. One way to be more confident about the results it is by running it a few times and (testing) whether a structure is more often returned. The best way to validate the results is using an external source. For example when using genes, you would like to perform a real lab experiment.

erdogant commented 4 months ago

If there is anything else, let me know.