Added root functions. More work on LW

This commit is contained in:
BuildTools 2021-09-13 22:22:31 -05:00
parent 867be1c23e
commit ded6222f39

55
main.py
View File

@ -3,13 +3,60 @@
#Professor: Dr. Sen, Fall 2021
#Noah Schrick - 1492657
def main():
print("Hello")
print("Now Hello")
import json
def likelihood_weighting():
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")