testDecisionTreeFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 /*
13  * testDecisionTreeFactor.cpp
14  *
15  * @date Feb 5, 2012
16  * @author Frank Dellaert
17  * @author Duy-Nguyen Ta
18  */
19 
22 #include <gtsam/base/Testable.h>
24 #include <boost/assign/std/map.hpp>
25 using namespace boost::assign;
26 
27 using namespace std;
28 using namespace gtsam;
29 
30 /* ************************************************************************* */
31 TEST( DecisionTreeFactor, constructors)
32 {
33  DiscreteKey X(0,2), Y(1,3), Z(2,2);
34 
35  DecisionTreeFactor f1(X, "2 8");
36  DecisionTreeFactor f2(X & Y, "2 5 3 6 4 7");
37  DecisionTreeFactor f3(X & Y & Z, "2 5 3 6 4 7 25 55 35 65 45 75");
38  EXPECT_LONGS_EQUAL(1,f1.size());
39  EXPECT_LONGS_EQUAL(2,f2.size());
40  EXPECT_LONGS_EQUAL(3,f3.size());
41 
42  // f1.print("f1:");
43  // f2.print("f2:");
44  // f3.print("f3:");
45 
47  values[0] = 1; // x
48  values[1] = 2; // y
49  values[2] = 1; // z
50  EXPECT_DOUBLES_EQUAL(8, f1(values), 1e-9);
51  EXPECT_DOUBLES_EQUAL(7, f2(values), 1e-9);
52  EXPECT_DOUBLES_EQUAL(75, f3(values), 1e-9);
53 }
54 
55 /* ************************************************************************* */
57 {
58  // Declare a bunch of keys
59  DiscreteKey v0(0,2), v1(1,2), v2(2,2);
60 
61  // Create a factor
62  DecisionTreeFactor f1(v0 & v1, "1 2 3 4");
63  DecisionTreeFactor f2(v1 & v2, "5 6 7 8");
64 // f1.print("f1:");
65 // f2.print("f2:");
66 
67  DecisionTreeFactor expected(v0 & v1 & v2, "5 6 14 16 15 18 28 32");
68 
69  DecisionTreeFactor actual = f1 * f2;
70 // actual.print("actual: ");
71  CHECK(assert_equal(expected, actual));
72 }
73 
74 /* ************************************************************************* */
76 {
77  // Declare a bunch of keys
78  DiscreteKey v0(0,3), v1(1,2);
79 
80  // Create a factor
81  DecisionTreeFactor f1(v0 & v1, "1 2 3 4 5 6");
82 
83  DecisionTreeFactor expected(v1, "9 12");
84  DecisionTreeFactor::shared_ptr actual = f1.sum(1);
85  CHECK(assert_equal(expected, *actual, 1e-5));
86 // f1.print("f1:");
87 // actual->print("actual: ");
88 // actual->printCache("actual cache: ");
89 
90  DecisionTreeFactor expected2(v1, "5 6");
91  DecisionTreeFactor::shared_ptr actual2 = f1.max(1);
92  CHECK(assert_equal(expected2, *actual2));
93 
94  DecisionTreeFactor f2(v1 & v0, "1 2 3 4 5 6");
95  DecisionTreeFactor::shared_ptr actual22 = f2.sum(1);
96 // f2.print("f2: ");
97 // actual22->print("actual22: ");
98 
99 }
100 
101 /* ************************************************************************* */
102 int main() {
103  TestResult tr;
104  return TestRegistry::runAllTests(tr);
105 }
106 /* ************************************************************************* */
107 
#define CHECK(condition)
Definition: Test.h:109
TEST_UNSAFE(DecisionTreeFactor, multiplication)
Vector v2
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Vector v1
signatures for conditional densities
Matrix expected
Definition: testMatrix.cpp:974
leaf::MyValues values
Definition: Half.h:150
double f2(const Vector2 &x)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:162
#define Z
Definition: icosphere.cpp:21
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
Array< double, 1, 3 > e(1./3., 0.5, 2.)
shared_ptr sum(size_t nrFrontals) const
Create new factor by summing all values with the same separator values.
TEST(DecisionTreeFactor, constructors)
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
std::vector< float > Values
size_t size() const
Definition: Factor.h:135
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
static const double v0
double f3(double x1, double x2)
boost::shared_ptr< DecisionTreeFactor > shared_ptr
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator values.
#define X
Definition: icosphere.cpp:20


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:25