common definitions of Unary, UnaryAssignment and Binary
parent
f9a9801912
commit
e6b6528521
|
|
@ -94,7 +94,7 @@ namespace gtsam {
|
|||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
DecisionTreeFactor DecisionTreeFactor::apply(ADT::Unary op) const {
|
||||
DecisionTreeFactor DecisionTreeFactor::apply(Unary op) const {
|
||||
// apply operand
|
||||
ADT result = ADT::apply(op);
|
||||
// Make a new factor
|
||||
|
|
@ -102,7 +102,7 @@ namespace gtsam {
|
|||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
DecisionTreeFactor DecisionTreeFactor::apply(ADT::UnaryAssignment op) const {
|
||||
DecisionTreeFactor DecisionTreeFactor::apply(UnaryAssignment op) const {
|
||||
// apply operand
|
||||
ADT result = ADT::apply(op);
|
||||
// Make a new factor
|
||||
|
|
@ -111,7 +111,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************ */
|
||||
DecisionTreeFactor DecisionTreeFactor::apply(const DecisionTreeFactor& f,
|
||||
ADT::Binary op) const {
|
||||
Binary op) const {
|
||||
map<Key, size_t> cs; // new cardinalities
|
||||
// make unique key-cardinality map
|
||||
for (Key j : keys()) cs[j] = cardinality(j);
|
||||
|
|
@ -129,8 +129,8 @@ namespace gtsam {
|
|||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(
|
||||
size_t nrFrontals, ADT::Binary op) const {
|
||||
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(size_t nrFrontals,
|
||||
Binary op) const {
|
||||
if (nrFrontals > size()) {
|
||||
throw invalid_argument(
|
||||
"DecisionTreeFactor::combine: invalid number of frontal "
|
||||
|
|
@ -157,7 +157,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************ */
|
||||
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(
|
||||
const Ordering& frontalKeys, ADT::Binary op) const {
|
||||
const Ordering& frontalKeys, Binary op) const {
|
||||
if (frontalKeys.size() > size()) {
|
||||
throw invalid_argument(
|
||||
"DecisionTreeFactor::combine: invalid number of frontal "
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ namespace gtsam {
|
|||
typedef std::shared_ptr<DecisionTreeFactor> shared_ptr;
|
||||
typedef AlgebraicDecisionTree<Key> ADT;
|
||||
|
||||
using Base::Binary;
|
||||
using Base::Unary;
|
||||
using Base::UnaryAssignment;
|
||||
|
||||
/// @name Standard Constructors
|
||||
/// @{
|
||||
|
||||
|
|
@ -140,7 +144,7 @@ namespace gtsam {
|
|||
double error(const DiscreteValues& values) const override;
|
||||
|
||||
/// multiply two factors
|
||||
DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override {
|
||||
DecisionTreeFactor operator*(const DecisionTreeFactor& f) const {
|
||||
return apply(f, Ring::mul);
|
||||
}
|
||||
|
||||
|
|
@ -196,21 +200,21 @@ namespace gtsam {
|
|||
* Apply unary operator (*this) "op" f
|
||||
* @param op a unary operator that operates on AlgebraicDecisionTree
|
||||
*/
|
||||
DecisionTreeFactor apply(ADT::Unary op) const;
|
||||
DecisionTreeFactor apply(Unary op) const;
|
||||
|
||||
/**
|
||||
* Apply unary operator (*this) "op" f
|
||||
* @param op a unary operator that operates on AlgebraicDecisionTree. Takes
|
||||
* both the assignment and the value.
|
||||
*/
|
||||
DecisionTreeFactor apply(ADT::UnaryAssignment op) const;
|
||||
DecisionTreeFactor apply(UnaryAssignment op) const;
|
||||
|
||||
/**
|
||||
* Apply binary operator (*this) "op" f
|
||||
* @param f the second argument for op
|
||||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
||||
*/
|
||||
DecisionTreeFactor apply(const DecisionTreeFactor& f, ADT::Binary op) const;
|
||||
DecisionTreeFactor apply(const DecisionTreeFactor& f, Binary op) const;
|
||||
|
||||
/**
|
||||
* Combine frontal variables using binary operator "op"
|
||||
|
|
@ -218,7 +222,7 @@ namespace gtsam {
|
|||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
||||
* @return shared pointer to newly created DecisionTreeFactor
|
||||
*/
|
||||
shared_ptr combine(size_t nrFrontals, ADT::Binary op) const;
|
||||
shared_ptr combine(size_t nrFrontals, Binary op) const;
|
||||
|
||||
/**
|
||||
* Combine frontal variables in an Ordering using binary operator "op"
|
||||
|
|
@ -226,7 +230,7 @@ namespace gtsam {
|
|||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
||||
* @return shared pointer to newly created DecisionTreeFactor
|
||||
*/
|
||||
shared_ptr combine(const Ordering& keys, ADT::Binary op) const;
|
||||
shared_ptr combine(const Ordering& keys, Binary op) const;
|
||||
|
||||
/// Enumerate all values into a map from values to double.
|
||||
std::vector<std::pair<DiscreteValues, double>> enumerate() const;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ class GTSAM_EXPORT DiscreteFactor : public Factor {
|
|||
|
||||
using Values = DiscreteValues; ///< backwards compatibility
|
||||
|
||||
using Unary = std::function<double(const double&)>;
|
||||
using UnaryAssignment =
|
||||
std::function<double(const Assignment<Key>&, const double&)>;
|
||||
using Binary = std::function<double(const double, const double)>;
|
||||
|
||||
protected:
|
||||
/// Map of Keys and their cardinalities.
|
||||
std::map<Key, size_t> cardinalities_;
|
||||
|
|
|
|||
Loading…
Reference in New Issue