Macro Programming through Bayesian Networks: Distributed Inference and Anomaly Detection