Added root functions. More work on LW
This commit is contained in:
parent
867be1c23e
commit
ded6222f39
57
main.py
57
main.py
@ -3,12 +3,59 @@
|
|||||||
#Professor: Dr. Sen, Fall 2021
|
#Professor: Dr. Sen, Fall 2021
|
||||||
#Noah Schrick - 1492657
|
#Noah Schrick - 1492657
|
||||||
|
|
||||||
def main():
|
import json
|
||||||
print("Hello")
|
|
||||||
print("Now Hello")
|
|
||||||
|
|
||||||
def likelihood_weighting():
|
def main():
|
||||||
print("Hello")
|
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():
|
def gibbs_sampling():
|
||||||
print("Hello")
|
print("Hello")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user