Merge pull request #1355 from borglab/hybridvalues-order

release/4.3a0
Varun Agrawal 2022-12-29 22:09:53 -05:00 committed by GitHub
commit 04ba19337c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 16 deletions

View File

@ -218,7 +218,7 @@ HybridValues HybridBayesNet::optimize() const {
// Given the MPE, compute the optimal continuous values. // Given the MPE, compute the optimal continuous values.
GaussianBayesNet gbn = choose(mpe); GaussianBayesNet gbn = choose(mpe);
return HybridValues(mpe, gbn.optimize()); return HybridValues(gbn.optimize(), mpe);
} }
/* ************************************************************************* */ /* ************************************************************************* */
@ -267,7 +267,7 @@ HybridValues HybridBayesNet::sample(const HybridValues &given,
GaussianBayesNet gbn = choose(assignment); GaussianBayesNet gbn = choose(assignment);
// Sample from the Gaussian Bayes net. // Sample from the Gaussian Bayes net.
VectorValues sample = gbn.sample(given.continuous(), rng); VectorValues sample = gbn.sample(given.continuous(), rng);
return {assignment, sample}; return {sample, assignment};
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -58,7 +58,7 @@ HybridValues HybridBayesTree::optimize() const {
} }
VectorValues values = optimize(mpe); VectorValues values = optimize(mpe);
return HybridValues(mpe, values); return HybridValues(values, mpe);
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -37,12 +37,12 @@ namespace gtsam {
*/ */
class GTSAM_EXPORT HybridValues { class GTSAM_EXPORT HybridValues {
private: private:
// DiscreteValue stored the discrete components of the HybridValues.
DiscreteValues discrete_;
// VectorValue stored the continuous components of the HybridValues. // VectorValue stored the continuous components of the HybridValues.
VectorValues continuous_; VectorValues continuous_;
// DiscreteValue stored the discrete components of the HybridValues.
DiscreteValues discrete_;
public: public:
/// @name Standard Constructors /// @name Standard Constructors
/// @{ /// @{
@ -51,8 +51,8 @@ class GTSAM_EXPORT HybridValues {
HybridValues() = default; HybridValues() = default;
/// Construct from DiscreteValues and VectorValues. /// Construct from DiscreteValues and VectorValues.
HybridValues(const DiscreteValues& dv, const VectorValues& cv) HybridValues(const VectorValues& cv, const DiscreteValues& dv)
: discrete_(dv), continuous_(cv){}; : continuous_(cv), discrete_(dv){};
/// @} /// @}
/// @name Testable /// @name Testable
@ -62,15 +62,15 @@ class GTSAM_EXPORT HybridValues {
void print(const std::string& s = "HybridValues", void print(const std::string& s = "HybridValues",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::cout << s << ": \n"; std::cout << s << ": \n";
discrete_.print(" Discrete", keyFormatter); // print discrete components
continuous_.print(" Continuous", continuous_.print(" Continuous",
keyFormatter); // print continuous components keyFormatter); // print continuous components
discrete_.print(" Discrete", keyFormatter); // print discrete components
}; };
/// equals required by Testable for unit testing /// equals required by Testable for unit testing
bool equals(const HybridValues& other, double tol = 1e-9) const { bool equals(const HybridValues& other, double tol = 1e-9) const {
return discrete_.equals(other.discrete_, tol) && return continuous_.equals(other.continuous_, tol) &&
continuous_.equals(other.continuous_, tol); discrete_.equals(other.discrete_, tol);
} }
/// @} /// @}
@ -96,7 +96,7 @@ class GTSAM_EXPORT HybridValues {
* the key \c j is already used. * the key \c j is already used.
* @param value The vector to be inserted. * @param value The vector to be inserted.
* @param j The index with which the value will be associated. */ * @param j The index with which the value will be associated. */
void insert(Key j, int value) { discrete_[j] = value; }; void insert(Key j, size_t value) { discrete_[j] = value; };
/** Insert a vector \c value with key \c j. Throws an invalid_argument /** Insert a vector \c value with key \c j. Throws an invalid_argument
* exception if the key \c j is already used. * exception if the key \c j is already used.
@ -130,8 +130,8 @@ class GTSAM_EXPORT HybridValues {
std::string html( std::string html(
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::stringstream ss; std::stringstream ss;
ss << this->discrete_.html(keyFormatter);
ss << this->continuous_.html(keyFormatter); ss << this->continuous_.html(keyFormatter);
ss << this->discrete_.html(keyFormatter);
return ss.str(); return ss.str();
}; };

View File

@ -6,10 +6,11 @@ namespace gtsam {
#include <gtsam/hybrid/HybridValues.h> #include <gtsam/hybrid/HybridValues.h>
class HybridValues { class HybridValues {
gtsam::DiscreteValues discrete() const;
gtsam::VectorValues continuous() const; gtsam::VectorValues continuous() const;
gtsam::DiscreteValues discrete() const;
HybridValues(); HybridValues();
HybridValues(const gtsam::DiscreteValues &dv, const gtsam::VectorValues &cv); HybridValues(const gtsam::VectorValues &cv, const gtsam::DiscreteValues &dv);
void print(string s = "HybridValues", void print(string s = "HybridValues",
const gtsam::KeyFormatter& keyFormatter = const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const; gtsam::DefaultKeyFormatter) const;