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

Fan/prototype hybrid tr #42

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ea4ebb6
Fix typo
ProfFan Mar 11, 2022
0567303
Prototype a type-erased hybrid machinery
ProfFan Mar 11, 2022
efa37ff
Add better mocking for actual elimination
ProfFan Mar 12, 2022
3aac52c
Fix compilation error
ProfFan Mar 12, 2022
53551e0
Add shorthand for inserting raw JacobianFactor
ProfFan Mar 12, 2022
095f6ad
Add full elimination
ProfFan Mar 12, 2022
2bae286
More mock-ups added
ProfFan Mar 12, 2022
ee4f9d1
Added mixture factor functionality
ProfFan Mar 13, 2022
5ea614a
Added more mockups and color output of the elimination process
ProfFan Mar 14, 2022
0aeb596
add more comments
ProfFan Mar 14, 2022
fe5dde7
even better printing and comments
ProfFan Mar 14, 2022
f237438
Address comments
ProfFan Mar 15, 2022
36ee4ce
Missing pragma onces
ProfFan Mar 15, 2022
7ad2031
Now we have real multifrontal!
ProfFan Mar 22, 2022
d42fc21
Fully working Multifrontal
ProfFan Mar 24, 2022
1e8aae3
Add a test for EliminateSequential
ProfFan Mar 24, 2022
b4f8eea
Address comments
ProfFan Mar 24, 2022
4f8dfeb
Remove warning
ProfFan Mar 24, 2022
293ef61
Address comments
ProfFan Mar 24, 2022
a36c86a
Display debug messages only when DEBUG = true
ProfFan Mar 24, 2022
8b4283b
Add doxygen for GMM
ProfFan Mar 24, 2022
5f03e0f
Address compilation error on GCC
ProfFan Mar 24, 2022
8d88860
Fix GCC error
ProfFan Mar 24, 2022
d2dc620
Add Python bindings
ProfFan Mar 25, 2022
7f2fa61
Added more Python examples
ProfFan Mar 26, 2022
0f69b4c
Added plotting for nested dissection
ProfFan Mar 27, 2022
a9c1d43
Working iSAM for Hybrid
ProfFan Apr 1, 2022
1fe7e74
Merge remote-tracking branch 'origin/develop' into fan/prototype-hybr…
ProfFan Apr 16, 2022
2de3169
Fix compile
ProfFan Apr 20, 2022
1bf9952
Merge remote-tracking branch 'origin/develop' into fan/prototype-hybr…
ProfFan May 8, 2022
4e481ea
Fix the enable_if_t absence
ProfFan May 11, 2022
d012bcd
Remove most debug messages
ProfFan May 11, 2022
30412b8
Bump version
dellaert May 13, 2022
da00870
Merge pull request #1196 from borglab/release/4.2a7
dellaert May 16, 2022
d5fd279
Merge remote-tracking branch 'origin/develop' into fan/prototype-hybr…
ProfFan May 21, 2022
2c4990b
Address Varun's comments
ProfFan May 21, 2022
04593cc
Fix compile error
ProfFan May 21, 2022
2ae2cb6
Don't crash anymore
ProfFan May 22, 2022
b8299d7
Don't use Python dict method since it is not
ProfFan May 23, 2022
74af969
Trying to make MSVC happy
ProfFan May 23, 2022
b215d3a
Address PR comments
ProfFan May 23, 2022
e36583e
include missing headers for msvc and fix warning
varunagrawal May 24, 2022
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
1 change: 1 addition & 0 deletions gtsam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set (gtsam_subdirs
inference
symbolic
discrete
hybrid
linear
nonlinear
sam
Expand Down
8 changes: 8 additions & 0 deletions gtsam/hybrid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Install headers
set(subdir hybrid)
file(GLOB hybrid_headers "*.h")
# FIXME: exclude headers
install(FILES ${hybrid_headers} DESTINATION include/gtsam/hybrid)

# Add all tests
add_subdirectory(tests)
102 changes: 102 additions & 0 deletions gtsam/hybrid/GaussianMixture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* ----------------------------------------------------------------------------

* 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 GaussianMixture.cpp
* @brief A hybrid conditional in the Conditional Linear Gaussian scheme
* @author Fan Jiang
* @author Varun Agrawal
* @author Frank Dellaert
* @date Mar 12, 2022
*/

#include <gtsam/base/utilities.h>
#include <gtsam/discrete/DecisionTree-inl.h>
#include <gtsam/hybrid/GaussianMixture.h>
#include <gtsam/inference/Conditional-inst.h>
#include <gtsam/linear/GaussianFactorGraph.h>

namespace gtsam {

GaussianMixture::GaussianMixture(
const KeyVector &continuousFrontals, const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const GaussianMixture::Conditionals &conditionals)
: BaseFactor(CollectKeys(continuousFrontals, continuousParents),
discreteParents),
BaseConditional(continuousFrontals.size()),
conditionals_(conditionals) {}

const GaussianMixture::Conditionals &GaussianMixture::conditionals() {
return conditionals_;
}

GaussianMixture GaussianMixture::FromConditionalList(
const KeyVector &continuousFrontals, const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const std::vector<GaussianConditional::shared_ptr> &conditionalsList) {
Conditionals dt(discreteParents, conditionalsList);

return GaussianMixture(continuousFrontals, continuousParents, discreteParents,
dt);
}

/* *******************************************************************************/
GaussianMixture::Sum GaussianMixture::addTo(
const GaussianMixture::Sum &sum) const {
using Y = GaussianFactorGraph;
auto add = [](const Y &graph1, const Y &graph2) {
auto result = graph1;
result.push_back(graph2);
return result;
};
const Sum wrapped = wrappedConditionals();
return sum.empty() ? wrapped : sum.apply(wrapped, add);
}

/* *******************************************************************************/
GaussianMixture::Sum GaussianMixture::wrappedConditionals() const {
ProfFan marked this conversation as resolved.
Show resolved Hide resolved
auto wrap = [](const GaussianFactor::shared_ptr &factor) {
ProfFan marked this conversation as resolved.
Show resolved Hide resolved
GaussianFactorGraph result;
result.push_back(factor);
return result;
};
return {conditionals_, wrap};
varunagrawal marked this conversation as resolved.
Show resolved Hide resolved
}

bool GaussianMixture::equals(const HybridFactor &lf, double tol) const {
return false;
ProfFan marked this conversation as resolved.
Show resolved Hide resolved
}

void GaussianMixture::print(const std::string &s,
const KeyFormatter &formatter) const {
std::cout << s << ": ";
if (isContinuous_) std::cout << "Cont. ";
if (isDiscrete_) std::cout << "Disc. ";
if (isHybrid_) std::cout << "Hybr. ";
BaseConditional::print("", formatter);
std::cout << "Discrete Keys = ";
for (auto &dk : discreteKeys_) {
std::cout << "(" << formatter(dk.first) << ", " << dk.second << "), ";
}
std::cout << "\n";
conditionals_.print(
"", [&](Key k) { return formatter(k); },
[&](const GaussianConditional::shared_ptr &gf) -> std::string {
RedirectCout rd;
if (!gf->empty())
gf->print("", formatter);
else
return {"nullptr"};
return rd.str();
});
}
} // namespace gtsam
74 changes: 74 additions & 0 deletions gtsam/hybrid/GaussianMixture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* ----------------------------------------------------------------------------

* 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 GaussianMixture.h
* @brief A hybrid conditional in the Conditional Linear Gaussian scheme
* @author Fan Jiang
* @date Mar 12, 2022
*/

#pragma once

#include <gtsam/discrete/DecisionTree.h>
#include <gtsam/hybrid/HybridFactor.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/linear/GaussianConditional.h>

namespace gtsam {
class GaussianMixture : public HybridFactor,
public Conditional<HybridFactor, GaussianMixture> {
public:
using This = GaussianMixture;
using shared_ptr = boost::shared_ptr<GaussianMixture>;
using BaseFactor = HybridFactor;
using BaseConditional = Conditional<HybridFactor, GaussianMixture>;

using Conditionals = DecisionTree<Key, GaussianConditional::shared_ptr>;

Conditionals conditionals_;

public:
/**
* @brief Construct a new Gaussian Mixture object
*
* @param continuousFrontals the continuous frontals.
* @param continuousParents the continuous parents.
* @param discreteParents the discrete parents. Will be placed last.
* @param conditionals a decision tree of GaussianConditionals.
*/
GaussianMixture(const KeyVector &continuousFrontals,
const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const Conditionals &conditionals);

using Sum = DecisionTree<Key, GaussianFactorGraph>;

const Conditionals &conditionals();

/* *******************************************************************************/
Sum addTo(const Sum &sum) const;
ProfFan marked this conversation as resolved.
Show resolved Hide resolved

/* *******************************************************************************/
Sum wrappedConditionals() const;

static This FromConditionalList(
const KeyVector &continuousFrontals, const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const std::vector<GaussianConditional::shared_ptr> &conditionals);

bool equals(const HybridFactor &lf, double tol = 1e-9) const override;

void print(
const std::string &s = "GaussianMixture\n",
const KeyFormatter &formatter = DefaultKeyFormatter) const override;
};
} // namespace gtsam
ProfFan marked this conversation as resolved.
Show resolved Hide resolved
86 changes: 86 additions & 0 deletions gtsam/hybrid/GaussianMixtureFactor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* ----------------------------------------------------------------------------

* 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 GaussianMixtureFactor.cpp
* @brief A set of Gaussian factors indexed by a set of discrete keys.
* @author Fan Jiang
* @author Varun Agrawal
* @author Frank Dellaert
* @date Mar 12, 2022
*/

#include <gtsam/base/utilities.h>
#include <gtsam/discrete/DecisionTree-inl.h>
#include <gtsam/discrete/DecisionTree.h>
#include <gtsam/hybrid/GaussianMixtureFactor.h>
#include <gtsam/linear/GaussianFactorGraph.h>

namespace gtsam {

GaussianMixtureFactor::GaussianMixtureFactor(const KeyVector &continuousKeys,
const DiscreteKeys &discreteKeys,
const Factors &factors)
: Base(continuousKeys, discreteKeys), factors_(factors) {}
bool GaussianMixtureFactor::equals(const HybridFactor &lf, double tol) const {
return false;
}

GaussianMixtureFactor GaussianMixtureFactor::FromFactorList(
const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys,
const std::vector<GaussianFactor::shared_ptr> &factorsList) {
Factors dt(discreteKeys, factorsList);

return GaussianMixtureFactor(continuousKeys, discreteKeys, dt);
}

void GaussianMixtureFactor::print(const std::string &s,
const KeyFormatter &formatter) const {
HybridFactor::print(s, formatter);
factors_.print(
"mixture = ", [&](Key k) { return formatter(k); },
[&](const GaussianFactor::shared_ptr &gf) -> std::string {
RedirectCout rd;
if (!gf->empty())
gf->print("", formatter);
else
return {"nullptr"};
return rd.str();
});
}

const GaussianMixtureFactor::Factors &GaussianMixtureFactor::factors() {
return factors_;
}

/* *******************************************************************************/
GaussianMixtureFactor::Sum GaussianMixtureFactor::addTo(
const GaussianMixtureFactor::Sum &sum) const {
using Y = GaussianFactorGraph;
auto add = [](const Y &graph1, const Y &graph2) {
auto result = graph1;
result.push_back(graph2);
return result;
};
const Sum wrapped = wrappedFactors();
return sum.empty() ? wrapped : sum.apply(wrapped, add);
}

/* *******************************************************************************/
GaussianMixtureFactor::Sum GaussianMixtureFactor::wrappedFactors() const {
auto wrap = [](const GaussianFactor::shared_ptr &factor) {
GaussianFactorGraph result;
result.push_back(factor);
return result;
};
return {factors_, wrap};
}
} // namespace gtsam
71 changes: 71 additions & 0 deletions gtsam/hybrid/GaussianMixtureFactor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* ----------------------------------------------------------------------------

* 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 GaussianMixtureFactor.h
* @brief A set of Gaussian factors indexed by a set of discrete keys.
* @author Fan Jiang
* @author Varun Agrawal
* @author Frank Dellaert
* @date Mar 12, 2022
*/

#pragma once

#include <gtsam/discrete/DecisionTree.h>
#include <gtsam/discrete/DiscreteKey.h>
#include <gtsam/hybrid/HybridFactor.h>
#include <gtsam/linear/GaussianFactor.h>

namespace gtsam {

class GaussianFactorGraph;

typedef std::vector<gtsam::GaussianFactor::shared_ptr> GaussianFactorVector;

class GaussianMixtureFactor : public HybridFactor {
public:
using Base = HybridFactor;
using This = GaussianMixtureFactor;
using shared_ptr = boost::shared_ptr<This>;

using Factors = DecisionTree<Key, GaussianFactor::shared_ptr>;

Factors factors_;

GaussianMixtureFactor() = default;

GaussianMixtureFactor(const KeyVector &continuousKeys,
const DiscreteKeys &discreteKeys,
const Factors &factors);

using Sum = DecisionTree<Key, GaussianFactorGraph>;

const Factors &factors();

static This FromFactorList(
const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys,
const std::vector<GaussianFactor::shared_ptr> &factors);

/* *******************************************************************************/
Sum addTo(const Sum &sum) const;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this add?


/* *******************************************************************************/
Sum wrappedFactors() const;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this asGraph or a better name that directly signifies what is the intended use?


bool equals(const HybridFactor &lf, double tol = 1e-9) const override;

void print(
const std::string &s = "HybridFactor\n",
const KeyFormatter &formatter = DefaultKeyFormatter) const override;
};

} // namespace gtsam
16 changes: 16 additions & 0 deletions gtsam/hybrid/HybridBayesNet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* ----------------------------------------------------------------------------
* 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 HybridBayesNet.cpp
* @brief A bayes net of Gaussian Conditionals indexed by discrete keys.
* @author Fan Jiang
* @date January 2022
*/

#include <gtsam/hybrid/HybridBayesNet.h>
Loading