def test_logsubexp(self): a1 = to_log(np.array([1, 2, 3])) a2 = to_log(np.array([1, 1, 2])) result = from_log(logsubexp(a1, a2)) self.assertAlmostEqual(result[0], 0) self.assertAlmostEqual(result[1], 1) self.assertAlmostEqual(result[2], 1) result = from_log(logsubexp(a1, to_log(1))) self.assertAlmostEqual(result[0], 0) self.assertAlmostEqual(result[1], 1) self.assertAlmostEqual(result[2], 2)
def constant_factor(variables, variables_dict, length, logarithmetic=True): if logarithmetic: factor = Factor(variables, variables_dict, to_log(np.ones(length)), logarithmetic) else: factor = Factor(variables, variables_dict, np.ones(length), logarithmetic) return factor