Submitted:
25 October 2024
Posted:
29 October 2024
You are already at the latest version
Abstract
Bayesian networks have emerged as a powerful tool for modelling complex probabilistic relationships in uncertain environments. The process of inducing Bayesian networks involves learning both the structure of the network and the parameters of the associated probability distributions. This paper provides a detailed examination of the two main approaches to Bayesian network induction: structure learning and parameter estimation, highlighting the use of both constraint-based and score-based techniques. Furthermore, the role of distribution-based methods in the estimation and inference of probabilistic models is explored. These methods, including Maximum Likelihood Estimation, Bayesian Estimation, and Monte Carlo techniques, offer robust ways to handle parameter uncertainty and facilitate efficient inference in large, complex models. This comprehensive view aims to bridge the gap between the theoretical foundations and practical applications of these methods, providing insights for researchers and practitioners in the field of machine learning and probabilistic reasoning.
Keywords:
1. Introduction
1.1. Structure Learning of Bayesian Networks
1.1.1. Constraint-Based Methods
1.1.2. Score-Based Methods
1.2. Parameter Learning of Bayesian Networks
1.2.1. Maximum Likelihood Estimation
1.2.2. Bayesian Estimation
1.3. Distribution-Based Methods in Bayesian Networks
1.3.1. Maximum Likelihood and Bayesian Estimation
1.3.2. Monte Carlo Methods
1.4. Challenges and Applications
2. Methodology
2.2. Structure Learning
2.2.1. Constraint-Based Methods
2.2.2. Score-Based Methods
- likelihood of the data given the graph and its maximum likelihood estimates
- is the number of free parameters in the model (determined by the structure of ),
- is the number of data points in .
2.3. Parameter Learning
2.3.1. Maximum Likelihood Estimation (MLE)
2.3.2. Bayesian Estimation
2.4. Monte Carlo Methods
2.5. Inference in Bayesian Networks
2.6. Conclusion
2.7. Computational Mehods
| Python Code: |
| # Install required packages !pip install pgmpy !pip install networkx !pip install matplotlib import numpy as np import pandas as pd import matplotlib.pyplot as plt import networkx as nx from pgmpy.models import BayesianNetwork from pgmpy.estimators import MaximumLikelihoodEstimator, BayesianEstimator, HillClimbSearch, BicScore from pgmpy.inference import VariableElimination from pgmpy.sampling import GibbsSampling from sklearn.model_selection import train_test_split # Generating more complex synthetic data with 6 variables np.random.seed(42) size = 2000 # Define more complex dependencies between variables X1 = np.random.binomial(1, 0.5, size=size) X2 = np.random.binomial(1, 0.6 * X1 + 0.4 * (1 - X1), size=size) X3 = np.random.binomial(1, 0.7 * X1 + 0.3 * X2, size=size) X4 = np.random.binomial(1, 0.5 * X2 + 0.5 * X3, size=size) X5 = np.random.binomial(1, 0.6 * X3 + 0.4 * X4, size=size) X6 = np.random.binomial(1, 0.7 * X4 + 0.3 * X5, size=size) # Create a DataFrame data = pd.DataFrame(data={'X1': X1, 'X2': X2, 'X3': X3, 'X4': X4, 'X5': X5, 'X6': X6}) # Visualize the pre-defined Bayesian Network structure graph = nx.DiGraph() graph.add_edges_from([('X1', 'X2'), ('X1', 'X3'), ('X2', 'X4'), ('X3', 'X4'), ('X3', 'X5'), ('X4', 'X6'), ('X5', 'X6')]) pos = nx.spring_layout(graph) plt.figure(figsize=(8, 8)) nx.draw(graph, pos, with_labels=True, node_size=3000, node_color='skyblue', font_size=16, font_weight='bold', arrowsize=20) plt.title('Pre-defined Bayesian Network Structure') plt.show() # Define the Bayesian Network structure model = BayesianNetwork([('X1', 'X2'), ('X1', 'X3'), ('X2', 'X4'), ('X3', 'X4'), ('X3', 'X5'), ('X4', 'X6'), ('X5', 'X6')]) # Split data into train and test sets train_data, test_data = train_test_split(data, test_size=0.3, random_state=42) # Parameter learning using Maximum Likelihood Estimation (MLE) model.fit(train_data, estimator=MaximumLikelihoodEstimator) # Inference using the trained model inference = VariableElimination(model) q1 = inference.query(variables=['X6'], evidence={'X1': 1, 'X2': 1, 'X4': 1}) # Parameter learning using Bayesian Estimation model.fit(train_data, estimator=BayesianEstimator, prior_type='BDeu') # Inference using Bayesian Estimation q2 = inference.query(variables=['X6'], evidence={'X1': 1, 'X2': 1, 'X4': 1}) # Hill-Climbing Search for structure learning hc = HillClimbSearch(train_data) best_model_hc = hc.estimate(scoring_method=BicScore(train_data)) # Visualizing the learned structure from Hill-Climbing plt.figure(figsize=(8, 8)) nx.draw(best_model_hc, pos, with_labels=True, node_size=3000, node_color='lightgreen', font_size=16, font_weight='bold', arrowsize=20) plt.title('Structure Learned via Hill-Climbing') plt.show() # Gibbs Sampling gibbs = GibbsSampling(model) samples = gibbs.sample(size=2000) # Display results print("MLE Inference (P(X6=1 | X1=1, X2=1, X4=1)): ", q1.values) print("Bayesian Inference (P(X6=1 | X1=1, X2=1, X4=1)): ", q2.values) print("Gibbs Sampling Example (First 5 samples):\n", samples.head()) |
3. Results
3.1. Pre-defined Bayesian Network Structure
- Edges:
- This means that depends on depends on both and depends on , and depends on both and . This structure represents the assumptions about how the variables influence one another.
- This learned structure may differ from the predefined one because it is based on the observed dependencies in the synthetic data. The Hill-Climbing search starts with an empty graph and iteratively adds, removes, or reverses edges to improve the fit of the structure to the data (based on a scoring function like BIC).
- The graph visualization here will show the learned relationships between the variables, which may include additional or missing edges compared to the predefined structure, depending on the data and the search process.
- Comparing the two graphs (predefined and learned), you will notice different dependencies inferred from the data, reflecting how the Hill-Climbing algorithm interprets the relationships among variables. These variations occur due to the search method used for structure learning.
3.2. Table Outputs
- The two values represent the conditional probability distribution of :
| X1 | X2 | X3 | X4 | X5 | X6 | |
| 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 | 0 | 0 |
| 2 | 1 | 0 | 1 | 0 | 0 | 0 |
| 3 | 1 | 0 | 0 | 0 | 0 | 0 |
| 4 | 0 | 1 | 0 | 0 | 0 | 0 |
- This table shows the sampled values of the six variables ( , and X6 ) after performing Gibbs sampling on the Bayesian network.
- Each row represents a sample, and the values in the columns represent the state ( 0 or 1 ) of each variable in that particular sample.
- In the first sample ( row 0 ), , and .
- In the second sample ( row 1 ), , and .
3.3. Graph Visualizations

-
Loss Graph (Left):
- The blue line shows the training loss, which starts high (~1.9) and decreases over time, indicating the model is learning during training
- The orange line shows the validation loss, which initially stays stable but then starts increasing after epoch 3-4
- The diverging pattern between training and validation loss (training going down while validation goes up) is a classic sign of overfitting, where the model is memorizing the training data but not generalizing well to new data
-
Accuracy Graph (Right):
- The blue line shows training accuracy, which steadily improves from ~50% to over 90%
-
The orange line shows validation accuracy, which:
- ○
- Stays relatively flat around 50-55% initially
- ○
- Has a spike around epoch 3 (~75%)
- ○
- Then drops significantly to around 40% and stays there
- Current step is 3/3
- Each step takes about 21ms
- The test loss is 0.7987
- The test accuracy is 65%
- The model performs increasingly well on training data (high accuracy, low loss)
- But performs poorly on validation data (increasing loss, decreasing accuracy)
- The divergence becomes particularly noticeable after epoch 3-4.
- Adding regularization
- Using dropout
- Reducing model complexity
- Adding more training data
- Implementing early stopping (perhaps around epoch 3 before overfitting becomes severe)
- Using data augmentation
4. Discussion
4.1. Bayesian Networks: Structure and Complexity
4.2. Parameter Learning: Maximum Likelihood and Bayesian Estimation
4.3. Inference: Variable Elimination and the Power of Probabilistic Reasoning
4.4. Gibbs Sampling: Approximate Inference
0 0 1 1 1 0 0
1 1 0 1 0 0 0
2 1 0 1 0 0 0
3 1 0 0 0 0 0
4 0 1 0 0 0 0
4.5. Practical Applications and Challenges
5. Conclusions
References
- Bishop, C.M. Pattern Recognition and Machine Learnin; Springer, 2006. [Google Scholar]
- Chickering, D.M. Optimal Structure Identification with Greedy Search. Journal of Machine Learning Research 2002, 3, 507–554. [Google Scholar]
- Cooper, G.F.; Herskovits, E. A Bayesian method for the induction of probabilistic networks from data. Machine Learning 1992, 9, 309–347. [Google Scholar] [CrossRef]
- Dempster, A.P.; Laird, N.M.; Rubin, D.B. Maximum likelihood from incomplete data via the EM algorithm. Journal of the Royal Statistical Society: Series B 1977, 39, 1–22. [Google Scholar] [CrossRef]
- Friedman, N.; Linial, M.; Nachman, I.; Pe'er, D. Using Bayesian networks to analyze expression data. Journal of Computational Biology 2000, 7, 601–620. [Google Scholar] [CrossRef] [PubMed]
- Gelman, A.; Carlin, J.B.; Stern, H.S.; Dunson, D.B.; Vehtari, A.; Rubin, D.B. Bayesian Data Analysis, 3rd ed.; CRC Press, 2013. [Google Scholar]
- Geman, S.; Geman, D. Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images. IEEE Transactions on Pattern Analysis and Machine Intelligence 1984, 6, 721–741. [Google Scholar] [CrossRef] [PubMed]
- Heckerman, D.; Geiger, D.; Chickering, D.M. Learning Bayesian networks: The combination of knowledge and statistical data. Machine Learning 1995, 20, 197–243. [Google Scholar] [CrossRef]
- Kalisch, M.; Bühlmann, P. Estimating high-dimensional directed acyclic graphs with the PC-algorithm. Journal of Machine Learning Research 2007, 8, 613–636. [Google Scholar]
- Koller, D.; Friedman, N. Probabilistic Graphical Models: Principles and Techniques; MIT Press, 2009. [Google Scholar]
- Lucas, P.J.; van der Gaag, L.C.; Abu-Hanna, A. Bayesian networks in biomedicine and healthcare. Artificial Intelligence in Medicine 2004, 30, 201–214. [Google Scholar] [CrossRef] [PubMed]
- Neal, R.M. Probabilistic inference using Markov chain Monte Carlo methods. In Technical Report CRG-TR-93-1; University of Toronto, 1993. [Google Scholar]
- Pearl, J. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference; Morgan Kaufmann, 1988. [Google Scholar]
- Robert, C. P.; Casella, G. Monte Carlo Statistical Methods, 2nd ed.; Springer, 2013. [Google Scholar]
- Schwarz, G. Estimating the dimension of a model. The Annals of Statistics 1978, 6, 461–464. [Google Scholar] [CrossRef]
- Spirtes, P.; Glymour, C.N.; Scheines, R. Causation, Prediction, and Search, 2nd ed.; MIT Press, 2000. [Google Scholar]
- Tsamardinos, I.; Brown, L.E.; Aliferis, C.F. The Max-Min Hill-Climbing Bayesian network structure learning algorithm. Machine Learning 2006, 65, 31–78. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).