#Project 1 for the University of Tulsa's CS-7313 Adv. AI Course #Approximate Inference Methods for Bayesian Networks #Professor: Dr. Sen, Fall 2021 #Noah Schrick - 1492657 import json def main(): bayes_net = import_bayes() print(len(bayes_net)) #print(is_root("3", bayes_net)) #Import the BN from the json def import_bayes(): with open ("gen-bn/bn.json") as json_file: bayes_json = json.load(json_file) json_file.close() return bayes_json #Checks if node has parents def is_root(node, BN): return (BN[node]["parents"]) == [] #Return a list of the root nodes def get_root(node, BN): roots = [] for i in range(len(BN)): if ((BN[node]["parents"]) == []): roots.append(node) return roots #print(bayes_json["x"]): prints the information about node x (an int) #print(bayes_json["x"]["parents"] prints the information about node x's parents #class BayesianNetwork: #Compute the estimate of P(X|e), where X is the query variable, and e is the observed value for variables E def likelihood_weighting(X, e, bayes_net, samples): #Vector of weighted counts for each value of X, initialized to zero W = {} #Init True and False probabilities T = 0 F = 0 for i in range(samples): x,w = weighted_sample(bayes_net, e) print("Hello") #Returns an event and a weight def weighted_sample(bayes_net, e): w = 1 #x = get_variable_nodes # for def gibbs_sampling(): print("Hello") def metropolis_hastings(): print("Hello") if __name__ == '__main__': main()