def setUp(self): cNode = Node.BayesNode(0, 2, index=0, name="cloudy") sNode = Node.BayesNode(1, 2, index=1, name="sprinkler") rNode = Node.BayesNode(2, 2, index=2, name="rain") wNode = Node.BayesNode(3, 2, index=3, name="wetgrass") self.nodes = [cNode, sNode, rNode, wNode] self.potential = Distribution.Potential(self.nodes, default=1)
def __init__(self, name, variables): self.name = name self.variables = set(variables) self.potential = Distribution.Potential(self.variables) self.visited = False self.neighbors_separator = set() self.num_var = len(self.variables)
def testBasicDiv(self): assert all(self.potential.table == 1) other = Distribution.Potential(self.nodes, default=2) new = self.potential / other assert all(new.table == 0.5) assert all(self.potential.table == 1) self.potential /= other assert all(new.table == 0.5)
def reinit_potential(self): self.potential = Distribution.Potential(self.var)
def __init__(self, name, cx, cy): self.name = name self.var = cx.variables.intersection(cy.variables) self.potential = Distribution.Potential(self.var) self.visited = False self.neighbors = [cx, cy]
def testBasicMultiply(self): new = self.potential * Distribution.Potential(self.nodes[1:3], default=3) # This just checks their nodesets are equal assert (len(new.nodes) == len(self.potential.nodes))
def testPotentialEQ(self): new = Distribution.Potential(self.nodes) assert (self.potential == new)