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

HybridValues specify continuous then discrete #1355

Merged
merged 2 commits into from
Dec 30, 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
4 changes: 2 additions & 2 deletions gtsam/hybrid/HybridBayesNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ HybridValues HybridBayesNet::optimize() const {

// Given the MPE, compute the optimal continuous values.
GaussianBayesNet gbn = choose(mpe);
return HybridValues(mpe, gbn.optimize());
return HybridValues(gbn.optimize(), mpe);
}

/* ************************************************************************* */
Expand Down Expand Up @@ -267,7 +267,7 @@ HybridValues HybridBayesNet::sample(const HybridValues &given,
GaussianBayesNet gbn = choose(assignment);
// Sample from the Gaussian Bayes net.
VectorValues sample = gbn.sample(given.continuous(), rng);
return {assignment, sample};
return {sample, assignment};
}

/* ************************************************************************* */
Expand Down
2 changes: 1 addition & 1 deletion gtsam/hybrid/HybridBayesTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ HybridValues HybridBayesTree::optimize() const {
}

VectorValues values = optimize(mpe);
return HybridValues(mpe, values);
return HybridValues(values, mpe);
}

/* ************************************************************************* */
Expand Down
22 changes: 11 additions & 11 deletions gtsam/hybrid/HybridValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ namespace gtsam {
*/
class GTSAM_EXPORT HybridValues {
private:
// DiscreteValue stored the discrete components of the HybridValues.
DiscreteValues discrete_;

// VectorValue stored the continuous components of the HybridValues.
VectorValues continuous_;

// DiscreteValue stored the discrete components of the HybridValues.
DiscreteValues discrete_;

public:
/// @name Standard Constructors
/// @{
Expand All @@ -51,8 +51,8 @@ class GTSAM_EXPORT HybridValues {
HybridValues() = default;

/// Construct from DiscreteValues and VectorValues.
HybridValues(const DiscreteValues& dv, const VectorValues& cv)
: discrete_(dv), continuous_(cv){};
HybridValues(const VectorValues& cv, const DiscreteValues& dv)
: continuous_(cv), discrete_(dv){};

/// @}
/// @name Testable
Expand All @@ -62,15 +62,15 @@ class GTSAM_EXPORT HybridValues {
void print(const std::string& s = "HybridValues",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::cout << s << ": \n";
discrete_.print(" Discrete", keyFormatter); // print discrete components
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
bool equals(const HybridValues& other, double tol = 1e-9) const {
return discrete_.equals(other.discrete_, tol) &&
continuous_.equals(other.continuous_, tol);
return continuous_.equals(other.continuous_, tol) &&
discrete_.equals(other.discrete_, tol);
}

/// @}
Expand All @@ -96,7 +96,7 @@ class GTSAM_EXPORT HybridValues {
* the key \c j is already used.
* @param value The vector to be inserted.
* @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
* exception if the key \c j is already used.
Expand Down Expand Up @@ -130,8 +130,8 @@ class GTSAM_EXPORT HybridValues {
std::string html(
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::stringstream ss;
ss << this->discrete_.html(keyFormatter);
ss << this->continuous_.html(keyFormatter);
ss << this->discrete_.html(keyFormatter);
return ss.str();
};

Expand Down
5 changes: 3 additions & 2 deletions gtsam/hybrid/hybrid.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace gtsam {

#include <gtsam/hybrid/HybridValues.h>
class HybridValues {
gtsam::DiscreteValues discrete() const;
gtsam::VectorValues continuous() const;
gtsam::DiscreteValues discrete() const;

HybridValues();
HybridValues(const gtsam::DiscreteValues &dv, const gtsam::VectorValues &cv);
HybridValues(const gtsam::VectorValues &cv, const gtsam::DiscreteValues &dv);
void print(string s = "HybridValues",
const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
Expand Down