2 GTSAM Copyright 2010-2021, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 6 See LICENSE for the license information 8 Unit tests for DecisionTreeFactors. 16 from gtsam
import (DecisionTreeFactor, DiscreteDistribution, DiscreteValues,
22 """Tests for DecisionTreeFactors.""" 27 self.
factor = DecisionTreeFactor([self.
A, self.
B],
"1 2 3 4 5 6")
30 actual = self.
factor.enumerate()
31 _, values = zip(*actual)
32 self.assertEqual(
list(values), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
35 """Test whether multiplication works with overloading.""" 41 prior = DiscreteDistribution(v1, [1, 3])
42 f1 = DecisionTreeFactor([v0, v1],
"1 2 3 4")
43 expected = DecisionTreeFactor([v0, v1],
"0.25 1.5 0.75 3")
48 f2 = DecisionTreeFactor([v1, v2],
"5 6 7 8")
50 expected2 = DecisionTreeFactor([v0, v1, v2],
"5 6 14 16 15 18 28 32")
54 """Test whether we can call methods in python.""" 59 self.assertIsInstance(self.
factor(values), float)
62 self.assertIsInstance(self.
factor.cardinality(self.
A[0]), int)
65 self.assertIsInstance(self.
factor / self.
factor, DecisionTreeFactor)
68 self.assertIsInstance(self.
factor.sum(1), DecisionTreeFactor)
72 ordering.push_back(self.
A[0])
73 self.assertIsInstance(self.
factor.sum(ordering), DecisionTreeFactor)
76 self.assertIsInstance(self.
factor.
max(1), DecisionTreeFactor)
79 """Test whether the _repr_markdown_ method.""" 92 return "A" if x == 12
else "B" 94 actual = self.
factor._repr_markdown_(formatter)
95 self.assertEqual(actual, expected)
98 if __name__ ==
"__main__":
def gtsamAssertEquals(self, actual, expected, tol=1e-9)
def test_multiplication(self)
const KeyFormatter & formatter