More detailed timing in EliminationTree
parent
898ca38f1c
commit
888b166787
|
@ -5,6 +5,7 @@
|
||||||
* @created Oct 13, 2010
|
* @created Oct 13, 2010
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <gtsam/base/timing.h>
|
||||||
#include <gtsam/inference/EliminationTree.h>
|
#include <gtsam/inference/EliminationTree.h>
|
||||||
#include <gtsam/inference/VariableSlots.h>
|
#include <gtsam/inference/VariableSlots.h>
|
||||||
#include <gtsam/inference/FactorGraph-inl.h>
|
#include <gtsam/inference/FactorGraph-inl.h>
|
||||||
|
@ -84,8 +85,12 @@ template<class DERIVEDFACTOR>
|
||||||
typename EliminationTree<FACTOR>::shared_ptr
|
typename EliminationTree<FACTOR>::shared_ptr
|
||||||
EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph, const VariableIndex& structure) {
|
EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph, const VariableIndex& structure) {
|
||||||
|
|
||||||
|
tic("ET 1: Create");
|
||||||
|
|
||||||
|
tic("ET 1.1: ComputeParents");
|
||||||
// Compute the tree structure
|
// Compute the tree structure
|
||||||
vector<Index> parents(ComputeParents(structure));
|
vector<Index> parents(ComputeParents(structure));
|
||||||
|
toc("ET 1.1: ComputeParents");
|
||||||
|
|
||||||
// Number of variables
|
// Number of variables
|
||||||
const size_t n = structure.size();
|
const size_t n = structure.size();
|
||||||
|
@ -93,6 +98,7 @@ EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph, c
|
||||||
static const Index none = numeric_limits<Index>::max();
|
static const Index none = numeric_limits<Index>::max();
|
||||||
|
|
||||||
// Create tree structure
|
// Create tree structure
|
||||||
|
tic("ET 1.2: assemble tree");
|
||||||
vector<shared_ptr> trees(n);
|
vector<shared_ptr> trees(n);
|
||||||
for (Index k = 1; k <= n; k++) {
|
for (Index k = 1; k <= n; k++) {
|
||||||
Index j = n - k;
|
Index j = n - k;
|
||||||
|
@ -100,8 +106,10 @@ EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph, c
|
||||||
if (parents[j] != none)
|
if (parents[j] != none)
|
||||||
trees[parents[j]]->add(trees[j]);
|
trees[parents[j]]->add(trees[j]);
|
||||||
}
|
}
|
||||||
|
toc("ET 1.2: assemble tree");
|
||||||
|
|
||||||
// Hang factors in right places
|
// Hang factors in right places
|
||||||
|
tic("ET 1.3: hang factors");
|
||||||
BOOST_FOREACH(const typename DERIVEDFACTOR::shared_ptr& derivedFactor, factorGraph) {
|
BOOST_FOREACH(const typename DERIVEDFACTOR::shared_ptr& derivedFactor, factorGraph) {
|
||||||
// Here we static_cast to the factor type of this EliminationTree. This
|
// Here we static_cast to the factor type of this EliminationTree. This
|
||||||
// allows performing symbolic elimination on, for example, GaussianFactors.
|
// allows performing symbolic elimination on, for example, GaussianFactors.
|
||||||
|
@ -109,6 +117,9 @@ EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph, c
|
||||||
Index j = factor->front();
|
Index j = factor->front();
|
||||||
trees[j]->add(factor);
|
trees[j]->add(factor);
|
||||||
}
|
}
|
||||||
|
toc("ET 1.3: hang factors");
|
||||||
|
|
||||||
|
toc("ET 1: Create");
|
||||||
|
|
||||||
// Assert that all other nodes have parents, i.e. that this is not a forest.
|
// Assert that all other nodes have parents, i.e. that this is not a forest.
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -124,7 +135,14 @@ template<class FACTOR>
|
||||||
template<class DERIVEDFACTOR>
|
template<class DERIVEDFACTOR>
|
||||||
typename EliminationTree<FACTOR>::shared_ptr
|
typename EliminationTree<FACTOR>::shared_ptr
|
||||||
EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph) {
|
EliminationTree<FACTOR>::Create(const FactorGraph<DERIVEDFACTOR>& factorGraph) {
|
||||||
return Create(factorGraph, VariableIndex(factorGraph));
|
|
||||||
|
// Build variable index
|
||||||
|
tic("ET 0: variable index");
|
||||||
|
const VariableIndex variableIndex(factorGraph);
|
||||||
|
toc("ET 0: variable index");
|
||||||
|
|
||||||
|
// Build elimination tree
|
||||||
|
return Create(factorGraph, variableIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -157,16 +175,25 @@ template<class FACTOR>
|
||||||
typename EliminationTree<FACTOR>::BayesNet::shared_ptr
|
typename EliminationTree<FACTOR>::BayesNet::shared_ptr
|
||||||
EliminationTree<FACTOR>::eliminate() const {
|
EliminationTree<FACTOR>::eliminate() const {
|
||||||
|
|
||||||
|
tic("ET 2: eliminate");
|
||||||
|
|
||||||
// call recursive routine
|
// call recursive routine
|
||||||
|
tic("ET 2.1: recursive eliminate");
|
||||||
Conditionals conditionals(this->key_ + 1);
|
Conditionals conditionals(this->key_ + 1);
|
||||||
(void)eliminate_(conditionals);
|
(void)eliminate_(conditionals);
|
||||||
|
toc("ET 2.1: recursive eliminate");
|
||||||
|
|
||||||
// Add conditionals to BayesNet
|
// Add conditionals to BayesNet
|
||||||
|
tic("ET 2.1: assemble BayesNet");
|
||||||
typename BayesNet::shared_ptr bayesNet(new BayesNet);
|
typename BayesNet::shared_ptr bayesNet(new BayesNet);
|
||||||
BOOST_FOREACH(const typename BayesNet::sharedConditional& conditional, conditionals) {
|
BOOST_FOREACH(const typename BayesNet::sharedConditional& conditional, conditionals) {
|
||||||
if(conditional)
|
if(conditional)
|
||||||
bayesNet->push_back(conditional);
|
bayesNet->push_back(conditional);
|
||||||
}
|
}
|
||||||
|
toc("ET 2.1: assemble BayesNet");
|
||||||
|
|
||||||
|
toc("ET 2: eliminate");
|
||||||
|
|
||||||
return bayesNet;
|
return bayesNet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue