Merge branch 'develop' into feature/kf_docs
commit
1849c7b424
|
@ -129,7 +129,7 @@ protected:
|
||||||
result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); }
|
result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); }
|
||||||
|
|
||||||
#define CHECK_EQUAL(expected,actual)\
|
#define CHECK_EQUAL(expected,actual)\
|
||||||
{ if (!((expected) == (actual))) { result_.addFailure(Failure(name_, __FILE__, __LINE__, std::to_string(expected), std::to_string(actual))); } }
|
{ if (!((expected) == (actual))) { result_.addFailure(Failure(name_, __FILE__, __LINE__, std::to_string(expected), std::to_string(actual))); return; } }
|
||||||
|
|
||||||
#define LONGS_EQUAL(expected,actual)\
|
#define LONGS_EQUAL(expected,actual)\
|
||||||
{ long actualTemp = actual; \
|
{ long actualTemp = actual; \
|
||||||
|
|
10
INSTALL.md
10
INSTALL.md
|
@ -159,6 +159,16 @@ Set with the command line as follows:
|
||||||
ON: When enabled, libgtsam_unstable will be built and installed with the same options as libgtsam. In addition, if tests are enabled, the unit tests will be built as well. The Matlab toolbox will also be generated if the matlab toolbox is enabled, installing into a folder called `gtsam_unstable`.
|
ON: When enabled, libgtsam_unstable will be built and installed with the same options as libgtsam. In addition, if tests are enabled, the unit tests will be built as well. The Matlab toolbox will also be generated if the matlab toolbox is enabled, installing into a folder called `gtsam_unstable`.
|
||||||
OFF (Default) If disabled, no `gtsam_unstable` code will be included in build or install.
|
OFF (Default) If disabled, no `gtsam_unstable` code will be included in build or install.
|
||||||
|
|
||||||
|
## Convenience Options:
|
||||||
|
|
||||||
|
#### GTSAM_BUILD_EXAMPLES_ALWAYS
|
||||||
|
|
||||||
|
Whether or not to force building examples, can be true or false.
|
||||||
|
|
||||||
|
#### GTSAM_BUILD_TESTS
|
||||||
|
|
||||||
|
Whether or not to build tests, can be true or false.
|
||||||
|
|
||||||
## Check
|
## Check
|
||||||
|
|
||||||
`make check` will build and run all of the tests. Note that the tests will only be
|
`make check` will build and run all of the tests. Note that the tests will only be
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <gtsam/slam/dataset.h>
|
#include <gtsam/slam/dataset.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <gtsam/linear/NoiseModel.h>
|
#include <gtsam/linear/NoiseModel.h>
|
||||||
#include <gtsam/geometry/Point2.h>
|
#include <gtsam/geometry/Point2.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <Eigen/LU>
|
#include <Eigen/LU>
|
||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cassert>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <gtsam/base/MatrixSerialization.h>
|
#include <gtsam/base/MatrixSerialization.h>
|
||||||
#include <gtsam/base/FastVector.h>
|
#include <gtsam/base/FastVector.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <gtsam/base/numericalDerivative.h>
|
#include <gtsam/base/numericalDerivative.h>
|
||||||
#include <CppUnitLite/TestHarness.h>
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,14 @@
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
double Chebyshev2::Point(size_t N, int j, double a, double b) {
|
||||||
|
assert(j >= 0 && size_t(j) < N);
|
||||||
|
const double dtheta = M_PI / (N > 1 ? (N - 1) : 1);
|
||||||
|
// We add -PI so that we get values ordered from -1 to +1
|
||||||
|
// sin(-M_PI_2 + dtheta*j); also works
|
||||||
|
return a + (b - a) * (1. + cos(-M_PI + dtheta * j)) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
Weights Chebyshev2::CalculateWeights(size_t N, double x, double a, double b) {
|
Weights Chebyshev2::CalculateWeights(size_t N, double x, double a, double b) {
|
||||||
// Allocate space for weights
|
// Allocate space for weights
|
||||||
Weights weights(N);
|
Weights weights(N);
|
||||||
|
|
|
@ -61,13 +61,7 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> {
|
||||||
* @param b Upper bound of interval (default: 1)
|
* @param b Upper bound of interval (default: 1)
|
||||||
* @return double
|
* @return double
|
||||||
*/
|
*/
|
||||||
static double Point(size_t N, int j, double a = -1, double b = 1) {
|
static double Point(size_t N, int j, double a = -1, double b = 1);
|
||||||
assert(j >= 0 && size_t(j) < N);
|
|
||||||
const double dtheta = M_PI / (N > 1 ? (N - 1) : 1);
|
|
||||||
// We add -PI so that we get values ordered from -1 to +1
|
|
||||||
// sin(-M_PI_2 + dtheta*j); also works
|
|
||||||
return a + (b - a) * (1. + cos(-M_PI + dtheta * j)) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// All Chebyshev points
|
/// All Chebyshev points
|
||||||
static Vector Points(size_t N) {
|
static Vector Points(size_t N) {
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
|
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iomanip>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -55,26 +55,6 @@ namespace gtsam {
|
||||||
public:
|
public:
|
||||||
using Base = DecisionTree<L, double>;
|
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) {}
|
AlgebraicDecisionTree(double leaf = 1.0) : Base(leaf) {}
|
||||||
|
|
||||||
// Explicitly non-explicit constructor
|
// Explicitly non-explicit constructor
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor DecisionTreeFactor::apply(ADT::Unary op) const {
|
DecisionTreeFactor DecisionTreeFactor::apply(Unary op) const {
|
||||||
// apply operand
|
// apply operand
|
||||||
ADT result = ADT::apply(op);
|
ADT result = ADT::apply(op);
|
||||||
// Make a new factor
|
// Make a new factor
|
||||||
|
@ -91,7 +91,7 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor DecisionTreeFactor::apply(ADT::UnaryAssignment op) const {
|
DecisionTreeFactor DecisionTreeFactor::apply(UnaryAssignment op) const {
|
||||||
// apply operand
|
// apply operand
|
||||||
ADT result = ADT::apply(op);
|
ADT result = ADT::apply(op);
|
||||||
// Make a new factor
|
// Make a new factor
|
||||||
|
@ -100,7 +100,7 @@ namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor DecisionTreeFactor::apply(const DecisionTreeFactor& f,
|
DecisionTreeFactor DecisionTreeFactor::apply(const DecisionTreeFactor& f,
|
||||||
ADT::Binary op) const {
|
Binary op) const {
|
||||||
map<Key, size_t> cs; // new cardinalities
|
map<Key, size_t> cs; // new cardinalities
|
||||||
// make unique key-cardinality map
|
// make unique key-cardinality map
|
||||||
for (Key j : keys()) cs[j] = cardinality(j);
|
for (Key j : keys()) cs[j] = cardinality(j);
|
||||||
|
@ -118,8 +118,8 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(
|
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(size_t nrFrontals,
|
||||||
size_t nrFrontals, ADT::Binary op) const {
|
Binary op) const {
|
||||||
if (nrFrontals > size()) {
|
if (nrFrontals > size()) {
|
||||||
throw invalid_argument(
|
throw invalid_argument(
|
||||||
"DecisionTreeFactor::combine: invalid number of frontal "
|
"DecisionTreeFactor::combine: invalid number of frontal "
|
||||||
|
@ -146,7 +146,7 @@ namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(
|
DecisionTreeFactor::shared_ptr DecisionTreeFactor::combine(
|
||||||
const Ordering& frontalKeys, ADT::Binary op) const {
|
const Ordering& frontalKeys, Binary op) const {
|
||||||
if (frontalKeys.size() > size()) {
|
if (frontalKeys.size() > size()) {
|
||||||
throw invalid_argument(
|
throw invalid_argument(
|
||||||
"DecisionTreeFactor::combine: invalid number of frontal "
|
"DecisionTreeFactor::combine: invalid number of frontal "
|
||||||
|
@ -195,7 +195,7 @@ namespace gtsam {
|
||||||
// Construct unordered_map with values
|
// Construct unordered_map with values
|
||||||
std::vector<std::pair<DiscreteValues, double>> result;
|
std::vector<std::pair<DiscreteValues, double>> result;
|
||||||
for (const auto& assignment : assignments) {
|
for (const auto& assignment : assignments) {
|
||||||
result.emplace_back(assignment, operator()(assignment));
|
result.emplace_back(assignment, evaluate(assignment));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,12 @@
|
||||||
#include <gtsam/discrete/AlgebraicDecisionTree.h>
|
#include <gtsam/discrete/AlgebraicDecisionTree.h>
|
||||||
#include <gtsam/discrete/DiscreteFactor.h>
|
#include <gtsam/discrete/DiscreteFactor.h>
|
||||||
#include <gtsam/discrete/DiscreteKey.h>
|
#include <gtsam/discrete/DiscreteKey.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/inference/Ordering.h>
|
#include <gtsam/inference/Ordering.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -50,6 +51,11 @@ namespace gtsam {
|
||||||
typedef std::shared_ptr<DecisionTreeFactor> shared_ptr;
|
typedef std::shared_ptr<DecisionTreeFactor> shared_ptr;
|
||||||
typedef AlgebraicDecisionTree<Key> ADT;
|
typedef AlgebraicDecisionTree<Key> ADT;
|
||||||
|
|
||||||
|
// Needed since we have definitions in both DiscreteFactor and DecisionTree
|
||||||
|
using Base::Binary;
|
||||||
|
using Base::Unary;
|
||||||
|
using Base::UnaryAssignment;
|
||||||
|
|
||||||
/// @name Standard Constructors
|
/// @name Standard Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -129,23 +135,21 @@ namespace gtsam {
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/// Calculate probability for given values `x`,
|
/// Calculate probability for given values,
|
||||||
/// is just look up in AlgebraicDecisionTree.
|
/// is just look up in AlgebraicDecisionTree.
|
||||||
double evaluate(const Assignment<Key>& values) const {
|
virtual double evaluate(const Assignment<Key>& values) const override {
|
||||||
return ADT::operator()(values);
|
return ADT::operator()(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate probability distribution, sugar.
|
/// Disambiguate to use DiscreteFactor version. Mainly for wrapper
|
||||||
double operator()(const DiscreteValues& values) const override {
|
using DiscreteFactor::operator();
|
||||||
return ADT::operator()(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate error for DiscreteValues `x`, is -log(probability).
|
/// Calculate error for DiscreteValues `x`, is -log(probability).
|
||||||
double error(const DiscreteValues& values) const override;
|
double error(const DiscreteValues& values) const override;
|
||||||
|
|
||||||
/// multiply two factors
|
/// multiply two factors
|
||||||
DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override {
|
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);
|
static double safe_div(const double& a, const double& b);
|
||||||
|
@ -160,22 +164,22 @@ namespace gtsam {
|
||||||
|
|
||||||
/// Create new factor by summing all values with the same separator values
|
/// Create new factor by summing all values with the same separator values
|
||||||
shared_ptr sum(size_t nrFrontals) const {
|
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
|
/// Create new factor by summing all values with the same separator values
|
||||||
shared_ptr sum(const Ordering& keys) const {
|
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.
|
/// Create new factor by maximizing over all values with the same separator.
|
||||||
shared_ptr max(size_t nrFrontals) const {
|
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.
|
/// Create new factor by maximizing over all values with the same separator.
|
||||||
shared_ptr max(const Ordering& keys) const {
|
shared_ptr max(const Ordering& keys) const {
|
||||||
return combine(keys, ADT::Ring::max);
|
return combine(keys, Ring::max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
@ -186,21 +190,21 @@ namespace gtsam {
|
||||||
* Apply unary operator (*this) "op" f
|
* Apply unary operator (*this) "op" f
|
||||||
* @param op a unary operator that operates on AlgebraicDecisionTree
|
* @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
|
* Apply unary operator (*this) "op" f
|
||||||
* @param op a unary operator that operates on AlgebraicDecisionTree. Takes
|
* @param op a unary operator that operates on AlgebraicDecisionTree. Takes
|
||||||
* both the assignment and the value.
|
* both the assignment and the value.
|
||||||
*/
|
*/
|
||||||
DecisionTreeFactor apply(ADT::UnaryAssignment op) const;
|
DecisionTreeFactor apply(UnaryAssignment op) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply binary operator (*this) "op" f
|
* Apply binary operator (*this) "op" f
|
||||||
* @param f the second argument for op
|
* @param f the second argument for op
|
||||||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
* @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"
|
* Combine frontal variables using binary operator "op"
|
||||||
|
@ -208,7 +212,7 @@ namespace gtsam {
|
||||||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
* @param op a binary operator that operates on AlgebraicDecisionTree
|
||||||
* @return shared pointer to newly created DecisionTreeFactor
|
* @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"
|
* Combine frontal variables in an Ordering using binary operator "op"
|
||||||
|
@ -216,7 +220,7 @@ namespace gtsam {
|
||||||
* @param op a binary operator that operates on AlgebraicDecisionTree
|
* @param op a binary operator that operates on AlgebraicDecisionTree
|
||||||
* @return shared pointer to newly created DecisionTreeFactor
|
* @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.
|
/// Enumerate all values into a map from values to double.
|
||||||
std::vector<std::pair<DiscreteValues, double>> enumerate() const;
|
std::vector<std::pair<DiscreteValues, double>> enumerate() const;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/base/debug.h>
|
#include <gtsam/base/debug.h>
|
||||||
#include <gtsam/discrete/DiscreteConditional.h>
|
#include <gtsam/discrete/DiscreteConditional.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/discrete/Signature.h>
|
#include <gtsam/discrete/Signature.h>
|
||||||
#include <gtsam/hybrid/HybridValues.h>
|
#include <gtsam/hybrid/HybridValues.h>
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
@ -104,7 +106,7 @@ DiscreteConditional DiscreteConditional::operator*(
|
||||||
// Finally, add parents to keys, in order
|
// Finally, add parents to keys, in order
|
||||||
for (auto&& dk : parents) discreteKeys.push_back(dk);
|
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);
|
return DiscreteConditional(newFrontals.size(), discreteKeys, product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,13 +168,9 @@ class GTSAM_EXPORT DiscreteConditional
|
||||||
static_cast<const BaseConditional*>(this)->print(s, formatter);
|
static_cast<const BaseConditional*>(this)->print(s, formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate, just look up in AlgebraicDecisionTree
|
using BaseFactor::error; ///< DiscreteValues version
|
||||||
double evaluate(const DiscreteValues& values) const {
|
using BaseFactor::evaluate; ///< DiscreteValues version
|
||||||
return ADT::operator()(values);
|
using BaseFactor::operator(); ///< DiscreteValues version
|
||||||
}
|
|
||||||
|
|
||||||
using DecisionTreeFactor::error; ///< DiscreteValues version
|
|
||||||
using DecisionTreeFactor::operator(); ///< DiscreteValues version
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief restrict to given *parent* values.
|
* @brief restrict to given *parent* values.
|
||||||
|
|
|
@ -40,7 +40,7 @@ class GTSAM_EXPORT DiscreteDistribution : public DiscreteConditional {
|
||||||
/// Default constructor needed for serialization.
|
/// Default constructor needed for serialization.
|
||||||
DiscreteDistribution() {}
|
DiscreteDistribution() {}
|
||||||
|
|
||||||
/// Constructor from factor.
|
/// Constructor from DecisionTreeFactor.
|
||||||
explicit DiscreteDistribution(const DecisionTreeFactor& f)
|
explicit DiscreteDistribution(const DecisionTreeFactor& f)
|
||||||
: Base(f.size(), f) {}
|
: Base(f.size(), f) {}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,11 @@ class GTSAM_EXPORT DiscreteFactor : public Factor {
|
||||||
|
|
||||||
using Values = DiscreteValues; ///< backwards compatibility
|
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:
|
protected:
|
||||||
/// Map of Keys and their cardinalities.
|
/// Map of Keys and their cardinalities.
|
||||||
std::map<Key, size_t> cardinalities_;
|
std::map<Key, size_t> cardinalities_;
|
||||||
|
@ -92,8 +97,21 @@ class GTSAM_EXPORT DiscreteFactor : public Factor {
|
||||||
|
|
||||||
size_t cardinality(Key j) const { return cardinalities_.at(j); }
|
size_t cardinality(Key j) const { return cardinalities_.at(j); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculate probability for given values.
|
||||||
|
* Calls specialized evaluation under the hood.
|
||||||
|
*
|
||||||
|
* Note: Uses Assignment<Key> as it is the base class of DiscreteValues.
|
||||||
|
*
|
||||||
|
* @param values Discrete assignment.
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
virtual double evaluate(const Assignment<Key>& values) const = 0;
|
||||||
|
|
||||||
/// Find value for given assignment of values to variables
|
/// Find value for given assignment of values to variables
|
||||||
virtual double operator()(const DiscreteValues&) const = 0;
|
double operator()(const DiscreteValues& values) const {
|
||||||
|
return evaluate(values);
|
||||||
|
}
|
||||||
|
|
||||||
/// Error is just -log(value)
|
/// Error is just -log(value)
|
||||||
virtual double error(const DiscreteValues& values) const;
|
virtual double error(const DiscreteValues& values) const;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* @date Feb 14, 2011
|
* @date Feb 14, 2011
|
||||||
* @author Duy-Nguyen Ta
|
* @author Duy-Nguyen Ta
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
|
* @author Varun Agrawal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtsam/discrete/DiscreteBayesTree.h>
|
#include <gtsam/discrete/DiscreteBayesTree.h>
|
||||||
|
@ -35,13 +36,12 @@ namespace gtsam {
|
||||||
template class FactorGraph<DiscreteFactor>;
|
template class FactorGraph<DiscreteFactor>;
|
||||||
template class EliminateableFactorGraph<DiscreteFactorGraph>;
|
template class EliminateableFactorGraph<DiscreteFactorGraph>;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
bool DiscreteFactorGraph::equals(const This& fg, double tol) const
|
bool DiscreteFactorGraph::equals(const This& fg, double tol) const {
|
||||||
{
|
|
||||||
return Base::equals(fg, tol);
|
return Base::equals(fg, tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
KeySet DiscreteFactorGraph::keys() const {
|
KeySet DiscreteFactorGraph::keys() const {
|
||||||
KeySet keys;
|
KeySet keys;
|
||||||
for (const sharedFactor& factor : *this) {
|
for (const sharedFactor& factor : *this) {
|
||||||
|
@ -50,11 +50,11 @@ namespace gtsam {
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
DiscreteKeys DiscreteFactorGraph::discreteKeys() const {
|
DiscreteKeys DiscreteFactorGraph::discreteKeys() const {
|
||||||
DiscreteKeys result;
|
DiscreteKeys result;
|
||||||
for (auto&& factor : *this) {
|
for (auto&& factor : *this) {
|
||||||
if (auto p = std::dynamic_pointer_cast<DecisionTreeFactor>(factor)) {
|
if (auto p = std::dynamic_pointer_cast<DiscreteFactor>(factor)) {
|
||||||
DiscreteKeys factor_keys = p->discreteKeys();
|
DiscreteKeys factor_keys = p->discreteKeys();
|
||||||
result.insert(result.end(), factor_keys.begin(), factor_keys.end());
|
result.insert(result.end(), factor_keys.begin(), factor_keys.end());
|
||||||
}
|
}
|
||||||
|
@ -63,24 +63,25 @@ namespace gtsam {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor DiscreteFactorGraph::product() const {
|
DecisionTreeFactor DiscreteFactorGraph::product() const {
|
||||||
DecisionTreeFactor result;
|
DecisionTreeFactor result;
|
||||||
for(const sharedFactor& factor: *this)
|
for (const sharedFactor& factor : *this) {
|
||||||
if (factor) result = (*factor) * result;
|
if (factor) result = (*factor) * result;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
double DiscreteFactorGraph::operator()(
|
double DiscreteFactorGraph::operator()(const DiscreteValues& values) const {
|
||||||
const DiscreteValues &values) const {
|
|
||||||
double product = 1.0;
|
double product = 1.0;
|
||||||
for( const sharedFactor& factor: factors_ )
|
for (const sharedFactor& factor : factors_) {
|
||||||
product *= (*factor)(values);
|
if (factor) product *= (*factor)(values);
|
||||||
|
}
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************ */
|
||||||
void DiscreteFactorGraph::print(const string& s,
|
void DiscreteFactorGraph::print(const string& s,
|
||||||
const KeyFormatter& formatter) const {
|
const KeyFormatter& formatter) const {
|
||||||
std::cout << s << std::endl;
|
std::cout << s << std::endl;
|
||||||
|
@ -110,15 +111,18 @@ namespace gtsam {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/**
|
||||||
// Alternate eliminate function for MPE
|
* @brief Multiply all the `factors` and normalize the
|
||||||
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> //
|
* product to prevent underflow.
|
||||||
EliminateForMPE(const DiscreteFactorGraph& factors,
|
*
|
||||||
const Ordering& frontalKeys) {
|
* @param factors The factors to multiply as a DiscreteFactorGraph.
|
||||||
|
* @return DecisionTreeFactor
|
||||||
|
*/
|
||||||
|
static DecisionTreeFactor ProductAndNormalize(
|
||||||
|
const DiscreteFactorGraph& factors) {
|
||||||
// PRODUCT: multiply all factors
|
// PRODUCT: multiply all factors
|
||||||
gttic(product);
|
gttic(product);
|
||||||
DecisionTreeFactor product;
|
DecisionTreeFactor product = factors.product();
|
||||||
for (auto&& factor : factors) product = (*factor) * product;
|
|
||||||
gttoc(product);
|
gttoc(product);
|
||||||
|
|
||||||
// Max over all the potentials by pretending all keys are frontal:
|
// Max over all the potentials by pretending all keys are frontal:
|
||||||
|
@ -127,6 +131,16 @@ namespace gtsam {
|
||||||
// Normalize the product factor to prevent underflow.
|
// Normalize the product factor to prevent underflow.
|
||||||
product = product / (*normalization);
|
product = product / (*normalization);
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************ */
|
||||||
|
// Alternate eliminate function for MPE
|
||||||
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
||||||
|
EliminateForMPE(const DiscreteFactorGraph& factors,
|
||||||
|
const Ordering& frontalKeys) {
|
||||||
|
DecisionTreeFactor product = ProductAndNormalize(factors);
|
||||||
|
|
||||||
// max out frontals, this is the factor on the separator
|
// max out frontals, this is the factor on the separator
|
||||||
gttic(max);
|
gttic(max);
|
||||||
DecisionTreeFactor::shared_ptr max = product.max(frontalKeys);
|
DecisionTreeFactor::shared_ptr max = product.max(frontalKeys);
|
||||||
|
@ -142,8 +156,8 @@ namespace gtsam {
|
||||||
// Make lookup with product
|
// Make lookup with product
|
||||||
gttic(lookup);
|
gttic(lookup);
|
||||||
size_t nrFrontals = frontalKeys.size();
|
size_t nrFrontals = frontalKeys.size();
|
||||||
auto lookup = std::make_shared<DiscreteLookupTable>(nrFrontals,
|
auto lookup =
|
||||||
orderedKeys, product);
|
std::make_shared<DiscreteLookupTable>(nrFrontals, orderedKeys, product);
|
||||||
gttoc(lookup);
|
gttoc(lookup);
|
||||||
|
|
||||||
return {std::dynamic_pointer_cast<DiscreteConditional>(lookup), max};
|
return {std::dynamic_pointer_cast<DiscreteConditional>(lookup), max};
|
||||||
|
@ -201,20 +215,10 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> //
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
||||||
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys) {
|
const Ordering& frontalKeys) {
|
||||||
// PRODUCT: multiply all factors
|
DecisionTreeFactor product = ProductAndNormalize(factors);
|
||||||
gttic(product);
|
|
||||||
DecisionTreeFactor product;
|
|
||||||
for (auto&& factor : factors) product = (*factor) * product;
|
|
||||||
gttoc(product);
|
|
||||||
|
|
||||||
// Max over all the potentials by pretending all keys are frontal:
|
|
||||||
auto normalization = product.max(product.size());
|
|
||||||
|
|
||||||
// Normalize the product factor to prevent underflow.
|
|
||||||
product = product / (*normalization);
|
|
||||||
|
|
||||||
// sum out frontals, this is the factor on the separator
|
// sum out frontals, this is the factor on the separator
|
||||||
gttic(sum);
|
gttic(sum);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* @date Feb 14, 2011
|
* @date Feb 14, 2011
|
||||||
* @author Duy-Nguyen Ta
|
* @author Duy-Nguyen Ta
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
|
* @author Varun Agrawal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -48,7 +49,7 @@ class DiscreteJunctionTree;
|
||||||
* @ingroup discrete
|
* @ingroup discrete
|
||||||
*/
|
*/
|
||||||
GTSAM_EXPORT
|
GTSAM_EXPORT
|
||||||
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr>
|
||||||
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys);
|
const Ordering& frontalKeys);
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ EliminateDiscrete(const DiscreteFactorGraph& factors,
|
||||||
* @ingroup discrete
|
* @ingroup discrete
|
||||||
*/
|
*/
|
||||||
GTSAM_EXPORT
|
GTSAM_EXPORT
|
||||||
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr>
|
||||||
EliminateForMPE(const DiscreteFactorGraph& factors,
|
EliminateForMPE(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys);
|
const Ordering& frontalKeys);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
|
@ -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; }
|
||||||
|
};
|
|
@ -133,7 +133,7 @@ bool TableFactor::equals(const DiscreteFactor& other, double tol) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
double TableFactor::operator()(const DiscreteValues& values) const {
|
double TableFactor::evaluate(const Assignment<Key>& values) const {
|
||||||
// a b c d => D * (C * (B * (a) + b) + c) + d
|
// a b c d => D * (C * (B * (a) + b) + c) + d
|
||||||
uint64_t idx = 0, card = 1;
|
uint64_t idx = 0, card = 1;
|
||||||
for (auto it = sorted_dkeys_.rbegin(); it != sorted_dkeys_.rend(); ++it) {
|
for (auto it = sorted_dkeys_.rbegin(); it != sorted_dkeys_.rend(); ++it) {
|
||||||
|
@ -180,6 +180,7 @@ DecisionTreeFactor TableFactor::toDecisionTreeFactor() const {
|
||||||
for (auto i = 0; i < sparse_table_.size(); i++) {
|
for (auto i = 0; i < sparse_table_.size(); i++) {
|
||||||
table.push_back(sparse_table_.coeff(i));
|
table.push_back(sparse_table_.coeff(i));
|
||||||
}
|
}
|
||||||
|
// NOTE(Varun): This constructor is really expensive!!
|
||||||
DecisionTreeFactor f(dkeys, table);
|
DecisionTreeFactor f(dkeys, table);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <gtsam/discrete/DiscreteFactor.h>
|
#include <gtsam/discrete/DiscreteFactor.h>
|
||||||
#include <gtsam/discrete/DiscreteKey.h>
|
#include <gtsam/discrete/DiscreteKey.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/inference/Ordering.h>
|
#include <gtsam/inference/Ordering.h>
|
||||||
|
|
||||||
#include <Eigen/Sparse>
|
#include <Eigen/Sparse>
|
||||||
|
@ -93,27 +94,8 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor {
|
||||||
typedef std::shared_ptr<TableFactor> shared_ptr;
|
typedef std::shared_ptr<TableFactor> shared_ptr;
|
||||||
typedef Eigen::SparseVector<double>::InnerIterator SparseIt;
|
typedef Eigen::SparseVector<double>::InnerIterator SparseIt;
|
||||||
typedef std::vector<std::pair<DiscreteValues, double>> AssignValList;
|
typedef std::vector<std::pair<DiscreteValues, double>> AssignValList;
|
||||||
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)>;
|
|
||||||
|
|
||||||
public:
|
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
|
/// @name Standard Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -169,14 +151,8 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor {
|
||||||
// /// @name Standard Interface
|
// /// @name Standard Interface
|
||||||
// /// @{
|
// /// @{
|
||||||
|
|
||||||
/// Calculate probability for given values `x`,
|
/// Evaluate probability distribution, is just look up in TableFactor.
|
||||||
/// is just look up in TableFactor.
|
double evaluate(const Assignment<Key>& values) const override;
|
||||||
double evaluate(const DiscreteValues& values) const {
|
|
||||||
return operator()(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Evaluate probability distribution, sugar.
|
|
||||||
double operator()(const DiscreteValues& values) const override;
|
|
||||||
|
|
||||||
/// Calculate error for DiscreteValues `x`, is -log(probability).
|
/// Calculate error for DiscreteValues `x`, is -log(probability).
|
||||||
double error(const DiscreteValues& values) const override;
|
double error(const DiscreteValues& values) const override;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/base/serializationTestHelpers.h>
|
#include <gtsam/base/serializationTestHelpers.h>
|
||||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/discrete/Signature.h>
|
#include <gtsam/discrete/Signature.h>
|
||||||
#include <gtsam/inference/Symbol.h>
|
#include <gtsam/inference/Symbol.h>
|
||||||
|
|
||||||
|
@ -124,14 +125,6 @@ struct traits<DT> : public Testable<DT> {};
|
||||||
|
|
||||||
GTSAM_CONCEPT_TESTABLE_INST(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.
|
// Check that creating decision trees respects key order.
|
||||||
TEST(DecisionTree, ConstructorOrder) {
|
TEST(DecisionTree, ConstructorOrder) {
|
||||||
|
|
|
@ -113,7 +113,8 @@ TEST(DiscreteFactorGraph, test) {
|
||||||
const Ordering frontalKeys{0};
|
const Ordering frontalKeys{0};
|
||||||
const auto [conditional, newFactorPtr] = EliminateDiscrete(graph, frontalKeys);
|
const auto [conditional, newFactorPtr] = EliminateDiscrete(graph, frontalKeys);
|
||||||
|
|
||||||
DecisionTreeFactor newFactor = *newFactorPtr;
|
DecisionTreeFactor newFactor =
|
||||||
|
*std::dynamic_pointer_cast<DecisionTreeFactor>(newFactorPtr);
|
||||||
|
|
||||||
// Normalize newFactor by max for comparison with expected
|
// Normalize newFactor by max for comparison with expected
|
||||||
auto normalization = newFactor.max(newFactor.size());
|
auto normalization = newFactor.max(newFactor.size());
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <gtsam/geometry/Cal3f.h>
|
#include <gtsam/geometry/Cal3f.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <gtsam/inference/Key.h>
|
#include <gtsam/inference/Key.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <gtsam/base/concepts.h>
|
#include <gtsam/base/concepts.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,13 @@ public:
|
||||||
Pose2(const Rot2& r, const Point2& t) : r_(r), t_(t) {}
|
Pose2(const Rot2& r, const Point2& t) : r_(r), t_(t) {}
|
||||||
|
|
||||||
/** Constructor from 3*3 matrix */
|
/** Constructor from 3*3 matrix */
|
||||||
Pose2(const Matrix &T) :
|
Pose2(const Matrix &T)
|
||||||
r_(Rot2::atan2(T(1, 0), T(0, 0))), t_(T(0, 2), T(1, 2)) {
|
: r_(Rot2::atan2(T(1, 0), T(0, 0))), t_(T(0, 2), T(1, 2)) {
|
||||||
assert(T.rows() == 3 && T.cols() == 3);
|
#ifndef NDEBUG
|
||||||
|
if (T.rows() != 3 || T.cols() != 3) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <gtsam/geometry/SO3.h>
|
#include <gtsam/geometry/SO3.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -159,7 +159,11 @@ class GTSAM_EXPORT Rot3 : public LieGroup<Rot3, 3> {
|
||||||
/// Rotations around Z, Y, then X axes as in http://en.wikipedia.org/wiki/Rotation_matrix, counterclockwise when looking from unchanging axis.
|
/// Rotations around Z, Y, then X axes as in http://en.wikipedia.org/wiki/Rotation_matrix, counterclockwise when looking from unchanging axis.
|
||||||
inline static Rot3 RzRyRx(const Vector& xyz,
|
inline static Rot3 RzRyRx(const Vector& xyz,
|
||||||
OptionalJacobian<3, 3> H = {}) {
|
OptionalJacobian<3, 3> H = {}) {
|
||||||
assert(xyz.size() == 3);
|
#ifndef NDEBUG
|
||||||
|
if (xyz.size() != 3) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Rot3 out;
|
Rot3 out;
|
||||||
if (H) {
|
if (H) {
|
||||||
Vector3 Hx, Hy, Hz;
|
Vector3 Hx, Hy, Hz;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gtsam/geometry/Point3.h"
|
#include <gtsam/geometry/Point3.h>
|
||||||
#include <gtsam/geometry/Cal3Bundler.h>
|
#include <gtsam/geometry/Cal3Bundler.h>
|
||||||
#include <gtsam/geometry/Cal3Fisheye.h>
|
#include <gtsam/geometry/Cal3Fisheye.h>
|
||||||
#include <gtsam/geometry/Cal3Unified.h>
|
#include <gtsam/geometry/Cal3Unified.h>
|
||||||
|
@ -317,7 +317,11 @@ typename CAMERA::MeasurementVector undistortMeasurements(
|
||||||
const CameraSet<CAMERA>& cameras,
|
const CameraSet<CAMERA>& cameras,
|
||||||
const typename CAMERA::MeasurementVector& measurements) {
|
const typename CAMERA::MeasurementVector& measurements) {
|
||||||
const size_t nrMeasurements = measurements.size();
|
const size_t nrMeasurements = measurements.size();
|
||||||
assert(nrMeasurements == cameras.size());
|
#ifndef NDEBUG
|
||||||
|
if (nrMeasurements != cameras.size()) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
typename CAMERA::MeasurementVector undistortedMeasurements(nrMeasurements);
|
typename CAMERA::MeasurementVector undistortedMeasurements(nrMeasurements);
|
||||||
for (size_t ii = 0; ii < nrMeasurements; ++ii) {
|
for (size_t ii = 0; ii < nrMeasurements; ++ii) {
|
||||||
// Calibrate with cal and uncalibrate with pinhole version of cal so that
|
// Calibrate with cal and uncalibrate with pinhole version of cal so that
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <gtsam/inference/Key.h>
|
#include <gtsam/inference/Key.h>
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <cassert>
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#endif
|
#endif
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
#include <gtsam/base/treeTraversal-inst.h>
|
#include <gtsam/base/treeTraversal-inst.h>
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <gtsam/symbolic/SymbolicConditional.h>
|
#include <gtsam/symbolic/SymbolicConditional.h>
|
||||||
#include <gtsam/symbolic/SymbolicFactor-inst.h>
|
#include <gtsam/symbolic/SymbolicFactor-inst.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
template<class BAYESTREE, class GRAPH, class ETREE_NODE>
|
template<class BAYESTREE, class GRAPH, class ETREE_NODE>
|
||||||
|
|
|
@ -92,7 +92,11 @@ public:
|
||||||
return nKeys_;
|
return nKeys_;
|
||||||
}
|
}
|
||||||
Key intToKey(int32_t value) const {
|
Key intToKey(int32_t value) const {
|
||||||
assert(value >= 0);
|
#ifndef NDEBUG
|
||||||
|
if (value < 0) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return intKeyBMap_.right.find(value)->second;
|
return intKeyBMap_.right.find(value)->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <gtsam/inference/Ordering.h>
|
#include <gtsam/inference/Ordering.h>
|
||||||
#include <gtsam/3rdparty/CCOLAMD/Include/ccolamd.h>
|
#include <gtsam/3rdparty/CCOLAMD/Include/ccolamd.h>
|
||||||
|
|
|
@ -25,13 +25,14 @@
|
||||||
#include <gtsam/base/cholesky.h>
|
#include <gtsam/base/cholesky.h>
|
||||||
#include <gtsam/base/debug.h>
|
#include <gtsam/base/debug.h>
|
||||||
#include <gtsam/base/FastMap.h>
|
#include <gtsam/base/FastMap.h>
|
||||||
|
#include <gtsam/base/Vector.h>
|
||||||
#include <gtsam/base/Matrix.h>
|
#include <gtsam/base/Matrix.h>
|
||||||
#include <gtsam/base/ThreadsafeException.h>
|
#include <gtsam/base/ThreadsafeException.h>
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "gtsam/base/Vector.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <gtsam/base/SymmetricBlockMatrix.h>
|
#include <gtsam/base/SymmetricBlockMatrix.h>
|
||||||
#include <gtsam/base/FastVector.h>
|
#include <gtsam/base/FastVector.h>
|
||||||
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
@ -241,14 +240,18 @@ namespace gtsam {
|
||||||
* use, for example, begin() + 2 to get the 3rd variable in this factor.
|
* use, for example, begin() + 2 to get the 3rd variable in this factor.
|
||||||
* @return The linear term \f$ g \f$ */
|
* @return The linear term \f$ g \f$ */
|
||||||
SymmetricBlockMatrix::constBlock linearTerm(const_iterator j) const {
|
SymmetricBlockMatrix::constBlock linearTerm(const_iterator j) const {
|
||||||
assert(!empty());
|
#ifndef NDEBUG
|
||||||
|
if(empty()) throw;
|
||||||
|
#endif
|
||||||
return info_.aboveDiagonalBlock(j - begin(), size());
|
return info_.aboveDiagonalBlock(j - begin(), size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the complete linear term \f$ g \f$ as described above.
|
/** Return the complete linear term \f$ g \f$ as described above.
|
||||||
* @return The linear term \f$ g \f$ */
|
* @return The linear term \f$ g \f$ */
|
||||||
SymmetricBlockMatrix::constBlock linearTerm() const {
|
SymmetricBlockMatrix::constBlock linearTerm() const {
|
||||||
assert(!empty());
|
#ifndef NDEBUG
|
||||||
|
if(empty()) throw;
|
||||||
|
#endif
|
||||||
// get the last column (except the bottom right block)
|
// get the last column (except the bottom right block)
|
||||||
return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
|
return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
|
||||||
}
|
}
|
||||||
|
@ -256,7 +259,9 @@ namespace gtsam {
|
||||||
/** Return the complete linear term \f$ g \f$ as described above.
|
/** Return the complete linear term \f$ g \f$ as described above.
|
||||||
* @return The linear term \f$ g \f$ */
|
* @return The linear term \f$ g \f$ */
|
||||||
SymmetricBlockMatrix::Block linearTerm() {
|
SymmetricBlockMatrix::Block linearTerm() {
|
||||||
assert(!empty());
|
#ifndef NDEBUG
|
||||||
|
if(empty()) throw;
|
||||||
|
#endif
|
||||||
return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
|
return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +330,9 @@ namespace gtsam {
|
||||||
* @param other the HessianFactor to be updated
|
* @param other the HessianFactor to be updated
|
||||||
*/
|
*/
|
||||||
void updateHessian(HessianFactor* other) const {
|
void updateHessian(HessianFactor* other) const {
|
||||||
assert(other);
|
#ifndef NDEBUG
|
||||||
|
if(!other) throw;
|
||||||
|
#endif
|
||||||
updateHessian(other->keys_, &other->info_);
|
updateHessian(other->keys_, &other->info_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <gtsam/base/cholesky.h>
|
#include <gtsam/base/cholesky.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,16 @@
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <gtsam/linear/KalmanFilter.h>
|
||||||
|
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/linear/GaussianBayesNet.h>
|
#include <gtsam/linear/GaussianBayesNet.h>
|
||||||
#include <gtsam/linear/JacobianFactor.h>
|
#include <gtsam/linear/JacobianFactor.h>
|
||||||
#include <gtsam/linear/KalmanFilter.h>
|
|
||||||
|
|
||||||
#include "gtsam/base/Matrix.h"
|
#ifndef NDEBUG
|
||||||
|
#include <cassert>
|
||||||
|
#endif
|
||||||
|
|
||||||
// In the code below we often get a covariance matrix Q, and we need to create a
|
// In the code below we often get a covariance matrix Q, and we need to create a
|
||||||
// JacobianFactor with cost 0.5 * |Ax - b|^T Q^{-1} |Ax - b|. Factorizing Q as
|
// JacobianFactor with cost 0.5 * |Ax - b|^T Q^{-1} |Ax - b|. Factorizing Q as
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtsam/linear/Sampler.h>
|
#include <gtsam/linear/Sampler.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <gtsam/base/Vector.h>
|
#include <gtsam/base/Vector.h>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* External or standard includes */
|
/* External or standard includes */
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
* @author Varun Agrawal
|
* @author Varun Agrawal
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "PreintegrationBase.h"
|
#include <gtsam/navigation/PreintegrationBase.h>
|
||||||
#include <gtsam/base/numericalDerivative.h>
|
#include <gtsam/base/numericalDerivative.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <gtsam/linear/VectorValues.h>
|
#include <gtsam/linear/VectorValues.h>
|
||||||
#include <gtsam/inference/Ordering.h>
|
#include <gtsam/inference/Ordering.h>
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include <gtsam/linear/GaussianBayesNet.h>
|
#include <gtsam/linear/GaussianBayesNet.h>
|
||||||
#include <gtsam/linear/GaussianFactorGraph.h>
|
#include <gtsam/linear/GaussianFactorGraph.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <gtsam/hybrid/HybridValues.h>
|
#include <gtsam/hybrid/HybridValues.h>
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <typeinfo> // operator typeid
|
#include <typeinfo> // operator typeid
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
class ExpressionFactorBinaryTest;
|
class ExpressionFactorBinaryTest;
|
||||||
// Forward declare for testing
|
// Forward declare for testing
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,9 @@ class EssentialMatrixFactor : public NoiseModelFactorN<EssentialMatrix> {
|
||||||
const SharedNoiseModel& model,
|
const SharedNoiseModel& model,
|
||||||
std::shared_ptr<CALIBRATION> K)
|
std::shared_ptr<CALIBRATION> K)
|
||||||
: Base(model, key) {
|
: Base(model, key) {
|
||||||
assert(K);
|
#ifndef NDEBUG
|
||||||
|
if (!K) throw;
|
||||||
|
#endif
|
||||||
vA_ = EssentialMatrix::Homogeneous(K->calibrate(pA));
|
vA_ = EssentialMatrix::Homogeneous(K->calibrate(pA));
|
||||||
vB_ = EssentialMatrix::Homogeneous(K->calibrate(pB));
|
vB_ = EssentialMatrix::Homogeneous(K->calibrate(pB));
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,11 @@ protected:
|
||||||
|
|
||||||
/// Add a bunch of measurements, together with the camera keys.
|
/// Add a bunch of measurements, together with the camera keys.
|
||||||
void add(const ZVector& measurements, const KeyVector& cameraKeys) {
|
void add(const ZVector& measurements, const KeyVector& cameraKeys) {
|
||||||
assert(measurements.size() == cameraKeys.size());
|
#ifndef NDEBUG
|
||||||
|
if (measurements.size() != cameraKeys.size()) {
|
||||||
|
throw std::runtime_error("Number of measurements and camera keys do not match");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for (size_t i = 0; i < measurements.size(); i++) {
|
for (size_t i = 0; i < measurements.size(); i++) {
|
||||||
this->add(measurements[i], cameraKeys[i]);
|
this->add(measurements[i], cameraKeys[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ void AllDiff::print(const std::string& s, const KeyFormatter& formatter) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
double AllDiff::operator()(const DiscreteValues& values) const {
|
double AllDiff::evaluate(const Assignment<Key>& values) const {
|
||||||
std::set<size_t> taken; // record values taken by keys
|
std::set<size_t> taken; // record values taken by keys
|
||||||
for (Key dkey : keys_) {
|
for (Key dkey : keys_) {
|
||||||
size_t value = values.at(dkey); // get the value for that key
|
size_t value = values.at(dkey); // get the value for that key
|
||||||
|
|
|
@ -45,7 +45,7 @@ class GTSAM_UNSTABLE_EXPORT AllDiff : public Constraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate value = expensive !
|
/// Calculate value = expensive !
|
||||||
double operator()(const DiscreteValues& values) const override;
|
double evaluate(const Assignment<Key>& values) const override;
|
||||||
|
|
||||||
/// Convert into a decisiontree, can be *very* expensive !
|
/// Convert into a decisiontree, can be *very* expensive !
|
||||||
DecisionTreeFactor toDecisionTreeFactor() const override;
|
DecisionTreeFactor toDecisionTreeFactor() const override;
|
||||||
|
|
|
@ -47,7 +47,7 @@ class BinaryAllDiff : public Constraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate value
|
/// Calculate value
|
||||||
double operator()(const DiscreteValues& values) const override {
|
double evaluate(const Assignment<Key>& values) const override {
|
||||||
return (double)(values.at(keys_[0]) != values.at(keys_[1]));
|
return (double)(values.at(keys_[0]) != values.at(keys_[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ string Domain::base1Str() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
double Domain::operator()(const DiscreteValues& values) const {
|
double Domain::evaluate(const Assignment<Key>& values) const {
|
||||||
return contains(values.at(key()));
|
return contains(values.at(key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class GTSAM_UNSTABLE_EXPORT Domain : public Constraint {
|
||||||
bool contains(size_t value) const { return values_.count(value) > 0; }
|
bool contains(size_t value) const { return values_.count(value) > 0; }
|
||||||
|
|
||||||
/// Calculate value
|
/// Calculate value
|
||||||
double operator()(const DiscreteValues& values) const override;
|
double evaluate(const Assignment<Key>& values) const override;
|
||||||
|
|
||||||
/// Convert into a decisiontree
|
/// Convert into a decisiontree
|
||||||
DecisionTreeFactor toDecisionTreeFactor() const override;
|
DecisionTreeFactor toDecisionTreeFactor() const override;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ void SingleValue::print(const string& s, const KeyFormatter& formatter) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
double SingleValue::operator()(const DiscreteValues& values) const {
|
double SingleValue::evaluate(const Assignment<Key>& values) const {
|
||||||
return (double)(values.at(keys_[0]) == value_);
|
return (double)(values.at(keys_[0]) == value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate value
|
/// Calculate value
|
||||||
double operator()(const DiscreteValues& values) const override;
|
double evaluate(const Assignment<Key>& values) const override;
|
||||||
|
|
||||||
/// Convert into a decisiontree
|
/// Convert into a decisiontree
|
||||||
DecisionTreeFactor toDecisionTreeFactor() const override;
|
DecisionTreeFactor toDecisionTreeFactor() const override;
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
||||||
#include <gtsam_unstable/slam/PartialPriorFactor.h>
|
#include <gtsam_unstable/slam/PartialPriorFactor.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
// Indices of relevant variables in the PoseRTV tangent vector:
|
// Indices of relevant variables in the PoseRTV tangent vector:
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <gtsam/geometry/Pose2.h>
|
#include <gtsam/geometry/Pose2.h>
|
||||||
#include <gtsam/base/Vector.h>
|
#include <gtsam/base/Vector.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
#include <gtsam_unstable/dynamics/PoseRTV.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
namespace dynamics {
|
namespace dynamics {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/geometry/BearingS2.h>
|
#include <gtsam_unstable/geometry/BearingS2.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "gtsam/base/OptionalJacobian.h"
|
#include <cassert>
|
||||||
#include "gtsam/base/Vector.h"
|
#include <gtsam/base/OptionalJacobian.h>
|
||||||
|
#include <gtsam/base/Vector.h>
|
||||||
|
|
||||||
#include <gtsam_unstable/geometry/Pose3Upright.h>
|
#include <gtsam_unstable/geometry/Pose3Upright.h>
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
#include <gtsam/base/debug.h>
|
#include <gtsam/base/debug.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/nonlinear/LinearizedFactor.h>
|
#include <gtsam_unstable/nonlinear/LinearizedFactor.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <cassert>
|
||||||
#include <boost/shared_array.hpp>
|
#include <boost/shared_array.hpp>
|
||||||
|
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
#include <gtsam/base/Lie.h>
|
#include <gtsam/base/Lie.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/slam/SmartStereoProjectionFactorPP.h>
|
#include <gtsam_unstable/slam/SmartStereoProjectionFactorPP.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
SmartStereoProjectionFactorPP::SmartStereoProjectionFactorPP(
|
SmartStereoProjectionFactorPP::SmartStereoProjectionFactorPP(
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h>
|
#include <gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
SmartStereoProjectionPoseFactor::SmartStereoProjectionPoseFactor(
|
SmartStereoProjectionPoseFactor::SmartStereoProjectionPoseFactor(
|
||||||
|
|
|
@ -13,9 +13,10 @@ Author: Frank Dellaert
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from gtsam.utils.test_case import GtsamTestCase
|
||||||
|
|
||||||
from gtsam import (DecisionTreeFactor, DiscreteDistribution, DiscreteValues,
|
from gtsam import (DecisionTreeFactor, DiscreteDistribution, DiscreteValues,
|
||||||
Ordering)
|
Ordering)
|
||||||
from gtsam.utils.test_case import GtsamTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class TestDecisionTreeFactor(GtsamTestCase):
|
class TestDecisionTreeFactor(GtsamTestCase):
|
||||||
|
|
|
@ -19,8 +19,8 @@ from gtsam.utils.test_case import GtsamTestCase
|
||||||
|
|
||||||
import gtsam
|
import gtsam
|
||||||
from gtsam import (DiscreteBayesNet, DiscreteBayesTreeClique,
|
from gtsam import (DiscreteBayesNet, DiscreteBayesTreeClique,
|
||||||
DiscreteConditional, DiscreteFactorGraph,
|
DiscreteConditional, DiscreteFactorGraph, DiscreteValues,
|
||||||
DiscreteValues, Ordering)
|
Ordering)
|
||||||
|
|
||||||
|
|
||||||
class TestDiscreteBayesNet(GtsamTestCase):
|
class TestDiscreteBayesNet(GtsamTestCase):
|
||||||
|
|
|
@ -13,9 +13,10 @@ Author: Varun Agrawal
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from gtsam import DecisionTreeFactor, DiscreteConditional, DiscreteKeys
|
|
||||||
from gtsam.utils.test_case import GtsamTestCase
|
from gtsam.utils.test_case import GtsamTestCase
|
||||||
|
|
||||||
|
from gtsam import DecisionTreeFactor, DiscreteConditional, DiscreteKeys
|
||||||
|
|
||||||
# Some DiscreteKeys for binary variables:
|
# Some DiscreteKeys for binary variables:
|
||||||
A = 0, 2
|
A = 0, 2
|
||||||
B = 1, 2
|
B = 1, 2
|
||||||
|
|
|
@ -14,9 +14,12 @@ Author: Frank Dellaert
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from gtsam import DecisionTreeFactor, DiscreteConditional, DiscreteFactorGraph, DiscreteKeys, DiscreteValues, Ordering, Symbol
|
|
||||||
from gtsam.utils.test_case import GtsamTestCase
|
from gtsam.utils.test_case import GtsamTestCase
|
||||||
|
|
||||||
|
from gtsam import (DecisionTreeFactor, DiscreteConditional,
|
||||||
|
DiscreteFactorGraph, DiscreteKeys, DiscreteValues, Ordering,
|
||||||
|
Symbol)
|
||||||
|
|
||||||
OrderingType = Ordering.OrderingType
|
OrderingType = Ordering.OrderingType
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <CppUnitLite/TestHarness.h>
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
Loading…
Reference in New Issue