Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #1217

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions gtsam/discrete/DecisionTree-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
#include <string>
#include <vector>

using boost::assign::operator+=;

namespace gtsam {

using boost::assign::operator+=;

/****************************************************************************/
// Node
/****************************************************************************/
Expand Down Expand Up @@ -291,10 +291,7 @@ namespace gtsam {
}

os << "\"" << this->id() << "\" -> \"" << branch->id() << "\"";
if (B == 2) {
if (i == 0) os << " [style=dashed]";
if (i > 1) os << " [style=bold]";
}
if (B == 2 && i == 0) os << " [style=dashed]";
os << std::endl;
branch->dot(os, labelFormatter, valueFormatter, showZero);
}
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/DecisionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace gtsam {
/// @{

/// Make virtual
virtual ~DecisionTree() {}
virtual ~DecisionTree() = default;

/// Check if tree is empty.
bool empty() const { return !root_; }
Expand Down
4 changes: 4 additions & 0 deletions gtsam/discrete/DiscreteFactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class GTSAM_EXPORT DiscreteFactorGraph
/// @}
}; // \ DiscreteFactorGraph

std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> //
EliminateForMPE(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys);

/// traits
template <>
struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
Expand Down
2 changes: 1 addition & 1 deletion gtsam/inference/FactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class FactorGraph {
* less than the original, factors at the end will be removed. If the new
* size is larger than the original, null factors will be appended.
*/
void resize(size_t size) { factors_.resize(size); }
virtual void resize(size_t size) { factors_.resize(size); }

/** delete factor without re-arranging indexes by inserting a nullptr pointer
*/
Expand Down
11 changes: 11 additions & 0 deletions gtsam/inference/Ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ void Ordering::print(const std::string& str,
cout.flush();
}

/* ************************************************************************* */
Ordering::This& Ordering::operator+=(KeyVector& keys) {
this->insert(this->end(), keys.begin(), keys.end());
return *this;
}

/* ************************************************************************* */
bool Ordering::contains(const Key& key) const {
return std::find(this->begin(), this->end(), key) != this->end();
}

/* ************************************************************************* */
bool Ordering::equals(const Ordering& other, double tol) const {
return (*this) == other;
Expand Down
18 changes: 17 additions & 1 deletion gtsam/inference/Ordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,23 @@ class Ordering: public KeyVector {
boost::assign_detail::call_push_back<This>(*this))(key);
}

/// Invert (not reverse) the ordering - returns a map from key to order position
/**
* @brief Append new keys to the ordering as `ordering += keys`.
*
* @param key
* @return The ordering variable with appended keys.
*/
This& operator+=(KeyVector& keys);

/// Check if key exists in ordering.
bool contains(const Key& key) const;

/**
* @brief Invert (not reverse) the ordering - returns a map from key to order
* position.
*
* @return FastMap<Key, size_t>
*/
FastMap<Key, size_t> invert() const;

/// @name Fill-reducing Orderings @{
Expand Down
26 changes: 26 additions & 0 deletions gtsam/inference/tests/testOrdering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ TEST(Ordering, csr_format_3) {
EXPECT(adjExpected == adjAcutal);
}

/* ************************************************************************* */
TEST(Ordering, AppendVector) {
using symbol_shorthand::X;
Ordering actual;
KeyVector keys = {X(0), X(1), X(2)};
actual += keys;

Ordering expected;
expected += X(0);
expected += X(1);
expected += X(2);
EXPECT(assert_equal(expected, actual));
}

/* ************************************************************************* */
TEST(Ordering, Contains) {
using symbol_shorthand::X;
Ordering ordering;
ordering += X(0);
ordering += X(1);
ordering += X(2);

EXPECT(ordering.contains(X(1)));
EXPECT(!ordering.contains(X(4)));
}

/* ************************************************************************* */
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
TEST(Ordering, csr_format_4) {
Expand Down
2 changes: 1 addition & 1 deletion gtsam/linear/GaussianBayesNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace gtsam {
/// @name Standard Constructors
/// @{

/** Construct empty factor graph */
/** Construct empty bayes net */
GaussianBayesNet() {}

/** Construct from iterator over conditionals */
Expand Down
4 changes: 2 additions & 2 deletions gtsam/linear/GaussianConditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* @author Christian Potthast, Frank Dellaert
*/

#include <gtsam/linear/linearExceptions.h>
#include <gtsam/linear/GaussianConditional.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/linear/Sampler.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/linear/linearExceptions.h>

#include <boost/format.hpp>
#ifdef __GNUC__
Expand Down
1 change: 1 addition & 0 deletions gtsam/linear/GaussianConditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gtsam/global_includes.h>
#include <gtsam/linear/JacobianFactor.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/inference/Conditional-inst.h>
#include <gtsam/linear/VectorValues.h>

#include <random> // for std::mt19937_64
Expand Down