def test_factor(self): fn = lambda c: ord(c) - ord('a') dist = Distribution({'a': 1, 'b': 2}) dist.factor('a', 0.5) self.almostEqual(list(dist.as_numpy_array(fn)), [0.2, 0.8]) dist = Distribution({'a': 1, 'b': 2, 'c': 3}) dist.factor('b', 3) self.almostEqual(list(dist.as_numpy_array(fn)), [0.1, 0.6, 0.3])
def test_as_numpy_array(self): dist = Distribution({'a': 1, 'b': 2, 'd': 2}) fn = lambda c: ord(c) - ord('a') self.almostEqual(list(dist.as_numpy_array(fn)), [0.2, 0.4, 0, 0.4]) self.almostEqual(list(dist.as_numpy_array(fn, 5)), [0.2, 0.4, 0, 0.4, 0])