add timing info
parent
4dac37ce2b
commit
6c4546779a
|
|
@ -22,6 +22,7 @@
|
||||||
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
||||||
#include <gtsam/discrete/DiscreteJunctionTree.h>
|
#include <gtsam/discrete/DiscreteJunctionTree.h>
|
||||||
#include <gtsam/discrete/DiscreteLookupDAG.h>
|
#include <gtsam/discrete/DiscreteLookupDAG.h>
|
||||||
|
#include <gtsam/discrete/TableFactor.h>
|
||||||
#include <gtsam/inference/EliminateableFactorGraph-inst.h>
|
#include <gtsam/inference/EliminateableFactorGraph-inst.h>
|
||||||
#include <gtsam/inference/FactorGraph-inst.h>
|
#include <gtsam/inference/FactorGraph-inst.h>
|
||||||
|
|
||||||
|
|
@ -144,12 +145,15 @@ namespace gtsam {
|
||||||
EliminateForMPE(const DiscreteFactorGraph& factors,
|
EliminateForMPE(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys) {
|
const Ordering& frontalKeys) {
|
||||||
// PRODUCT: multiply all factors
|
// PRODUCT: multiply all factors
|
||||||
gttic(product);
|
gttic_(MPEProduct);
|
||||||
DiscreteFactor::shared_ptr product = factors.product();
|
DiscreteFactor::shared_ptr product = factors.product();
|
||||||
gttoc(product);
|
gttoc_(MPEProduct);
|
||||||
|
|
||||||
|
gttic_(Normalize);
|
||||||
|
|
||||||
// Normalize the product
|
// Normalize the product
|
||||||
product = Normalize(product);
|
product = Normalize(product);
|
||||||
|
gttoc_(Normalize);
|
||||||
|
|
||||||
// max out frontals, this is the factor on the separator
|
// max out frontals, this is the factor on the separator
|
||||||
gttic(max);
|
gttic(max);
|
||||||
|
|
@ -229,17 +233,19 @@ namespace gtsam {
|
||||||
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys) {
|
const Ordering& frontalKeys) {
|
||||||
// PRODUCT: multiply all factors
|
// PRODUCT: multiply all factors
|
||||||
gttic(product);
|
gttic_(product);
|
||||||
DiscreteFactor::shared_ptr product = factors.product();
|
DiscreteFactor::shared_ptr product = factors.product();
|
||||||
gttoc(product);
|
gttoc_(product);
|
||||||
|
|
||||||
|
gttic_(Normalize);
|
||||||
// Normalize the product
|
// Normalize the product
|
||||||
product = Normalize(product);
|
product = Normalize(product);
|
||||||
|
gttoc_(Normalize);
|
||||||
|
|
||||||
// sum out frontals, this is the factor on the separator
|
// sum out frontals, this is the factor on the separator
|
||||||
gttic(sum);
|
gttic_(sum);
|
||||||
DecisionTreeFactor::shared_ptr sum = product->sum(frontalKeys);
|
DecisionTreeFactor::shared_ptr sum = product->sum(frontalKeys);
|
||||||
gttoc(sum);
|
gttoc_(sum);
|
||||||
|
|
||||||
// Ordering keys for the conditional so that frontalKeys are really in front
|
// Ordering keys for the conditional so that frontalKeys are really in front
|
||||||
Ordering orderedKeys;
|
Ordering orderedKeys;
|
||||||
|
|
@ -249,10 +255,10 @@ namespace gtsam {
|
||||||
sum->keys().end());
|
sum->keys().end());
|
||||||
|
|
||||||
// now divide product/sum to get conditional
|
// now divide product/sum to get conditional
|
||||||
gttic(divide);
|
gttic_(divide);
|
||||||
auto conditional =
|
auto conditional =
|
||||||
std::make_shared<DiscreteConditional>(product, *sum, orderedKeys);
|
std::make_shared<DiscreteConditional>(product, *sum, orderedKeys);
|
||||||
gttoc(divide);
|
gttoc_(divide);
|
||||||
|
|
||||||
return {conditional, sum};
|
return {conditional, sum};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ TableFactor::TableFactor(const DiscreteKeys& dkeys,
|
||||||
*/
|
*/
|
||||||
std::vector<double> ComputeLeafOrdering(const DiscreteKeys& dkeys,
|
std::vector<double> ComputeLeafOrdering(const DiscreteKeys& dkeys,
|
||||||
const DecisionTreeFactor& dt) {
|
const DecisionTreeFactor& dt) {
|
||||||
|
gttic_(ComputeLeafOrdering);
|
||||||
std::vector<double> probs = dt.probabilities();
|
std::vector<double> probs = dt.probabilities();
|
||||||
|
gttoc_(ComputeLeafOrdering);
|
||||||
std::vector<double> ordered;
|
std::vector<double> ordered;
|
||||||
|
|
||||||
size_t n = dkeys[0].second;
|
size_t n = dkeys[0].second;
|
||||||
|
|
@ -180,12 +182,16 @@ DiscreteFactor::shared_ptr TableFactor::operator*(
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor TableFactor::toDecisionTreeFactor() const {
|
DecisionTreeFactor TableFactor::toDecisionTreeFactor() const {
|
||||||
|
gttic_(toDecisionTreeFactor);
|
||||||
DiscreteKeys dkeys = discreteKeys();
|
DiscreteKeys dkeys = discreteKeys();
|
||||||
std::vector<double> table;
|
std::vector<double> table;
|
||||||
for (auto i = 0; i < sparse_table_.size(); i++) {
|
for (auto i = 0; i < sparse_table_.size(); i++) {
|
||||||
table.push_back(sparse_table_.coeff(i));
|
table.push_back(sparse_table_.coeff(i));
|
||||||
}
|
}
|
||||||
|
gttoc_(toDecisionTreeFactor);
|
||||||
|
gttic_(toDecisionTreeFactor_Constructor);
|
||||||
DecisionTreeFactor f(dkeys, table);
|
DecisionTreeFactor f(dkeys, table);
|
||||||
|
gttoc_(toDecisionTreeFactor_Constructor);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue