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

Switch to EliminateDiscrete for max-product #1362

Merged
merged 52 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
efd8eb1
Switch to EliminateDiscrete for max-product
dellaert Dec 31, 2022
dcb07fe
Test eliminate
dellaert Dec 31, 2022
4d3bbf6
HBN::evaluate
dellaert Dec 28, 2022
b772d67
refactoring variables for clarity
dellaert Dec 28, 2022
be8008e
Also print mean if no parents
dellaert Dec 31, 2022
f6f782a
Add static
dellaert Dec 31, 2022
143022c
Tiny Bayes net example
dellaert Dec 31, 2022
df4fb13
fix comment
dellaert Dec 31, 2022
4023e71
continuousSubset
dellaert Dec 31, 2022
c8008cb
tiny FG
dellaert Dec 31, 2022
b463386
Made SumFrontals a method to test
dellaert Dec 31, 2022
92e2a39
Added factor and constant and removed factors method
dellaert Jan 1, 2023
fa76d53
refactored and documented SumFrontals
dellaert Jan 1, 2023
039c9b9
Test SumFrontals
dellaert Jan 1, 2023
526da2c
Add Testable to GraphAndConstant
dellaert Jan 1, 2023
b094953
Fix compile issues after rebase
dellaert Jan 1, 2023
4cb03b3
Fix SumFrontals test
dellaert Jan 1, 2023
7ab4c3e
Change to real test
dellaert Jan 1, 2023
6483130
Print estimated marginals and ratios!
dellaert Jan 1, 2023
dbd9faf
Fix quality testing
dellaert Jan 1, 2023
3d821ec
Now test elimination in c++
dellaert Jan 1, 2023
0095f73
attempt to fix elimination
dellaert Jan 1, 2023
665cb29
Make testcase exactly 5.0 mean
dellaert Jan 1, 2023
2c7b3a2
Refactoring in elimination
dellaert Jan 1, 2023
4d313fa
Comment on constant
dellaert Jan 1, 2023
064f17b
Added two-measurement example
dellaert Jan 2, 2023
312ba5f
Synced two examples
dellaert Jan 2, 2023
7c27061
Added missing methods
dellaert Jan 2, 2023
bd8d2ea
Added error for all versions - should become logDiensity?
dellaert Jan 2, 2023
021ee1a
Deterministic example, much more generic importance sampler
dellaert Jan 2, 2023
fbfc20b
Fixed conversion arguments
dellaert Jan 2, 2023
06aed53
rename
dellaert Jan 2, 2023
f8d75ab
name change of Sum to GaussianFactorGraphTree and SumFrontals to asse…
dellaert Jan 2, 2023
12d02be
Right marginals for tiny1
dellaert Jan 2, 2023
797ac34
Same correct error with factor_z.error()
dellaert Jan 2, 2023
625977e
Example with 2 measurements agrees with importance sampling
dellaert Jan 2, 2023
c3f0469
Add mean to test
dellaert Jan 2, 2023
f726cf6
f(x0, x1, m0; z0, z1) now has constant ratios !
dellaert Jan 2, 2023
66b846f
Merge branch 'hybrid/elimination' into hybrid/test_with_evaluate
varunagrawal Jan 3, 2023
38f3209
fix GaussianConditional print test
varunagrawal Jan 3, 2023
195dddf
clean up HybridGaussianFactorGraph
varunagrawal Jan 3, 2023
47346c5
move GraphAndConstant traits definition to HybridFactor
varunagrawal Jan 3, 2023
ca1c517
remove extra print statements
varunagrawal Jan 3, 2023
7825ffd
fix tests due to change to EliminateDiscrete
varunagrawal Jan 3, 2023
f117da2
remove extra print
varunagrawal Jan 3, 2023
cb885fb
check for nullptr in HybridConditional::equals
varunagrawal Jan 3, 2023
46acba5
serialize inner_, need to test
varunagrawal Jan 3, 2023
41c73fd
comment out failing tests, need to serialize DecisionTree
varunagrawal Jan 3, 2023
e01f7e7
kill unnecessary method
varunagrawal Jan 3, 2023
9e7fcc8
make header functions as inline
varunagrawal Jan 3, 2023
3771d63
simplify HybridConditional equality check
varunagrawal Jan 3, 2023
385ae34
Merge pull request #1363 from borglab/hybrid/test_with_evaluate-2
varunagrawal Jan 3, 2023
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
14 changes: 13 additions & 1 deletion gtsam/hybrid/GaussianMixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ GaussianConditional::shared_ptr GaussianMixture::operator()(
/* *******************************************************************************/
bool GaussianMixture::equals(const HybridFactor &lf, double tol) const {
const This *e = dynamic_cast<const This *>(&lf);
return e != nullptr && BaseFactor::equals(*e, tol);
if (e == nullptr) return false;

// This will return false if either conditionals_ is empty or e->conditionals_
// is empty, but not if both are empty or both are not empty:
if (conditionals_.empty() ^ e->conditionals_.empty()) return false;
std::cout << "checking" << std::endl;
// Check the base and the factors:
return BaseFactor::equals(*e, tol) &&
conditionals_.equals(e->conditionals_,
[tol](const GaussianConditional::shared_ptr &f1,
const GaussianConditional::shared_ptr &f2) {
return f1->equals(*(f2), tol);
});
}

/* *******************************************************************************/
Expand Down
11 changes: 11 additions & 0 deletions gtsam/hybrid/HybridBayesNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ static std::mt19937_64 kRandomNumberGenerator(42);

namespace gtsam {

/* ************************************************************************* */
void HybridBayesNet::print(const std::string &s,
const KeyFormatter &formatter) const {
Base::print(s, formatter);
}

/* ************************************************************************* */
bool HybridBayesNet::equals(const This &bn, double tol) const {
return Base::equals(bn, tol);
}

/* ************************************************************************* */
DecisionTreeFactor::shared_ptr HybridBayesNet::discreteConditionals() const {
AlgebraicDecisionTree<Key> decisionTree;
Expand Down
14 changes: 5 additions & 9 deletions gtsam/hybrid/HybridBayesNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ class GTSAM_EXPORT HybridBayesNet : public BayesNet<HybridConditional> {
/// @name Testable
/// @{

/** Check equality */
bool equals(const This &bn, double tol = 1e-9) const {
return Base::equals(bn, tol);
}

/// print graph
/// GTSAM-style printing
void print(
const std::string &s = "",
const KeyFormatter &formatter = DefaultKeyFormatter) const override {
Base::print(s, formatter);
}
const KeyFormatter &formatter = DefaultKeyFormatter) const override;

/// GTSAM-style equals
bool equals(const This& fg, double tol = 1e-9) const;

/// @}
/// @name Standard Interface
/// @{
Expand Down
15 changes: 14 additions & 1 deletion gtsam/hybrid/HybridConditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ void HybridConditional::print(const std::string &s,
/* ************************************************************************ */
bool HybridConditional::equals(const HybridFactor &other, double tol) const {
const This *e = dynamic_cast<const This *>(&other);
return e != nullptr && BaseFactor::equals(*e, tol);
if (e == nullptr) return false;
varunagrawal marked this conversation as resolved.
Show resolved Hide resolved
if (auto gm = asMixture()) {
auto other = e->asMixture();
return other != nullptr && gm->equals(*other, tol);
}
if (auto gm = asGaussian()) {
auto other = e->asGaussian();
return other != nullptr && gm->equals(*other, tol);
}
if (auto gm = asDiscrete()) {
auto other = e->asDiscrete();
return other != nullptr && gm->equals(*other, tol);
}
return inner_->equals(*(e->inner_), tol);
}

} // namespace gtsam