class TimeDiscreteFactor: def setup(self): self.phi_large = DiscreteFactor(range(10), [2] * 10, [1] * (2**10)) def time_factor_reduce(self): self.phi_large.reduce([(3, 0), (6, 1)], inplace=False) def time_factor_marginalize(self): self.phi_large.marginalize([4, 5, 8], inplace=False) def time_factor_multiply_large(self): phi = self.phi_large * self.phi_large def time_factor_compare(self): self.phi_large == self.phi_large
def test_factor_reduce_statename(self): phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi.reduce([('speed', 'medium'), ('time', 'day')]) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi = phi.reduce([('speed', 'medium'), ('time', 'day')], inplace=False) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi.reduce([('speed', 1), ('time', 0)]) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi = phi.reduce([('speed', 1), ('time', 0)], inplace=False) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1]))
def test_factor_reduce_statename(self): phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi.reduce([('speed', 'medium'), ('time', 'day')]) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi = phi.reduce([('speed', 'medium'), ('time', 'day')], inplace=False) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi.reduce([('speed', 1), ('time', 0)]) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(['speed', 'switch', 'time'], [3, 2, 2], np.ones(12), state_names=self.sn1) phi = phi.reduce([('speed', 1), ('time', 0)], inplace=False) self.assertEqual(phi.variables, ['switch']) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1]))
def test_factor_reduce_statename(self): phi = DiscreteFactor(["speed", "switch", "time"], [3, 2, 2], np.ones(12), state_names=self.sn1) phi.reduce([("speed", "medium"), ("time", "day")]) self.assertEqual(phi.variables, ["switch"]) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(["speed", "switch", "time"], [3, 2, 2], np.ones(12), state_names=self.sn1) phi = phi.reduce([("speed", "medium"), ("time", "day")], inplace=False) self.assertEqual(phi.variables, ["switch"]) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(["speed", "switch", "time"], [3, 2, 2], np.ones(12)) phi.reduce([("speed", 1), ("time", 0)]) self.assertEqual(phi.variables, ["switch"]) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1])) phi = DiscreteFactor(["speed", "switch", "time"], [3, 2, 2], np.ones(12)) phi = phi.reduce([("speed", 1), ("time", 0)], inplace=False) self.assertEqual(phi.variables, ["switch"]) self.assertEqual(phi.cardinality, [2]) np_test.assert_array_equal(phi.values, np.array([1, 1]))