release/4.3a0
Michael Kaess 2010-09-05 18:28:06 +00:00
parent dacd4b78a1
commit d850e2837c
2 changed files with 19 additions and 25 deletions

View File

@ -129,6 +129,7 @@ namespace gtsam {
return chordalBayesNet; return chordalBayesNet;
} }
// special const version used in constructor below
GaussianBayesNet _eliminate_const(const FactorGraph<GaussianFactor>& graph, CachedFactors& cached, const Ordering& ordering) { GaussianBayesNet _eliminate_const(const FactorGraph<GaussianFactor>& graph, CachedFactors& cached, const Ordering& ordering) {
// make a copy that can be modified locally // make a copy that can be modified locally
FactorGraph<GaussianFactor> graph_ignored = graph; FactorGraph<GaussianFactor> graph_ignored = graph;
@ -142,7 +143,8 @@ namespace gtsam {
/** Create a Bayes Tree from a nonlinear factor graph */ /** Create a Bayes Tree from a nonlinear factor graph */
template<class Conditional, class Config> template<class Conditional, class Config>
ISAM2<Conditional, Config>::ISAM2(const NonlinearFactorGraph<Config>& nlfg, const Ordering& ordering, const Config& config) ISAM2<Conditional, Config>::ISAM2(const NonlinearFactorGraph<Config>& nlfg, const Ordering& ordering, const Config& config)
: BayesTree<Conditional>(nlfg.linearize(config)->eliminate(ordering)), theta_(config), nonlinearFactors_(nlfg) { : BayesTree<Conditional>(nlfg.linearize(config)->eliminate(ordering)),
theta_(config), delta_(VectorConfig()), nonlinearFactors_(nlfg) {
// todo: repeats calculation above, just to set "cached" // todo: repeats calculation above, just to set "cached"
// De-referencing shared pointer can be quite expensive because creates temporary // De-referencing shared pointer can be quite expensive because creates temporary
_eliminate_const(*nlfg.linearize(config), cached_, ordering); _eliminate_const(*nlfg.linearize(config), cached_, ordering);
@ -213,7 +215,7 @@ namespace gtsam {
// Input: BayesTree(this), newFactors // Input: BayesTree(this), newFactors
//#define PRINT_STATS // todo: figures for paper, disable for timing //#define PRINT_STATS // figures for paper, disable for timing
#ifdef PRINT_STATS #ifdef PRINT_STATS
static int counter = 0; static int counter = 0;
int maxClique = 0; int maxClique = 0;
@ -286,8 +288,8 @@ namespace gtsam {
// newKeys are passed in: those variables will be forced to the end in the ordering // newKeys are passed in: those variables will be forced to the end in the ordering
set<Symbol> newKeysSet; set<Symbol> newKeysSet;
newKeysSet.insert(newKeys.begin(), newKeys.end()); newKeysSet.insert(newKeys.begin(), newKeys.end());
Ordering ordering = factors.getConstrainedOrdering(newKeysSet); Ordering ordering = factors.getConstrainedOrdering(newKeysSet); // intelligent ordering
// Ordering ordering = factors.getOrdering(); // Ordering ordering = factors.getOrdering(); // original ordering, yields in bad performance
// eliminate into a Bayes net // eliminate into a Bayes net
tic("linear_eliminate"); tic("linear_eliminate");

View File

@ -35,19 +35,15 @@ namespace gtsam {
// current linearization point // current linearization point
Config theta_; Config theta_;
// the linear solution, an update to the estimate in theta
VectorConfig delta_;
// for keeping all original nonlinear factors // for keeping all original nonlinear factors
NonlinearFactorGraph<Config> nonlinearFactors_; NonlinearFactorGraph<Config> nonlinearFactors_;
// cached intermediate results for restarting computation in the middle // cached intermediate results for restarting computation in the middle
CachedFactors cached_; CachedFactors cached_;
// the linear solution, an update to the estimate in theta
VectorConfig delta_;
VectorConfig deltaMarked_;
// variables that have been updated, requiring the corresponding factors to be relinearized
std::list<Symbol> marked_;
public: public:
/** Create an empty Bayes Tree */ /** Create an empty Bayes Tree */
@ -57,37 +53,29 @@ namespace gtsam {
ISAM2(const NonlinearFactorGraph<Config>& fg, const Ordering& ordering, const Config& config); ISAM2(const NonlinearFactorGraph<Config>& fg, const Ordering& ordering, const Config& config);
/** Destructor */ /** Destructor */
virtual ~ISAM2() { virtual ~ISAM2() {}
}
typedef typename BayesTree<Conditional>::sharedClique sharedClique; typedef typename BayesTree<Conditional>::sharedClique sharedClique;
typedef typename BayesTree<Conditional>::Cliques Cliques; typedef typename BayesTree<Conditional>::Cliques Cliques;
/** /**
* ISAM2. (update_internal provides access to list of orphans for drawing purposes) * ISAM2.
*/ */
void linear_update(const FactorGraph<GaussianFactor>& newFactors);
void find_all(sharedClique clique, std::list<Symbol>& keys, const std::list<Symbol>& marked); // helper function
void fluid_relinearization(double relinearize_threshold);
void update(const NonlinearFactorGraph<Config>& newFactors, const Config& newTheta, void update(const NonlinearFactorGraph<Config>& newFactors, const Config& newTheta,
double wildfire_threshold = 0., double relinearize_threshold = 0., bool relinearize = true); double wildfire_threshold = 0., double relinearize_threshold = 0., bool relinearize = true);
// needed to create initial estimates (note that this will be the linearization point in the next step!) // needed to create initial estimates
const Config getLinearizationPoint() const {return theta_;} const Config getLinearizationPoint() const {return theta_;}
// estimate based on incomplete delta (threshold!) // estimate based on incomplete delta (threshold!)
const Config calculateEstimate() const {return theta_.expmap(delta_);} const Config calculateEstimate() const {return theta_.expmap(delta_);}
// estimate based on full delta (note that this is based on the actual current linearization point)
// estimate based on full delta (note that this is based on the current linearization point)
const Config calculateBestEstimate() const {return theta_.expmap(optimize2(*this, 0.));} const Config calculateBestEstimate() const {return theta_.expmap(optimize2(*this, 0.));}
const std::list<Symbol>& getMarkedUnsafe() const { return marked_; }
const NonlinearFactorGraph<Config>& getFactorsUnsafe() const { return nonlinearFactors_; } const NonlinearFactorGraph<Config>& getFactorsUnsafe() const { return nonlinearFactors_; }
const Config& getThetaUnsafe() const { return theta_; }
const VectorConfig& getDeltaUnsafe() const { return delta_; }
size_t lastAffectedVariableCount; size_t lastAffectedVariableCount;
size_t lastAffectedFactorCount; size_t lastAffectedFactorCount;
size_t lastAffectedCliqueCount; size_t lastAffectedCliqueCount;
@ -98,6 +86,10 @@ namespace gtsam {
boost::shared_ptr<GaussianFactorGraph> relinearizeAffectedFactors(const std::set<Symbol>& affectedKeys) const; boost::shared_ptr<GaussianFactorGraph> relinearizeAffectedFactors(const std::set<Symbol>& affectedKeys) const;
FactorGraph<GaussianFactor> getCachedBoundaryFactors(Cliques& orphans); FactorGraph<GaussianFactor> getCachedBoundaryFactors(Cliques& orphans);
void linear_update(const FactorGraph<GaussianFactor>& newFactors);
void find_all(sharedClique clique, std::list<Symbol>& keys, const std::list<Symbol>& marked); // helper function
void fluid_relinearization(double relinearize_threshold);
}; // ISAM2 }; // ISAM2
} /// namespace gtsam } /// namespace gtsam