Weighted Sample changes
This commit is contained in:
parent
ded6222f39
commit
ed5514b3d8
24
main.py
24
main.py
@ -4,10 +4,12 @@
|
|||||||
#Noah Schrick - 1492657
|
#Noah Schrick - 1492657
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
bayes_net = import_bayes()
|
bayes_net = import_bayes()
|
||||||
print(len(bayes_net))
|
print(len(bayes_net))
|
||||||
|
print(bayes_net["0"]["prob"][0][1])
|
||||||
#print(is_root("3", bayes_net))
|
#print(is_root("3", bayes_net))
|
||||||
|
|
||||||
#Import the BN from the json
|
#Import the BN from the json
|
||||||
@ -52,8 +54,28 @@ def likelihood_weighting(X, e, bayes_net, samples):
|
|||||||
#Returns an event and a weight
|
#Returns an event and a weight
|
||||||
def weighted_sample(bayes_net, e):
|
def weighted_sample(bayes_net, e):
|
||||||
w = 1
|
w = 1
|
||||||
#x = get_variable_nodes
|
sample = {}
|
||||||
|
#Elements in event x
|
||||||
|
for node in bayes_net:
|
||||||
|
#if bayes_net[e]["prob"][node] != None:
|
||||||
|
if e[node] !=None:
|
||||||
|
w*= bayes_net[node]["prob"][sample][1]
|
||||||
|
sample[node] = e[node]
|
||||||
|
else:
|
||||||
|
#Random sample
|
||||||
|
random_sample = random()
|
||||||
|
sample[node] = #True or False
|
||||||
|
|
||||||
|
#v
|
||||||
|
|
||||||
|
#for i in range(len(n)):
|
||||||
|
|
||||||
|
#Given a node in the bayes net and a random sample, determine if it should be
|
||||||
|
#classified as True or False
|
||||||
|
def get_bool(node, rand_sample, sample_table, BN):
|
||||||
|
table = {}
|
||||||
|
if is_root(node, BN):
|
||||||
|
table
|
||||||
|
|
||||||
# for
|
# for
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user