Made specific eliminate and eliminateOne methods for SymbolicFactorGraph and GaussianFactorGraph and made them accessible from MATLAB
parent
920bb52453
commit
24111423d7
2
gtsam.h
2
gtsam.h
|
@ -903,6 +903,7 @@ class SymbolicFactorGraph {
|
||||||
void push_factor(size_t key1, size_t key2, size_t key3, size_t key4);
|
void push_factor(size_t key1, size_t key2, size_t key3, size_t key4);
|
||||||
|
|
||||||
pair<gtsam::IndexConditional*, gtsam::SymbolicFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
pair<gtsam::IndexConditional*, gtsam::SymbolicFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
||||||
|
pair<gtsam::IndexConditional*, gtsam::SymbolicFactorGraph> eliminateOne(size_t j) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <gtsam/inference/SymbolicSequentialSolver.h>
|
#include <gtsam/inference/SymbolicSequentialSolver.h>
|
||||||
|
@ -1234,6 +1235,7 @@ class GaussianFactorGraph {
|
||||||
|
|
||||||
// Inference
|
// Inference
|
||||||
pair<gtsam::GaussianConditional*, gtsam::GaussianFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
pair<gtsam::GaussianConditional*, gtsam::GaussianFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
||||||
|
pair<gtsam::GaussianConditional*, gtsam::GaussianFactorGraph> eliminateOne(size_t j) const;
|
||||||
|
|
||||||
// Building the graph
|
// Building the graph
|
||||||
void push_back(gtsam::GaussianFactor* factor);
|
void push_back(gtsam::GaussianFactor* factor);
|
||||||
|
|
|
@ -197,14 +197,11 @@ class VariableIndex;
|
||||||
* BayesNet. If the variables are not fully-connected, it is more efficient
|
* BayesNet. If the variables are not fully-connected, it is more efficient
|
||||||
* to sequentially factorize multiple times.
|
* to sequentially factorize multiple times.
|
||||||
*/
|
*/
|
||||||
std::pair<typename FactorGraph<FACTOR>::sharedConditional, FactorGraph<FactorType> >
|
std::pair<sharedConditional, FactorGraph<FactorType> > eliminate(
|
||||||
eliminate(
|
|
||||||
const std::vector<KeyType>& variables, const Eliminate& eliminateFcn,
|
const std::vector<KeyType>& variables, const Eliminate& eliminateFcn,
|
||||||
boost::optional<const VariableIndex&> variableIndex = boost::none);
|
boost::optional<const VariableIndex&> variableIndex = boost::none);
|
||||||
|
|
||||||
/** Eliminate a single variable, by calling
|
/** Eliminate a single variable, by calling FactorGraph::eliminate. */
|
||||||
* eliminate(const Graph&, const std::vector<typename Graph::KeyType>&, const typename Graph::Eliminate&, boost::optional<const VariableIndex&>)
|
|
||||||
*/
|
|
||||||
std::pair<sharedConditional, FactorGraph<FactorType> > eliminateOne(
|
std::pair<sharedConditional, FactorGraph<FactorType> > eliminateOne(
|
||||||
KeyType variable, const Eliminate& eliminateFcn,
|
KeyType variable, const Eliminate& eliminateFcn,
|
||||||
boost::optional<const VariableIndex&> variableIndex = boost::none) {
|
boost::optional<const VariableIndex&> variableIndex = boost::none) {
|
||||||
|
|
|
@ -70,6 +70,20 @@ namespace gtsam {
|
||||||
return FactorGraph<IndexFactor>::eliminateFrontals(nFrontals, EliminateSymbolic);
|
return FactorGraph<IndexFactor>::eliminateFrontals(nFrontals, EliminateSymbolic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
std::pair<SymbolicFactorGraph::sharedConditional, SymbolicFactorGraph>
|
||||||
|
SymbolicFactorGraph::eliminate(const std::vector<Index>& variables)
|
||||||
|
{
|
||||||
|
return FactorGraph<IndexFactor>::eliminate(variables, EliminateSymbolic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
std::pair<SymbolicFactorGraph::sharedConditional, SymbolicFactorGraph>
|
||||||
|
SymbolicFactorGraph::eliminateOne(Index variable)
|
||||||
|
{
|
||||||
|
return FactorGraph<IndexFactor>::eliminateOne(variable, EliminateSymbolic);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void SymbolicFactorGraph::permuteWithInverse(
|
void SymbolicFactorGraph::permuteWithInverse(
|
||||||
const Permutation& inversePermutation) {
|
const Permutation& inversePermutation) {
|
||||||
|
|
|
@ -66,6 +66,27 @@ namespace gtsam {
|
||||||
* as the eliminate function argument.
|
* as the eliminate function argument.
|
||||||
*/
|
*/
|
||||||
std::pair<sharedConditional, SymbolicFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
std::pair<sharedConditional, SymbolicFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
||||||
|
|
||||||
|
/** Factor the factor graph into a conditional and a remaining factor graph.
|
||||||
|
* Given the factor graph \f$ f(X) \f$, and \c variables to factorize out
|
||||||
|
* \f$ V \f$, this function factorizes into \f$ f(X) = f(V;Y)f(Y) \f$, where
|
||||||
|
* \f$ Y := X\V \f$ are the remaining variables. If \f$ f(X) = p(X) \f$ is
|
||||||
|
* a probability density or likelihood, the factorization produces a
|
||||||
|
* conditional probability density and a marginal \f$ p(X) = p(V|Y)p(Y) \f$.
|
||||||
|
*
|
||||||
|
* For efficiency, this function treats the variables to eliminate
|
||||||
|
* \c variables as fully-connected, so produces a dense (fully-connected)
|
||||||
|
* conditional on all of the variables in \c variables, instead of a sparse
|
||||||
|
* BayesNet. If the variables are not fully-connected, it is more efficient
|
||||||
|
* to sequentially factorize multiple times.
|
||||||
|
* Note that this version simply calls
|
||||||
|
* FactorGraph<GaussianFactor>::eliminate with EliminateSymbolic as the eliminate
|
||||||
|
* function argument.
|
||||||
|
*/
|
||||||
|
std::pair<sharedConditional, SymbolicFactorGraph> eliminate(const std::vector<Index>& variables);
|
||||||
|
|
||||||
|
/** Eliminate a single variable, by calling SymbolicFactorGraph::eliminate. */
|
||||||
|
std::pair<sharedConditional, SymbolicFactorGraph> eliminateOne(Index variable);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
|
|
|
@ -54,6 +54,20 @@ namespace gtsam {
|
||||||
return FactorGraph<GaussianFactor>::eliminateFrontals(nFrontals, EliminateQR);
|
return FactorGraph<GaussianFactor>::eliminateFrontals(nFrontals, EliminateQR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
std::pair<GaussianFactorGraph::sharedConditional, GaussianFactorGraph>
|
||||||
|
GaussianFactorGraph::eliminate(const std::vector<Index>& variables)
|
||||||
|
{
|
||||||
|
return FactorGraph<GaussianFactor>::eliminate(variables, EliminateQR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
std::pair<GaussianFactorGraph::sharedConditional, GaussianFactorGraph>
|
||||||
|
GaussianFactorGraph::eliminateOne(Index variable)
|
||||||
|
{
|
||||||
|
return FactorGraph<GaussianFactor>::eliminateOne(variable, EliminateQR);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GaussianFactorGraph::permuteWithInverse(
|
void GaussianFactorGraph::permuteWithInverse(
|
||||||
const Permutation& inversePermutation) {
|
const Permutation& inversePermutation) {
|
||||||
|
@ -511,9 +525,6 @@ break;
|
||||||
GaussianFactorGraph::EliminationResult EliminatePreferCholesky(
|
GaussianFactorGraph::EliminationResult EliminatePreferCholesky(
|
||||||
const FactorGraph<GaussianFactor>& factors, size_t nrFrontals) {
|
const FactorGraph<GaussianFactor>& factors, size_t nrFrontals) {
|
||||||
|
|
||||||
typedef JacobianFactor J;
|
|
||||||
typedef HessianFactor H;
|
|
||||||
|
|
||||||
// If any JacobianFactors have constrained noise models, we have to convert
|
// If any JacobianFactors have constrained noise models, we have to convert
|
||||||
// all factors to JacobianFactors. Otherwise, we can convert all factors
|
// all factors to JacobianFactors. Otherwise, we can convert all factors
|
||||||
// to HessianFactors. This is because QR can handle constrained noise
|
// to HessianFactors. This is because QR can handle constrained noise
|
||||||
|
|
|
@ -123,6 +123,27 @@ namespace gtsam {
|
||||||
* eliminate function argument.
|
* eliminate function argument.
|
||||||
*/
|
*/
|
||||||
std::pair<sharedConditional, GaussianFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
std::pair<sharedConditional, GaussianFactorGraph> eliminateFrontals(size_t nFrontals) const;
|
||||||
|
|
||||||
|
/** Factor the factor graph into a conditional and a remaining factor graph.
|
||||||
|
* Given the factor graph \f$ f(X) \f$, and \c variables to factorize out
|
||||||
|
* \f$ V \f$, this function factorizes into \f$ f(X) = f(V;Y)f(Y) \f$, where
|
||||||
|
* \f$ Y := X\V \f$ are the remaining variables. If \f$ f(X) = p(X) \f$ is
|
||||||
|
* a probability density or likelihood, the factorization produces a
|
||||||
|
* conditional probability density and a marginal \f$ p(X) = p(V|Y)p(Y) \f$.
|
||||||
|
*
|
||||||
|
* For efficiency, this function treats the variables to eliminate
|
||||||
|
* \c variables as fully-connected, so produces a dense (fully-connected)
|
||||||
|
* conditional on all of the variables in \c variables, instead of a sparse
|
||||||
|
* BayesNet. If the variables are not fully-connected, it is more efficient
|
||||||
|
* to sequentially factorize multiple times.
|
||||||
|
* Note that this version simply calls
|
||||||
|
* FactorGraph<GaussianFactor>::eliminate with EliminateQR as the eliminate
|
||||||
|
* function argument.
|
||||||
|
*/
|
||||||
|
std::pair<sharedConditional, GaussianFactorGraph> eliminate(const std::vector<Index>& variables);
|
||||||
|
|
||||||
|
/** Eliminate a single variable, by calling GaussianFactorGraph::eliminate. */
|
||||||
|
std::pair<sharedConditional, GaussianFactorGraph> eliminateOne(Index variable);
|
||||||
|
|
||||||
/** Permute the variables in the factors */
|
/** Permute the variables in the factors */
|
||||||
void permuteWithInverse(const Permutation& inversePermutation);
|
void permuteWithInverse(const Permutation& inversePermutation);
|
||||||
|
|
Loading…
Reference in New Issue