Merge pull request #1922 from borglab/ring
commit
11142b08fc
|
@ -20,12 +20,12 @@
|
|||
|
||||
#include <gtsam/base/Testable.h>
|
||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||
#include <gtsam/discrete/Ring.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
namespace gtsam {
|
||||
|
@ -55,26 +55,6 @@ namespace gtsam {
|
|||
public:
|
||||
using Base = DecisionTree<L, double>;
|
||||
|
||||
/** The Real ring with addition and multiplication */
|
||||
struct Ring {
|
||||
static inline double zero() { return 0.0; }
|
||||
static inline double one() { return 1.0; }
|
||||
static inline double add(const double& a, const double& b) {
|
||||
return a + b;
|
||||
}
|
||||
static inline double max(const double& a, const double& b) {
|
||||
return std::max(a, b);
|
||||
}
|
||||
static inline double mul(const double& a, const double& b) {
|
||||
return a * b;
|
||||
}
|
||||
static inline double div(const double& a, const double& b) {
|
||||
return a / b;
|
||||
}
|
||||
static inline double id(const double& x) { return x; }
|
||||
static inline double negate(const double& x) { return -x; }
|
||||
};
|
||||
|
||||
AlgebraicDecisionTree(double leaf = 1.0) : Base(leaf) {}
|
||||
|
||||
// Explicitly non-explicit constructor
|
||||
|
|
|
@ -21,11 +21,12 @@
|
|||
#include <gtsam/discrete/AlgebraicDecisionTree.h>
|
||||
#include <gtsam/discrete/DiscreteFactor.h>
|
||||
#include <gtsam/discrete/DiscreteKey.h>
|
||||
#include <gtsam/discrete/Ring.h>
|
||||
#include <gtsam/inference/Ordering.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
@ -145,7 +146,7 @@ namespace gtsam {
|
|||
|
||||
/// multiply two factors
|
||||
DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override {
|
||||
return apply(f, ADT::Ring::mul);
|
||||
return apply(f, Ring::mul);
|
||||
}
|
||||
|
||||
static double safe_div(const double& a, const double& b);
|
||||
|
@ -160,22 +161,22 @@ namespace gtsam {
|
|||
|
||||
/// Create new factor by summing all values with the same separator values
|
||||
shared_ptr sum(size_t nrFrontals) const {
|
||||
return combine(nrFrontals, ADT::Ring::add);
|
||||
return combine(nrFrontals, Ring::add);
|
||||
}
|
||||
|
||||
/// Create new factor by summing all values with the same separator values
|
||||
shared_ptr sum(const Ordering& keys) const {
|
||||
return combine(keys, ADT::Ring::add);
|
||||
return combine(keys, Ring::add);
|
||||
}
|
||||
|
||||
/// Create new factor by maximizing over all values with the same separator.
|
||||
shared_ptr max(size_t nrFrontals) const {
|
||||
return combine(nrFrontals, ADT::Ring::max);
|
||||
return combine(nrFrontals, Ring::max);
|
||||
}
|
||||
|
||||
/// Create new factor by maximizing over all values with the same separator.
|
||||
shared_ptr max(const Ordering& keys) const {
|
||||
return combine(keys, ADT::Ring::max);
|
||||
return combine(keys, Ring::max);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <gtsam/base/Testable.h>
|
||||
#include <gtsam/base/debug.h>
|
||||
#include <gtsam/discrete/DiscreteConditional.h>
|
||||
#include <gtsam/discrete/Ring.h>
|
||||
#include <gtsam/discrete/Signature.h>
|
||||
#include <gtsam/hybrid/HybridValues.h>
|
||||
|
||||
|
@ -104,7 +105,7 @@ DiscreteConditional DiscreteConditional::operator*(
|
|||
// Finally, add parents to keys, in order
|
||||
for (auto&& dk : parents) discreteKeys.push_back(dk);
|
||||
|
||||
ADT product = ADT::apply(other, ADT::Ring::mul);
|
||||
ADT product = ADT::apply(other, Ring::mul);
|
||||
return DiscreteConditional(newFrontals.size(), discreteKeys, product);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||
* Atlanta, Georgia 30332-0415
|
||||
* All Rights Reserved
|
||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||
|
||||
* See LICENSE for the license information
|
||||
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @file Ring.h
|
||||
* @brief Real Ring definition
|
||||
* @author Varun Agrawal
|
||||
* @date Dec 8, 2024
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
/** The Real ring with addition and multiplication */
|
||||
struct Ring {
|
||||
static inline double zero() { return 0.0; }
|
||||
static inline double one() { return 1.0; }
|
||||
static inline double add(const double& a, const double& b) { return a + b; }
|
||||
static inline double max(const double& a, const double& b) {
|
||||
return std::max(a, b);
|
||||
}
|
||||
static inline double mul(const double& a, const double& b) { return a * b; }
|
||||
static inline double div(const double& a, const double& b) {
|
||||
return (a == 0 || b == 0) ? 0 : (a / b);
|
||||
}
|
||||
static inline double id(const double& x) { return x; }
|
||||
static inline double negate(const double& x) { return -x; }
|
||||
};
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <gtsam/discrete/DiscreteFactor.h>
|
||||
#include <gtsam/discrete/DiscreteKey.h>
|
||||
#include <gtsam/discrete/Ring.h>
|
||||
#include <gtsam/inference/Ordering.h>
|
||||
|
||||
#include <Eigen/Sparse>
|
||||
|
@ -99,21 +100,6 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor {
|
|||
using Binary = std::function<double(const double, const double)>;
|
||||
|
||||
public:
|
||||
/** The Real ring with addition and multiplication */
|
||||
struct Ring {
|
||||
static inline double zero() { return 0.0; }
|
||||
static inline double one() { return 1.0; }
|
||||
static inline double add(const double& a, const double& b) { return a + b; }
|
||||
static inline double max(const double& a, const double& b) {
|
||||
return std::max(a, b);
|
||||
}
|
||||
static inline double mul(const double& a, const double& b) { return a * b; }
|
||||
static inline double div(const double& a, const double& b) {
|
||||
return (a == 0 || b == 0) ? 0 : (a / b);
|
||||
}
|
||||
static inline double id(const double& x) { return x; }
|
||||
};
|
||||
|
||||
/// @name Standard Constructors
|
||||
/// @{
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <gtsam/base/Testable.h>
|
||||
#include <gtsam/base/serializationTestHelpers.h>
|
||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||
#include <gtsam/discrete/Ring.h>
|
||||
#include <gtsam/discrete/Signature.h>
|
||||
#include <gtsam/inference/Symbol.h>
|
||||
|
||||
|
@ -124,14 +125,6 @@ struct traits<DT> : public Testable<DT> {};
|
|||
|
||||
GTSAM_CONCEPT_TESTABLE_INST(DT)
|
||||
|
||||
struct Ring {
|
||||
static inline int zero() { return 0; }
|
||||
static inline int one() { return 1; }
|
||||
static inline int id(const int& a) { return a; }
|
||||
static inline int add(const int& a, const int& b) { return a + b; }
|
||||
static inline int mul(const int& a, const int& b) { return a * b; }
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
// Check that creating decision trees respects key order.
|
||||
TEST(DecisionTree, ConstructorOrder) {
|
||||
|
|
Loading…
Reference in New Issue