linting
parent
ca329daa13
commit
8acf67d4c8
|
|
@ -20,6 +20,10 @@
|
||||||
|
|
||||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -27,10 +31,11 @@ namespace gtsam {
|
||||||
* Just has some nice constructors and some syntactic sugar
|
* Just has some nice constructors and some syntactic sugar
|
||||||
* TODO: consider eliminating this class altogether?
|
* TODO: consider eliminating this class altogether?
|
||||||
*/
|
*/
|
||||||
template<typename L>
|
template <typename L>
|
||||||
class GTSAM_EXPORT AlgebraicDecisionTree: public DecisionTree<L, double> {
|
class GTSAM_EXPORT AlgebraicDecisionTree : public DecisionTree<L, double> {
|
||||||
/**
|
/**
|
||||||
* @brief Default method used by `labelFormatter` or `valueFormatter` when printing.
|
* @brief Default method used by `labelFormatter` or `valueFormatter` when
|
||||||
|
* printing.
|
||||||
*
|
*
|
||||||
* @param x The value passed to format.
|
* @param x The value passed to format.
|
||||||
* @return std::string
|
* @return std::string
|
||||||
|
|
@ -42,17 +47,12 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Base = DecisionTree<L, double>;
|
using Base = DecisionTree<L, double>;
|
||||||
|
|
||||||
/** The Real ring with addition and multiplication */
|
/** The Real ring with addition and multiplication */
|
||||||
struct Ring {
|
struct Ring {
|
||||||
static inline double zero() {
|
static inline double zero() { return 0.0; }
|
||||||
return 0.0;
|
static inline double one() { return 1.0; }
|
||||||
}
|
|
||||||
static inline double one() {
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
static inline double add(const double& a, const double& b) {
|
static inline double add(const double& a, const double& b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|
@ -65,39 +65,34 @@ namespace gtsam {
|
||||||
static inline double div(const double& a, const double& b) {
|
static inline double div(const double& a, const double& b) {
|
||||||
return a / b;
|
return a / b;
|
||||||
}
|
}
|
||||||
static inline double id(const double& x) {
|
static inline double id(const double& x) { return x; }
|
||||||
return x;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AlgebraicDecisionTree() :
|
AlgebraicDecisionTree() : Base(1.0) {}
|
||||||
Base(1.0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
AlgebraicDecisionTree(const Base& add) :
|
explicit AlgebraicDecisionTree(const Base& add) : Base(add) {}
|
||||||
Base(add) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a new leaf function splitting on a variable */
|
/** Create a new leaf function splitting on a variable */
|
||||||
AlgebraicDecisionTree(const L& label, double y1, double y2) :
|
AlgebraicDecisionTree(const L& label, double y1, double y2)
|
||||||
Base(label, y1, y2) {
|
: Base(label, y1, y2) {}
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a new leaf function splitting on a variable */
|
/** Create a new leaf function splitting on a variable */
|
||||||
AlgebraicDecisionTree(const typename Base::LabelC& labelC, double y1, double y2) :
|
AlgebraicDecisionTree(const typename Base::LabelC& labelC, double y1,
|
||||||
Base(labelC, y1, y2) {
|
double y2)
|
||||||
}
|
: Base(labelC, y1, y2) {}
|
||||||
|
|
||||||
/** Create from keys and vector table */
|
/** Create from keys and vector table */
|
||||||
AlgebraicDecisionTree //
|
AlgebraicDecisionTree //
|
||||||
(const std::vector<typename Base::LabelC>& labelCs, const std::vector<double>& ys) {
|
(const std::vector<typename Base::LabelC>& labelCs,
|
||||||
this->root_ = Base::create(labelCs.begin(), labelCs.end(), ys.begin(),
|
const std::vector<double>& ys) {
|
||||||
ys.end());
|
this->root_ =
|
||||||
|
Base::create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create from keys and string table */
|
/** Create from keys and string table */
|
||||||
AlgebraicDecisionTree //
|
AlgebraicDecisionTree //
|
||||||
(const std::vector<typename Base::LabelC>& labelCs, const std::string& table) {
|
(const std::vector<typename Base::LabelC>& labelCs,
|
||||||
|
const std::string& table) {
|
||||||
// Convert string to doubles
|
// Convert string to doubles
|
||||||
std::vector<double> ys;
|
std::vector<double> ys;
|
||||||
std::istringstream iss(table);
|
std::istringstream iss(table);
|
||||||
|
|
@ -105,14 +100,14 @@ namespace gtsam {
|
||||||
std::istream_iterator<double>(), std::back_inserter(ys));
|
std::istream_iterator<double>(), std::back_inserter(ys));
|
||||||
|
|
||||||
// now call recursive Create
|
// now call recursive Create
|
||||||
this->root_ = Base::create(labelCs.begin(), labelCs.end(), ys.begin(),
|
this->root_ =
|
||||||
ys.end());
|
Base::create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new function splitting on a variable */
|
/** Create a new function splitting on a variable */
|
||||||
template<typename Iterator>
|
template <typename Iterator>
|
||||||
AlgebraicDecisionTree(Iterator begin, Iterator end, const L& label) :
|
AlgebraicDecisionTree(Iterator begin, Iterator end, const L& label)
|
||||||
Base(nullptr) {
|
: Base(nullptr) {
|
||||||
this->root_ = compose(begin, end, label);
|
this->root_ = compose(begin, end, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +117,7 @@ namespace gtsam {
|
||||||
* @param other: The AlgebraicDecisionTree with label type M to convert.
|
* @param other: The AlgebraicDecisionTree with label type M to convert.
|
||||||
* @param map: Map from label type M to label type L.
|
* @param map: Map from label type M to label type L.
|
||||||
*/
|
*/
|
||||||
template<typename M>
|
template <typename M>
|
||||||
AlgebraicDecisionTree(const AlgebraicDecisionTree<M>& other,
|
AlgebraicDecisionTree(const AlgebraicDecisionTree<M>& other,
|
||||||
const std::map<M, L>& map) {
|
const std::map<M, L>& map) {
|
||||||
// Functor for label conversion so we can use `convertFrom`.
|
// Functor for label conversion so we can use `convertFrom`.
|
||||||
|
|
@ -177,8 +172,8 @@ namespace gtsam {
|
||||||
return Base::equals(other, compare);
|
return Base::equals(other, compare);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// AlgebraicDecisionTree
|
|
||||||
|
|
||||||
template<typename T> struct traits<AlgebraicDecisionTree<T>> : public Testable<AlgebraicDecisionTree<T>> {};
|
template <typename T>
|
||||||
}
|
struct traits<AlgebraicDecisionTree<T>>
|
||||||
// namespace gtsam
|
: public Testable<AlgebraicDecisionTree<T>> {};
|
||||||
|
} // namespace gtsam
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue