Skip to content

Commit

Permalink
experiment with removing the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Oct 9, 2024
1 parent f4bf280 commit 55dc3f5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
26 changes: 13 additions & 13 deletions gtsam/discrete/DecisionTree-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,19 @@ namespace gtsam {
root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end());
}

/****************************************************************************/
template<typename L, typename Y>
DecisionTree<L, Y>::DecisionTree(const std::vector<LabelC>& labelCs,
const std::string& table) {
// Convert std::string to values of type Y
std::vector<Y> ys;
std::istringstream iss(table);
copy(std::istream_iterator<Y>(iss), std::istream_iterator<Y>(),
back_inserter(ys));

// now call recursive Create
root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end());
}
// /****************************************************************************/
// template<typename L, typename Y>
// DecisionTree<L, Y>::DecisionTree(const std::vector<LabelC>& labelCs,
// const std::string& table) {
// // Convert std::string to values of type Y
// std::vector<Y> ys;
// std::istringstream iss(table);
// copy(std::istream_iterator<Y>(iss), std::istream_iterator<Y>(),
// back_inserter(ys));

// // now call recursive Create
// root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end());
// }

/****************************************************************************/
template<typename L, typename Y>
Expand Down
4 changes: 2 additions & 2 deletions gtsam/discrete/DecisionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ namespace gtsam {
/** Create from keys and a corresponding vector of values */
DecisionTree(const std::vector<LabelC>& labelCs, const std::vector<Y>& ys);

/** Create from keys and string table */
DecisionTree(const std::vector<LabelC>& labelCs, const std::string& table);
// /** Create from keys and string table */
// DecisionTree(const std::vector<LabelC>& labelCs, const std::string& table);

/** Create DecisionTree from others */
template<typename Iterator>
Expand Down
14 changes: 7 additions & 7 deletions gtsam/discrete/tests/testDecisionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ TEST(DecisionTree, Compose) {

// Create from string
vector<DT::LabelC> keys{DT::LabelC(A, 2), DT::LabelC(B, 2)};
DT f2(keys, "0 2 1 3");
DT f2(keys, {0, 2, 1, 3});
EXPECT(assert_equal(f2, f1, 1e-9));

// Put this AB tree together with another one
DT f3(keys, "4 6 5 7");
DT f3(keys, {4, 6, 5, 7});
DT f4(C, f1, f3);
DOT(f4);

// a bigger tree
keys.push_back(DT::LabelC(C, 2));
DT f5(keys, "0 4 2 6 1 5 3 7");
DT f5(keys, {0, 4, 2, 6, 1, 5, 3, 7});
EXPECT(assert_equal(f5, f4, 1e-9));
DOT(f5);
}
Expand Down Expand Up @@ -508,7 +508,7 @@ TEST(DecisionTree, threshold) {
// Create three level tree
const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
DT::LabelC("A", 2)};
DT tree(keys, "0 1 2 3 4 5 6 7");
DT tree(keys, {0, 1, 2, 3, 4, 5, 6, 7});

// Check number of leaves equal to zero
auto count = [](const int& value, int count) {
Expand Down Expand Up @@ -536,10 +536,10 @@ TEST(DecisionTree, ApplyWithAssignment) {
// Create three level tree
const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
DT::LabelC("A", 2)};
DT tree(keys, "1 2 3 4 5 6 7 8");
DT tree(keys, {1, 2, 3, 4, 5, 6, 7, 8});

DecisionTree<string, double> probTree(
keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
keys, {0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08});
double threshold = 0.045;

// We test pruning one tree by indexing into another.
Expand All @@ -553,7 +553,7 @@ TEST(DecisionTree, ApplyWithAssignment) {
};
DT prunedTree = tree.apply(pruner);

DT expectedTree(keys, "0 0 0 0 5 6 7 8");
DT expectedTree(keys, {0, 0, 0, 0, 5, 6, 7, 8});
EXPECT(assert_equal(expectedTree, prunedTree));

size_t count = 0;
Expand Down
8 changes: 0 additions & 8 deletions gtsam/hybrid/HybridGaussianProductFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ class GTSAM_EXPORT HybridGaussianProductFactor
*/
HybridGaussianProductFactor(Base&& tree) : Base(std::move(tree)) {}

/// Deleted constructor since we don't have istream operator for
/// GaussianFactorGraphValuePair
HybridGaussianProductFactor(const std::vector<DiscreteKey>& labelCs,
const std::string& table) {
throw std::runtime_error(
"HybridGaussianProductFactor: No way to construct.");
}

///@}

/// @name Operators
Expand Down

0 comments on commit 55dc3f5

Please sign in to comment.