From ded6222f392888b01e86394e7ebc68fd8186f96c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 13 Sep 2021 22:22:31 -0500 Subject: [PATCH] Added root functions. More work on LW --- main.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 6af6293..8f8eba9 100644 --- a/main.py +++ b/main.py @@ -3,12 +3,59 @@ #Professor: Dr. Sen, Fall 2021 #Noah Schrick - 1492657 -def main(): - print("Hello") - print("Now Hello") +import json -def likelihood_weighting(): - print("Hello") +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")