deprecated functions for backwards compatibility
also removed some edits that were tangential to the PR.release/4.3a0
parent
4877bdb4f3
commit
8e62a1405e
|
@ -71,8 +71,12 @@ bool assert_equal(const V& expected, const boost::optional<V>& actual, double to
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class V>
|
template<class V>
|
||||||
bool assert_equal(const V& expected, double tol = 1e-9) {
|
bool assert_equal(const V& expected, const boost::optional<const V&>& actual, double tol = 1e-9) {
|
||||||
return false;
|
if (!actual) {
|
||||||
|
std::cout << "actual is boost::none" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return assert_equal(expected, *actual, tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,12 +57,7 @@ DiscreteConditional::DiscreteConditional(const DecisionTreeFactor& joint,
|
||||||
/* ******************************************************************************** */
|
/* ******************************************************************************** */
|
||||||
DiscreteConditional::DiscreteConditional(const DecisionTreeFactor& joint,
|
DiscreteConditional::DiscreteConditional(const DecisionTreeFactor& joint,
|
||||||
const DecisionTreeFactor& marginal, const Ordering& orderedKeys) :
|
const DecisionTreeFactor& marginal, const Ordering& orderedKeys) :
|
||||||
BaseFactor(
|
DiscreteConditional(joint, marginal) {
|
||||||
ISDEBUG("DiscreteConditional::COUNT") ? joint : joint / marginal), BaseConditional(
|
|
||||||
joint.size()-marginal.size()) {
|
|
||||||
if (ISDEBUG("DiscreteConditional::DiscreteConditional"))
|
|
||||||
cout << (firstFrontalKey()) << endl; //TODO Print all keys
|
|
||||||
|
|
||||||
keys_.clear();
|
keys_.clear();
|
||||||
keys_.insert(keys_.end(), orderedKeys.begin(), orderedKeys.end());
|
keys_.insert(keys_.end(), orderedKeys.begin(), orderedKeys.end());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace gtsam {
|
||||||
template<class FACTORGRAPH>
|
template<class FACTORGRAPH>
|
||||||
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
|
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
|
||||||
EliminateableFactorGraph<FACTORGRAPH>::eliminateSequential(
|
EliminateableFactorGraph<FACTORGRAPH>::eliminateSequential(
|
||||||
const Eliminate& function, OptionalVariableIndex variableIndex,
|
OptionalOrderingType orderingType, const Eliminate& function,
|
||||||
OptionalOrderingType orderingType) const {
|
OptionalVariableIndex variableIndex) const {
|
||||||
if(!variableIndex) {
|
if(!variableIndex) {
|
||||||
// If no VariableIndex provided, compute one and call this function again IMPORTANT: we check
|
// If no VariableIndex provided, compute one and call this function again IMPORTANT: we check
|
||||||
// for no variable index first so that it's always computed if we need to call COLAMD because
|
// for no variable index first so that it's always computed if we need to call COLAMD because
|
||||||
|
@ -56,12 +56,12 @@ namespace gtsam {
|
||||||
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
|
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
|
||||||
EliminateableFactorGraph<FACTORGRAPH>::eliminateSequential(
|
EliminateableFactorGraph<FACTORGRAPH>::eliminateSequential(
|
||||||
const Ordering& ordering, const Eliminate& function,
|
const Ordering& ordering, const Eliminate& function,
|
||||||
OptionalVariableIndex variableIndex, OptionalOrderingType orderingType) const
|
OptionalVariableIndex variableIndex) const
|
||||||
{
|
{
|
||||||
if(!variableIndex) {
|
if(!variableIndex) {
|
||||||
// If no VariableIndex provided, compute one and call this function again
|
// If no VariableIndex provided, compute one and call this function again
|
||||||
VariableIndex computedVariableIndex(asDerived());
|
VariableIndex computedVariableIndex(asDerived());
|
||||||
return eliminateSequential(ordering, function, computedVariableIndex, orderingType);
|
return eliminateSequential(ordering, function, computedVariableIndex);
|
||||||
} else {
|
} else {
|
||||||
gttic(eliminateSequential);
|
gttic(eliminateSequential);
|
||||||
// Do elimination
|
// Do elimination
|
||||||
|
@ -81,8 +81,8 @@ namespace gtsam {
|
||||||
template<class FACTORGRAPH>
|
template<class FACTORGRAPH>
|
||||||
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
|
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
|
||||||
EliminateableFactorGraph<FACTORGRAPH>::eliminateMultifrontal(
|
EliminateableFactorGraph<FACTORGRAPH>::eliminateMultifrontal(
|
||||||
const Eliminate& function, OptionalVariableIndex variableIndex,
|
OptionalOrderingType orderingType, const Eliminate& function,
|
||||||
OptionalOrderingType orderingType) const
|
OptionalVariableIndex variableIndex) const
|
||||||
{
|
{
|
||||||
if(!variableIndex) {
|
if(!variableIndex) {
|
||||||
// If no VariableIndex provided, compute one and call this function again IMPORTANT: we check
|
// If no VariableIndex provided, compute one and call this function again IMPORTANT: we check
|
||||||
|
@ -110,12 +110,12 @@ namespace gtsam {
|
||||||
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
|
boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
|
||||||
EliminateableFactorGraph<FACTORGRAPH>::eliminateMultifrontal(
|
EliminateableFactorGraph<FACTORGRAPH>::eliminateMultifrontal(
|
||||||
const Ordering& ordering, const Eliminate& function,
|
const Ordering& ordering, const Eliminate& function,
|
||||||
OptionalVariableIndex variableIndex, OptionalOrderingType orderingType) const
|
OptionalVariableIndex variableIndex) const
|
||||||
{
|
{
|
||||||
if(!variableIndex) {
|
if(!variableIndex) {
|
||||||
// If no VariableIndex provided, compute one and call this function again
|
// If no VariableIndex provided, compute one and call this function again
|
||||||
VariableIndex computedVariableIndex(asDerived());
|
VariableIndex computedVariableIndex(asDerived());
|
||||||
return eliminateMultifrontal(ordering, function, computedVariableIndex, orderingType);
|
return eliminateMultifrontal(ordering, function, computedVariableIndex);
|
||||||
} else {
|
} else {
|
||||||
gttic(eliminateMultifrontal);
|
gttic(eliminateMultifrontal);
|
||||||
// Do elimination with given ordering
|
// Do elimination with given ordering
|
||||||
|
|
|
@ -89,7 +89,7 @@ namespace gtsam {
|
||||||
typedef boost::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
|
typedef boost::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
|
||||||
|
|
||||||
/// Typedef for an optional variable index as an argument to elimination functions
|
/// Typedef for an optional variable index as an argument to elimination functions
|
||||||
typedef const boost::optional<VariableIndex>& OptionalVariableIndex;
|
typedef boost::optional<const VariableIndex&> OptionalVariableIndex;
|
||||||
|
|
||||||
/// Typedef for an optional ordering type
|
/// Typedef for an optional ordering type
|
||||||
typedef boost::optional<Ordering::OrderingType> OptionalOrderingType;
|
typedef boost::optional<Ordering::OrderingType> OptionalOrderingType;
|
||||||
|
@ -115,9 +115,9 @@ namespace gtsam {
|
||||||
* \endcode
|
* \endcode
|
||||||
* */
|
* */
|
||||||
boost::shared_ptr<BayesNetType> eliminateSequential(
|
boost::shared_ptr<BayesNetType> eliminateSequential(
|
||||||
|
OptionalOrderingType orderingType = boost::none,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none,
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
OptionalOrderingType orderingType = boost::none) const;
|
|
||||||
|
|
||||||
/** Do sequential elimination of all variables to produce a Bayes net.
|
/** Do sequential elimination of all variables to produce a Bayes net.
|
||||||
*
|
*
|
||||||
|
@ -136,8 +136,7 @@ namespace gtsam {
|
||||||
boost::shared_ptr<BayesNetType> eliminateSequential(
|
boost::shared_ptr<BayesNetType> eliminateSequential(
|
||||||
const Ordering& ordering,
|
const Ordering& ordering,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none,
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
OptionalOrderingType orderingType = boost::none) const; // orderingType is not necessary anymore, kept for backwards compatibility
|
|
||||||
|
|
||||||
/** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not
|
/** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not
|
||||||
* provided, the ordering will be computed using either COLAMD or METIS, dependeing on
|
* provided, the ordering will be computed using either COLAMD or METIS, dependeing on
|
||||||
|
@ -156,9 +155,9 @@ namespace gtsam {
|
||||||
* \endcode
|
* \endcode
|
||||||
* */
|
* */
|
||||||
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
||||||
|
OptionalOrderingType orderingType = boost::none,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none,
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
OptionalOrderingType orderingType = boost::none) const;
|
|
||||||
|
|
||||||
/** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not
|
/** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not
|
||||||
* provided, the ordering will be computed using either COLAMD or METIS, dependeing on
|
* provided, the ordering will be computed using either COLAMD or METIS, dependeing on
|
||||||
|
@ -172,8 +171,7 @@ namespace gtsam {
|
||||||
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
||||||
const Ordering& ordering,
|
const Ordering& ordering,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none,
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
OptionalOrderingType orderingType = boost::none) const; // orderingType no longer needed
|
|
||||||
|
|
||||||
/** Do sequential elimination of some variables, in \c ordering provided, to produce a Bayes net
|
/** Do sequential elimination of some variables, in \c ordering provided, to produce a Bayes net
|
||||||
* and a remaining factor graph. This computes the factorization \f$ p(X) = p(A|B) p(B) \f$,
|
* and a remaining factor graph. This computes the factorization \f$ p(X) = p(A|B) p(B) \f$,
|
||||||
|
@ -241,7 +239,7 @@ namespace gtsam {
|
||||||
* provided one will be computed. */
|
* provided one will be computed. */
|
||||||
boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
|
boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
|
||||||
boost::variant<const Ordering&, const KeyVector&> variables,
|
boost::variant<const Ordering&, const KeyVector&> variables,
|
||||||
const Ordering& marginalizedVariableOrdering, // this no longer takes boost::none - potentially code breaking
|
const Ordering& marginalizedVariableOrdering,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none) const;
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
|
|
||||||
|
@ -271,7 +269,7 @@ namespace gtsam {
|
||||||
* provided one will be computed. */
|
* provided one will be computed. */
|
||||||
boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
|
boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
|
||||||
boost::variant<const Ordering&, const KeyVector&> variables,
|
boost::variant<const Ordering&, const KeyVector&> variables,
|
||||||
const Ordering& marginalizedVariableOrdering, // this no longer takes boost::none - potentially code breaking
|
const Ordering& marginalizedVariableOrdering,
|
||||||
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
OptionalVariableIndex variableIndex = boost::none) const;
|
OptionalVariableIndex variableIndex = boost::none) const;
|
||||||
|
|
||||||
|
@ -288,6 +286,59 @@ namespace gtsam {
|
||||||
|
|
||||||
// Access the derived factor graph class
|
// Access the derived factor graph class
|
||||||
FactorGraphType& asDerived() { return static_cast<FactorGraphType&>(*this); }
|
FactorGraphType& asDerived() { return static_cast<FactorGraphType&>(*this); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** \deprecated ordering and orderingType shouldn't both be specified */
|
||||||
|
boost::shared_ptr<BayesNetType> eliminateSequential(
|
||||||
|
const Ordering& ordering,
|
||||||
|
const Eliminate& function,
|
||||||
|
OptionalVariableIndex variableIndex,
|
||||||
|
OptionalOrderingType orderingType) const {
|
||||||
|
return eliminateSequential(ordering, function, variableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \deprecated orderingType specified first for consistency */
|
||||||
|
boost::shared_ptr<BayesNetType> eliminateSequential(
|
||||||
|
const Eliminate& function,
|
||||||
|
OptionalVariableIndex variableIndex = boost::none,
|
||||||
|
OptionalOrderingType orderingType = boost::none) const {
|
||||||
|
return eliminateSequential(orderingType, function, variableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \deprecated ordering and orderingType shouldn't both be specified */
|
||||||
|
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
||||||
|
const Ordering& ordering,
|
||||||
|
const Eliminate& function,
|
||||||
|
OptionalVariableIndex variableIndex,
|
||||||
|
OptionalOrderingType orderingType) const {
|
||||||
|
return eliminateMultifrontal(ordering, function, variableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \deprecated orderingType specified first for consistency */
|
||||||
|
boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
|
||||||
|
const Eliminate& function,
|
||||||
|
OptionalVariableIndex variableIndex = boost::none,
|
||||||
|
OptionalOrderingType orderingType = boost::none) const {
|
||||||
|
return eliminateMultifrontal(orderingType, function, variableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \deprecated */
|
||||||
|
boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
|
||||||
|
boost::variant<const Ordering&, const KeyVector&> variables,
|
||||||
|
boost::none_t,
|
||||||
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
|
OptionalVariableIndex variableIndex = boost::none) const {
|
||||||
|
return marginalMultifrontalBayesNet(variables, function, variableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \deprecated */
|
||||||
|
boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
|
||||||
|
boost::variant<const Ordering&, const KeyVector&> variables,
|
||||||
|
boost::none_t,
|
||||||
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate,
|
||||||
|
OptionalVariableIndex variableIndex = boost::none) const {
|
||||||
|
return marginalMultifrontalBayesTree(variables, function, variableIndex);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,4 +494,11 @@ namespace gtsam {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
/** \deprecated */
|
||||||
|
VectorValues GaussianFactorGraph::optimize(boost::none_t,
|
||||||
|
const Eliminate& function) const {
|
||||||
|
return optimize(function);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
|
@ -375,6 +375,12 @@ namespace gtsam {
|
||||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
|
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** \deprecated */
|
||||||
|
VectorValues optimize(boost::none_t,
|
||||||
|
const Eliminate& function = EliminationTraitsType::DefaultEliminate) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,8 +33,19 @@ string SlotEntry::toString() const {
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Scatter::Scatter(const GaussianFactorGraph& gfg) : Scatter(gfg, Ordering()) {}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Scatter::setDimensions(const GaussianFactorGraph& gfg, size_t sortStart) {
|
Scatter::Scatter(const GaussianFactorGraph& gfg,
|
||||||
|
const Ordering& ordering) {
|
||||||
|
gttic(Scatter_Constructor);
|
||||||
|
|
||||||
|
// If we have an ordering, pre-fill the ordered variables first
|
||||||
|
for (Key key : ordering) {
|
||||||
|
add(key, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, find dimensions of variables and/or extend
|
||||||
for (const auto& factor : gfg) {
|
for (const auto& factor : gfg) {
|
||||||
if (!factor)
|
if (!factor)
|
||||||
continue;
|
continue;
|
||||||
|
@ -57,30 +68,10 @@ void Scatter::setDimensions(const GaussianFactorGraph& gfg, size_t sortStart) {
|
||||||
|
|
||||||
// To keep the same behavior as before, sort the keys after the ordering
|
// To keep the same behavior as before, sort the keys after the ordering
|
||||||
iterator first = begin();
|
iterator first = begin();
|
||||||
first += sortStart;
|
first += ordering.size();
|
||||||
if (first != end()) std::sort(first, end());
|
if (first != end()) std::sort(first, end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
Scatter::Scatter(const GaussianFactorGraph& gfg) {
|
|
||||||
gttic(Scatter_Constructor);
|
|
||||||
|
|
||||||
setDimensions(gfg, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
Scatter::Scatter(const GaussianFactorGraph& gfg,
|
|
||||||
const Ordering& ordering) {
|
|
||||||
gttic(Scatter_Constructor);
|
|
||||||
|
|
||||||
// pre-fill the ordered variables first
|
|
||||||
for (Key key : ordering) {
|
|
||||||
add(key, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
setDimensions(gfg, ordering.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Scatter::add(Key key, size_t dim) {
|
void Scatter::add(Key key, size_t dim) {
|
||||||
emplace_back(SlotEntry(key, dim));
|
emplace_back(SlotEntry(key, dim));
|
||||||
|
|
|
@ -61,11 +61,6 @@ class Scatter : public FastVector<SlotEntry> {
|
||||||
void add(Key key, size_t dim);
|
void add(Key key, size_t dim);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Helper function for constructors, adds/finds dimensions of variables and
|
|
||||||
// sorts starting from sortStart
|
|
||||||
void setDimensions(const GaussianFactorGraph& gfg, size_t sortStart);
|
|
||||||
|
|
||||||
/// Find the SlotEntry with the right key (linear time worst case)
|
/// Find the SlotEntry with the right key (linear time worst case)
|
||||||
iterator find(Key key);
|
iterator find(Key key);
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
||||||
* @param ordering The ordering for elimination.
|
* @param ordering The ordering for elimination.
|
||||||
*/
|
*/
|
||||||
Marginals(const NonlinearFactorGraph& graph, const Values& solution, const Ordering& ordering, // argument order switch due to default value of factorization, potentially code breaking
|
Marginals(const NonlinearFactorGraph& graph, const Values& solution, const Ordering& ordering,
|
||||||
Factorization factorization = CHOLESKY);
|
Factorization factorization = CHOLESKY);
|
||||||
|
|
||||||
/** Construct a marginals class from a linear factor graph.
|
/** Construct a marginals class from a linear factor graph.
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
||||||
* @param ordering The ordering for elimination.
|
* @param ordering The ordering for elimination.
|
||||||
*/
|
*/
|
||||||
Marginals(const GaussianFactorGraph& graph, const Values& solution, const Ordering& ordering, // argument order switch due to default value of factorization, potentially code breaking
|
Marginals(const GaussianFactorGraph& graph, const Values& solution, const Ordering& ordering,
|
||||||
Factorization factorization = CHOLESKY);
|
Factorization factorization = CHOLESKY);
|
||||||
|
|
||||||
/** Construct a marginals class from a linear factor graph.
|
/** Construct a marginals class from a linear factor graph.
|
||||||
|
@ -97,7 +97,7 @@ public:
|
||||||
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems).
|
||||||
* @param ordering An optional variable ordering for elimination.
|
* @param ordering An optional variable ordering for elimination.
|
||||||
*/
|
*/
|
||||||
Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, const Ordering& ordering, // argument order switch due to default value of factorization, potentially code breaking
|
Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, const Ordering& ordering,
|
||||||
Factorization factorization = CHOLESKY);
|
Factorization factorization = CHOLESKY);
|
||||||
|
|
||||||
/** print */
|
/** print */
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
/** Optimize the bayes tree */
|
/** Optimize the bayes tree */
|
||||||
VectorValues optimize() const;
|
VectorValues optimize() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** Compute the Bayes Tree as a helper function to the constructor */
|
/** Compute the Bayes Tree as a helper function to the constructor */
|
||||||
|
@ -130,6 +130,19 @@ protected:
|
||||||
/** Compute the Bayes Tree as a helper function to the constructor */
|
/** Compute the Bayes Tree as a helper function to the constructor */
|
||||||
void computeBayesTree(const Ordering& ordering);
|
void computeBayesTree(const Ordering& ordering);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** \deprecated argument order changed due to removing boost::optional<Ordering> */
|
||||||
|
Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization,
|
||||||
|
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
|
||||||
|
|
||||||
|
/** \deprecated argument order changed due to removing boost::optional<Ordering> */
|
||||||
|
Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization,
|
||||||
|
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
|
||||||
|
|
||||||
|
/** \deprecated argument order changed due to removing boost::optional<Ordering> */
|
||||||
|
Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization,
|
||||||
|
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -376,19 +376,7 @@ static Scatter scatterFromValues(const Values& values, const Ordering& ordering)
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
||||||
const Values& values, const Dampen& dampen) const {
|
const Values& values, const Scatter& scatter, const Dampen& dampen) const {
|
||||||
KeyVector keys = values.keys();
|
|
||||||
Ordering defaultOrdering(keys);
|
|
||||||
return linearizeToHessianFactor(values, defaultOrdering, dampen);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
|
||||||
const Values& values, const Ordering& ordering, const Dampen& dampen) const {
|
|
||||||
gttic(NonlinearFactorGraph_linearizeToHessianFactor);
|
|
||||||
|
|
||||||
Scatter scatter = scatterFromValues(values, ordering);
|
|
||||||
|
|
||||||
// NOTE(frank): we are heavily leaning on friendship below
|
// NOTE(frank): we are heavily leaning on friendship below
|
||||||
HessianFactor::shared_ptr hessianFactor(new HessianFactor(scatter));
|
HessianFactor::shared_ptr hessianFactor(new HessianFactor(scatter));
|
||||||
|
|
||||||
|
@ -409,6 +397,24 @@ HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
||||||
return hessianFactor;
|
return hessianFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
||||||
|
const Values& values, const Ordering& order, const Dampen& dampen) const {
|
||||||
|
gttic(NonlinearFactorGraph_linearizeToHessianFactor);
|
||||||
|
|
||||||
|
Scatter scatter = scatterFromValues(values, order);
|
||||||
|
return linearizeToHessianFactor(values, scatter, dampen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
HessianFactor::shared_ptr NonlinearFactorGraph::linearizeToHessianFactor(
|
||||||
|
const Values& values, const Dampen& dampen) const {
|
||||||
|
gttic(NonlinearFactorGraph_linearizeToHessianFactor);
|
||||||
|
|
||||||
|
Scatter scatter = scatterFromValues(values);
|
||||||
|
return linearizeToHessianFactor(values, scatter, dampen);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Values NonlinearFactorGraph::updateCholesky(const Values& values,
|
Values NonlinearFactorGraph::updateCholesky(const Values& values,
|
||||||
const Dampen& dampen) const {
|
const Dampen& dampen) const {
|
||||||
|
|
|
@ -204,6 +204,13 @@ namespace gtsam {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linearize from Scatter rather than from Ordering. Made private because
|
||||||
|
* it doesn't include gttic.
|
||||||
|
*/
|
||||||
|
boost::shared_ptr<HessianFactor> linearizeToHessianFactor(
|
||||||
|
const Values& values, const Scatter& scatter, const Dampen& dampen = nullptr) const;
|
||||||
|
|
||||||
/** Serialization function */
|
/** Serialization function */
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
template<class ARCHIVE>
|
template<class ARCHIVE>
|
||||||
|
@ -211,6 +218,19 @@ namespace gtsam {
|
||||||
ar & boost::serialization::make_nvp("NonlinearFactorGraph",
|
ar & boost::serialization::make_nvp("NonlinearFactorGraph",
|
||||||
boost::serialization::base_object<Base>(*this));
|
boost::serialization::base_object<Base>(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** \deprecated */
|
||||||
|
boost::shared_ptr<HessianFactor> linearizeToHessianFactor(
|
||||||
|
const Values& values, boost::none_t, const Dampen& dampen = nullptr) const
|
||||||
|
{return linearizeToHessianFactor(values, dampen);}
|
||||||
|
|
||||||
|
/** \deprecated */
|
||||||
|
Values updateCholesky(const Values& values, boost::none_t,
|
||||||
|
const Dampen& dampen = nullptr) const
|
||||||
|
{return updateCholesky(values, dampen);}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// traits
|
/// traits
|
||||||
|
|
|
@ -128,18 +128,22 @@ VectorValues NonlinearOptimizer::solve(const GaussianFactorGraph& gfg,
|
||||||
const NonlinearOptimizerParams& params) const {
|
const NonlinearOptimizerParams& params) const {
|
||||||
// solution of linear solver is an update to the linearization point
|
// solution of linear solver is an update to the linearization point
|
||||||
VectorValues delta;
|
VectorValues delta;
|
||||||
Ordering ordering;
|
|
||||||
if (params.ordering)
|
|
||||||
ordering = *params.ordering;
|
|
||||||
|
|
||||||
// Check which solver we are using
|
// Check which solver we are using
|
||||||
if (params.isMultifrontal()) {
|
if (params.isMultifrontal()) {
|
||||||
// Multifrontal QR or Cholesky (decided by params.getEliminationFunction())
|
// Multifrontal QR or Cholesky (decided by params.getEliminationFunction())
|
||||||
delta = gfg.optimize(ordering, params.getEliminationFunction());
|
if (params.ordering)
|
||||||
|
delta = gfg.optimize(*params.ordering, params.getEliminationFunction());
|
||||||
|
else
|
||||||
|
delta = gfg.optimize(params.getEliminationFunction());
|
||||||
} else if (params.isSequential()) {
|
} else if (params.isSequential()) {
|
||||||
// Sequential QR or Cholesky (decided by params.getEliminationFunction())
|
// Sequential QR or Cholesky (decided by params.getEliminationFunction())
|
||||||
delta = gfg.eliminateSequential(ordering, params.getEliminationFunction(), boost::none,
|
if (params.ordering)
|
||||||
params.orderingType)->optimize();
|
delta = gfg.eliminateSequential(*params.ordering, params.getEliminationFunction(),
|
||||||
|
boost::none, params.orderingType)->optimize();
|
||||||
|
else
|
||||||
|
delta = gfg.eliminateSequential(params.getEliminationFunction(), boost::none,
|
||||||
|
params.orderingType)->optimize();
|
||||||
} else if (params.isIterative()) {
|
} else if (params.isIterative()) {
|
||||||
// Conjugate Gradient -> needs params.iterativeParams
|
// Conjugate Gradient -> needs params.iterativeParams
|
||||||
if (!params.iterativeParams)
|
if (!params.iterativeParams)
|
||||||
|
|
|
@ -206,6 +206,7 @@ TEST(GaussianFactorGraph, optimize_Cholesky) {
|
||||||
GaussianFactorGraph fg = createGaussianFactorGraph();
|
GaussianFactorGraph fg = createGaussianFactorGraph();
|
||||||
|
|
||||||
// optimize the graph
|
// optimize the graph
|
||||||
|
VectorValues actual1 = fg.optimize(boost::none, EliminateCholesky);
|
||||||
VectorValues actual = fg.optimize(EliminateCholesky);
|
VectorValues actual = fg.optimize(EliminateCholesky);
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
|
@ -220,6 +221,7 @@ TEST( GaussianFactorGraph, optimize_QR )
|
||||||
GaussianFactorGraph fg = createGaussianFactorGraph();
|
GaussianFactorGraph fg = createGaussianFactorGraph();
|
||||||
|
|
||||||
// optimize the graph
|
// optimize the graph
|
||||||
|
VectorValues actual1 = fg.optimize(boost::none, EliminateQR);
|
||||||
VectorValues actual = fg.optimize(EliminateQR);
|
VectorValues actual = fg.optimize(EliminateQR);
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
|
|
|
@ -198,7 +198,7 @@ TEST(NonlinearFactorGraph, UpdateCholesky) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
EXPECT(assert_equal(initial, fg.updateCholesky(initial, dampen), 1e-6));
|
EXPECT(assert_equal(initial, fg.updateCholesky(initial, boost::none, dampen), 1e-6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue