Esempio n. 1
0
    def testMultEmpty(self):
        newpot = self.pot * potential()
        self.assertTwoPot(newpot, self.pot)
        newpot = None

        newpot = potential() * self.pot
        self.assertTwoPot(newpot, self.pot)
Esempio n. 2
0
    def testMultEmpty(self):
        newpot = self.pot * potential()
        self.assertTwoPot(newpot, self.pot)
        newpot = None

        newpot = potential() * self.pot
        self.assertTwoPot(newpot, self.pot)
Esempio n. 3
0
    def testMatchPot(self):
        """all variables's dimensions are match in pot"""
        pot = [potential() for i in range(4)]
        pot[0].variables = np.array([0])
        pot[0].card = np.array([2])
        pot[0].table = np.zeros(2)

        pot[1].variables = np.array([1])
        pot[1].card = np.array([3])
        pot[1].table = np.zeros(3)

        pot[2].variables = np.array([2, 0, 1])
        pot[2].card = np.array([4, 2, 3])
        pot[2].table = np.zeros((4, 2, 3))

        pot[3].variables = np.array([3, 1])
        pot[3].card = np.array([3])
        pot[3].table = np.zeros((2, 3))

        v, ns, con, convec = potvariables(pot)
        #pot.dispose()
        pot = None
        self.assertEqual(v, [0, 1, 2, 3])
        self.assertEqual(ns, [2, 3, 4, 2])
        self.assertEqual(con, 1)
        self.assertEqual(convec, [1, 1, 1, 1])
Esempio n. 4
0
    def testMult(self):
        otherpot = potential()
        otherpot.variables = np.array([3])
        otherpot.card = np.array([3])
        otherpot.table = np.array([0.1, 0.4, 0.5])
        answerpot = potential()
        answerpot.variables = np.array([1, 2, 3])
        answerpot.card = np.array([2, 2, 3])
        answerpot.table = np.array([[[0.02, 0.08, 0.1], [0.08, 0.32, 0.4]], [[0.06, 0.24, 0.3], [0.04, 0.16, 0.2]]])
        self.assertTwoPot(self.pot * otherpot, answerpot)

        otherpot = potential()
        otherpot.variables = np.array([3, 1])
        otherpot.card = np.array([3, 2])
        otherpot.table = np.array([[0.2, 0.3], [0.2, 0.2], [0.6, 0.5]])
        answerpot = potential()
        answerpot.variables = np.array([1, 2, 3])
        answerpot.card = np.array([2, 2, 3])
        answerpot.table = np.array([[[0.04, 0.04, 0.12], [0.16, 0.16, 0.48]], [[0.18, 0.12, 0.3], [0.12, 0.08, 0.2]]])
        self.assertTwoPot(self.pot * otherpot, answerpot)
Esempio n. 5
0
    def testMult(self):
        otherpot = potential()
        otherpot.variables = np.array([3])
        otherpot.card = np.array([3])
        otherpot.table = np.array([0.1, 0.4, 0.5])
        answerpot = potential()
        answerpot.variables = np.array([1, 2, 3])
        answerpot.card = np.array([2, 2, 3])
        answerpot.table = np.array([[[0.02, 0.08, 0.1], [0.08, 0.32, 0.4]],
                                    [[0.06, 0.24, 0.3], [0.04, 0.16, 0.2]]])
        self.assertTwoPot(self.pot * otherpot, answerpot)

        otherpot = potential()
        otherpot.variables = np.array([3, 1])
        otherpot.card = np.array([3, 2])
        otherpot.table = np.array([[0.2, 0.3], [0.2, 0.2], [0.6, 0.5]])
        answerpot = potential()
        answerpot.variables = np.array([1, 2, 3])
        answerpot.card = np.array([2, 2, 3])
        answerpot.table = np.array([[[0.04, 0.04, 0.12], [0.16, 0.16, 0.48]],
                                    [[0.18, 0.12, 0.3], [0.12, 0.08, 0.2]]])
        self.assertTwoPot(self.pot * otherpot, answerpot)
Esempio n. 6
0
#!/usr/bin/env python

# this is a test case for sample codes

from brml.potential import potential
from brml.variable import variable


p = potential(1,1)
print "var POTENTIAL.p created"
print "p.variable = ", p.variables
print "p.table = ", p.table

v = variable('butler',['hehe', 'heihei'])
# v = variable('butler',['murderer','not murderer'])
print "var VARIABLE.v created"
print "v.name = ", v.name
print "v.domain = ", v.domain
Esempio n. 7
0
#!/usr/bin/env python

# this is a test case for sample codes

from brml.potential import potential
from brml.variable import variable

p = potential(1, 1)
print "var POTENTIAL.p created"
print "p.variable = ", p.variables
print "p.table = ", p.table

v = variable('butler', ['hehe', 'heihei'])
# v = variable('butler',['murderer','not murderer'])
print "var VARIABLE.v created"
print "v.name = ", v.name
print "v.domain = ", v.domain
Esempio n. 8
0
 def setUp(self):
     self.pot = potential()
     self.pot.variables = np.array([3, 2, 1])
     self.card = np.array([2, 3, 4])
     self.pot.table = np.arange(0, 24).reshape(2, 3, 4)
Esempio n. 9
0
 def setUp(self):
     self.pot = potential()
     self.pot.variables = np.array([2, 1])
     self.pot.card = np.array([2, 2])
     self.pot.table = np.array([[0.2, 0.6], [0.8, 0.4]])
Esempio n. 10
0
 def setUp(self):
     self.pot = potential()
     self.pot.variables = np.array([3, 2, 1])
     self.card = np.array([2, 3, 4])
     self.pot.table = np.arange(0, 24).reshape(2, 3, 4)
Esempio n. 11
0
variable = [variable(None, None) for i in range(4)]

variable[burglar].name = 'burglar'
variable[burglar].domain = ['yes', 'no']

variable[earthquake].name = 'earthquake'
variable[earthquake].domain = ['yes', 'no']

variable[alarm].name = 'alarm'
variable[alarm].domain = ['yes', 'no']

variable[radio].name = 'radio'
variable[radio].domain = ['yes', 'no']

pot = [potential() for i in range(4)]

pot[burglar].variables = np.array([burglar])
pot[burglar].card = np.array([2])
table = np.zeros(2)
table[yes] = 0.01
table[no] = 0.99
pot[burglar].table = table

pot[earthquake].variables = np.array([earthquake])
pot[earthquake].card = np.array([2])
table = np.zeros(2)
table[yes] = 0.000001
table[no] = 1 - table[yes]
pot[earthquake].table = table
Esempio n. 12
0
variable = [variable(None, None) for i in range(4)]

variable[burglar].name = 'burglar'
variable[burglar].domain = ['yes', 'no']

variable[earthquake].name = 'earthquake'
variable[earthquake].domain = ['yes', 'no']

variable[alarm].name = 'alarm'
variable[alarm].domain = ['yes', 'no']

variable[radio].name = 'radio'
variable[radio].domain = ['yes', 'no']

pot = [potential() for i in range(4)]

pot[burglar].variables = np.array([burglar])
pot[burglar].card = np.array([2])
table = np.zeros(2)
table[yes] = 0.01
table[no] = 0.99
pot[burglar].table = table

pot[earthquake].variables = np.array([earthquake])
pot[earthquake].card = np.array([2])
table = np.zeros(2)
table[yes] = 0.000001
table[no] = 1 - table[yes]
pot[earthquake].table = table
Esempio n. 13
0
 def setUp(self):
     self.pot = potential()
     self.pot.variables = np.array([2, 1])
     self.pot.card = np.array([2, 2])
     self.pot.table = np.array([[0.2, 0.6], [0.8, 0.4]])
Esempio n. 14
0
 def testDiffVaTa(self):
     pot = [potential(np.array([1, 2]), np.zeros((3, 2, 2)))]
     self.assertRaises(ValueError, potvariables, pot)
Esempio n. 15
0
 def testNoneVariables(self):
     pot = [potential(np.array([]), np.zeros(3))]
     self.assertRaises(ValueError, potvariables, pot)