made removeAndCombineFactors a function, not a method
parent
710d396d0b
commit
8d2d48d252
|
@ -205,15 +205,11 @@ FactorGraph<Factor>::findAndRemoveFactors(const string& key) {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/* find factors and remove them from the factor graph: O(n) */
|
/* find factors and remove them from the factor graph: O(n) */
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Factor>
|
template<class Factor> boost::shared_ptr<Factor>
|
||||||
typename FactorGraph<Factor>::sharedFactor
|
removeAndCombineFactors(FactorGraph<Factor>& factorGraph, const string& key)
|
||||||
FactorGraph<Factor>::removeAndCombineFactors(const string& key)
|
|
||||||
{
|
{
|
||||||
bool verbose = false;
|
vector<boost::shared_ptr<Factor> > found = factorGraph.findAndRemoveFactors(key);
|
||||||
if (verbose) cout << "FactorGraph::removeAndCombineFactors" << endl;
|
boost::shared_ptr<Factor> new_factor(new Factor(found));
|
||||||
vector<sharedFactor> found = findAndRemoveFactors(key);
|
|
||||||
sharedFactor new_factor(new Factor(found));
|
|
||||||
if (verbose) cout << "FactorGraph::removeAndCombineFactors done" << endl;
|
|
||||||
return new_factor;
|
return new_factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +221,7 @@ boost::shared_ptr<Conditional> _eliminateOne(FactorGraph<Factor>& graph, const s
|
||||||
|
|
||||||
// combine the factors of all nodes connected to the variable to be eliminated
|
// combine the factors of all nodes connected to the variable to be eliminated
|
||||||
// if no factors are connected to key, returns an empty factor
|
// if no factors are connected to key, returns an empty factor
|
||||||
boost::shared_ptr<Factor> joint_factor = graph.removeAndCombineFactors(key);
|
boost::shared_ptr<Factor> joint_factor = removeAndCombineFactors(graph,key);
|
||||||
|
|
||||||
// eliminate that joint factor
|
// eliminate that joint factor
|
||||||
boost::shared_ptr<Factor> factor;
|
boost::shared_ptr<Factor> factor;
|
||||||
|
|
|
@ -104,13 +104,6 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
std::vector<sharedFactor> findAndRemoveFactors(const std::string& key);
|
std::vector<sharedFactor> findAndRemoveFactors(const std::string& key);
|
||||||
|
|
||||||
/**
|
|
||||||
* extract and combine all the factors that involve a given node
|
|
||||||
* @param key the key for the given node
|
|
||||||
* @return the combined linear factor
|
|
||||||
*/
|
|
||||||
sharedFactor removeAndCombineFactors(const std::string& key);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Serialization function */
|
/** Serialization function */
|
||||||
|
@ -122,6 +115,15 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
}; // FactorGraph
|
}; // FactorGraph
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract and combine all the factors that involve a given node
|
||||||
|
* Put this here as not all Factors have a combine constructor
|
||||||
|
* @param key the key for the given node
|
||||||
|
* @return the combined linear factor
|
||||||
|
*/
|
||||||
|
template<class Factor> boost::shared_ptr<Factor>
|
||||||
|
removeAndCombineFactors(FactorGraph<Factor>& factorGraph, const std::string& key);
|
||||||
|
|
||||||
/** doubly templated functions */
|
/** doubly templated functions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -79,7 +79,7 @@ TEST( LinearFactorGraph, combine_factors_x1 )
|
||||||
Vector sigmas = Vector_(6, sigma1, sigma1, sigma2, sigma2, sigma3, sigma3);
|
Vector sigmas = Vector_(6, sigma1, sigma1, sigma2, sigma2, sigma3, sigma3);
|
||||||
|
|
||||||
// combine all factors
|
// combine all factors
|
||||||
LinearFactor::shared_ptr actual = fg.removeAndCombineFactors("x1");
|
LinearFactor::shared_ptr actual = removeAndCombineFactors(fg,"x1");
|
||||||
|
|
||||||
// the expected linear factor
|
// the expected linear factor
|
||||||
Matrix Al1 = Matrix_(6,2,
|
Matrix Al1 = Matrix_(6,2,
|
||||||
|
@ -141,7 +141,7 @@ TEST( LinearFactorGraph, combine_factors_x2 )
|
||||||
Vector sigmas = Vector_(4, sigma1, sigma1, sigma2, sigma2);
|
Vector sigmas = Vector_(4, sigma1, sigma1, sigma2, sigma2);
|
||||||
|
|
||||||
// combine all factors
|
// combine all factors
|
||||||
LinearFactor::shared_ptr actual = fg.removeAndCombineFactors("x2");
|
LinearFactor::shared_ptr actual = removeAndCombineFactors(fg,"x2");
|
||||||
|
|
||||||
// the expected linear factor
|
// the expected linear factor
|
||||||
Matrix Al1 = Matrix_(4,2,
|
Matrix Al1 = Matrix_(4,2,
|
||||||
|
|
|
@ -94,7 +94,7 @@ TEST( LinearFactorGraph, removeAndCombineFactors )
|
||||||
SymbolicFactorGraph fg(factorGraph);
|
SymbolicFactorGraph fg(factorGraph);
|
||||||
|
|
||||||
// combine all factors connected to x1
|
// combine all factors connected to x1
|
||||||
SymbolicFactor::shared_ptr actual = fg.removeAndCombineFactors("x1");
|
SymbolicFactor::shared_ptr actual = removeAndCombineFactors(fg,"x1");
|
||||||
|
|
||||||
list<string> keys; keys.push_back("l1"); keys.push_back("x1"); keys.push_back("x2");
|
list<string> keys; keys.push_back("l1"); keys.push_back("x1"); keys.push_back("x2");
|
||||||
SymbolicFactor expected(keys);
|
SymbolicFactor expected(keys);
|
||||||
|
|
Loading…
Reference in New Issue