relinearization working, but currently applied to all variables

release/4.3a0
Michael Kaess 2010-01-18 22:37:44 +00:00
parent 5e15564525
commit 0e6607d160
6 changed files with 24 additions and 35 deletions

View File

@ -753,10 +753,18 @@
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders> <runAllBuilders>true</runAllBuilders>
</target> </target>
<target name="testKey.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="testISAM.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments>-j2</buildArguments> <buildArguments>-j2</buildArguments>
<buildTarget>testKey.run</buildTarget> <buildTarget>testISAM.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="testGaussianISAM.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments>-j2</buildArguments>
<buildTarget>testGaussianISAM.run</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders> <runAllBuilders>true</runAllBuilders>

View File

@ -402,11 +402,11 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
template<class Conditional> template<class Conditional>
template<class Factor> template<class Factor>
void BayesTree<Conditional>::removeTop(const boost::shared_ptr<Factor>& newFactor, void BayesTree<Conditional>::removeTop(const list<Symbol>& keys,
FactorGraph<Factor> &factors, typename BayesTree<Conditional>::Cliques& orphans) { FactorGraph<Factor> &factors, typename BayesTree<Conditional>::Cliques& orphans) {
// process each key of the new factor // process each key of the new factor
BOOST_FOREACH(const Symbol& key, newFactor->keys()) BOOST_FOREACH(const Symbol& key, keys)
try { try {
// get the clique and remove it from orphans (if it exists) // get the clique and remove it from orphans (if it exists)
sharedClique clique = (*this)[key]; sharedClique clique = (*this)[key];
@ -424,21 +424,6 @@ namespace gtsam {
} }
} }
/* ************************************************************************* */
template<class Conditional>
template<class Factor>
pair<FactorGraph<Factor>, typename BayesTree<Conditional>::Cliques>
BayesTree<Conditional>::removeTop(const FactorGraph<Factor>& newFactors) {
// Remove the contaminated part of the Bayes tree
FactorGraph<Factor> factors;
Cliques orphans;
BOOST_FOREACH(boost::shared_ptr<Factor> factor, newFactors)
this->removeTop<Factor>(factor, factors, orphans);
return make_pair(factors,orphans);
}
/* ************************************************************************* */ /* ************************************************************************* */
} }

View File

@ -174,21 +174,13 @@ namespace gtsam {
std::pair<FactorGraph<Factor>, Cliques> removePath(sharedClique clique); std::pair<FactorGraph<Factor>, Cliques> removePath(sharedClique clique);
/** /**
* Given a factor, turn "contaminated" part of the tree back into a factor graph. * Given a list of keys, turn "contaminated" part of the tree back into a factor graph.
* Factors and orphans are added to the in/out arguments. * Factors and orphans are added to the in/out arguments.
*/ */
template<class Factor> template<class Factor>
void removeTop(const boost::shared_ptr<Factor>& newFactor, void removeTop(const std::list<Symbol>& keys,
FactorGraph<Factor> &factors, Cliques& orphans); FactorGraph<Factor> &factors, Cliques& orphans);
/**
* Given a set of factors, turn "contaminated" part of the tree back into a
* factor graph and return it along with a list of orphaned subtree roots.
* Used for incrementally updating a BayesTree given new measurements (factors).
*/
template<class Factor>
std::pair<FactorGraph<Factor>, Cliques> removeTop(const FactorGraph<Factor>& newFactors);
}; // BayesTree }; // BayesTree
} /// namespace gtsam } /// namespace gtsam

View File

@ -31,7 +31,7 @@ namespace gtsam {
// Remove the contaminated part of the Bayes tree // Remove the contaminated part of the Bayes tree
FactorGraph<Factor> factors; FactorGraph<Factor> factors;
boost::tie(factors, orphans) = removeTop(newFactors); removeTop(newFactors.keys(), factors, orphans);
// add the factors themselves // add the factors themselves
factors.push_back(newFactors); factors.push_back(newFactors);

View File

@ -119,6 +119,9 @@ namespace gtsam {
void ISAM2<Conditional, Config>::update_internal(const NonlinearFactorGraph<Config>& newFactors, void ISAM2<Conditional, Config>::update_internal(const NonlinearFactorGraph<Config>& newFactors,
const Config& config, Cliques& orphans) { const Config& config, Cliques& orphans) {
// todo: updates all variables... needs to be synced with removeTop!!!
linPoint_ = expmap(linPoint_, delta_);
// add new variables // add new variables
linPoint_.insert(config); linPoint_.insert(config);
@ -126,7 +129,9 @@ namespace gtsam {
// Remove the contaminated part of the Bayes tree // Remove the contaminated part of the Bayes tree
FactorGraph<GaussianFactor> affectedFactors; FactorGraph<GaussianFactor> affectedFactors;
boost::tie(affectedFactors, orphans) = this->removeTop(newFactorsLinearized); // list<Symbol> keysToBeRemoved = newFactorsLinearized.keys(); // todo
list<Symbol> keysToBeRemoved = nonlinearFactors_.keys();
this->removeTop(keysToBeRemoved, affectedFactors, orphans);
// relinearize the affected factors ... // relinearize the affected factors ...
list<Symbol> affectedKeys = affectedFactors.keys(); list<Symbol> affectedKeys = affectedFactors.keys();
@ -172,7 +177,6 @@ namespace gtsam {
// update solution - todo: potentially expensive // update solution - todo: potentially expensive
delta_ = optimize2(*this); delta_ = optimize2(*this);
} }
template<class Conditional, class Config> template<class Conditional, class Config>

View File

@ -214,7 +214,7 @@ TEST( BayesTree, removeTop )
// Remove the contaminated part of the Bayes tree // Remove the contaminated part of the Bayes tree
FactorGraph<SymbolicFactor> factors; FactorGraph<SymbolicFactor> factors;
SymbolicBayesTree::Cliques orphans; SymbolicBayesTree::Cliques orphans;
bayesTree.removeTop<SymbolicFactor>(newFactor, factors, orphans); bayesTree.removeTop<SymbolicFactor>(newFactor->keys(), factors, orphans);
// Check expected outcome // Check expected outcome
SymbolicFactorGraph expected; SymbolicFactorGraph expected;
@ -231,7 +231,7 @@ TEST( BayesTree, removeTop )
boost::shared_ptr<SymbolicFactor> newFactor2(new SymbolicFactor("B")); boost::shared_ptr<SymbolicFactor> newFactor2(new SymbolicFactor("B"));
FactorGraph<SymbolicFactor> factors2; FactorGraph<SymbolicFactor> factors2;
SymbolicBayesTree::Cliques orphans2; SymbolicBayesTree::Cliques orphans2;
bayesTree.removeTop<SymbolicFactor>(newFactor2, factors2, orphans2); bayesTree.removeTop<SymbolicFactor>(newFactor2->keys(), factors2, orphans2);
SymbolicFactorGraph expected2; SymbolicFactorGraph expected2;
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected2, factors2)); CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected2, factors2));
SymbolicBayesTree::Cliques expectedOrphans2; SymbolicBayesTree::Cliques expectedOrphans2;
@ -252,7 +252,7 @@ TEST( BayesTree, removeTop2 )
// Remove the contaminated part of the Bayes tree // Remove the contaminated part of the Bayes tree
FactorGraph<SymbolicFactor> factors; FactorGraph<SymbolicFactor> factors;
SymbolicBayesTree::Cliques orphans; SymbolicBayesTree::Cliques orphans;
boost::tie(factors,orphans) = bayesTree.removeTop<SymbolicFactor>(newFactors); bayesTree.removeTop<SymbolicFactor>(newFactors.keys(), factors, orphans);
// Check expected outcome // Check expected outcome
SymbolicFactorGraph expected; SymbolicFactorGraph expected;