/** * @file LinearFactor.cpp * @brief Linear Factor....A Gaussian * @brief linearFactor * @author Christian Potthast */ #include #include #include "LinearFactor.h" using namespace std; namespace ublas = boost::numeric::ublas; // trick from some reading group #define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL) using namespace std; using namespace gtsam; typedef pair& mypair; /* ************************************************************************* */ LinearFactor::LinearFactor(const vector & factors) { // Create RHS vector of the right size by adding together row counts size_t m = 0; BOOST_FOREACH(shared_ptr factor, factors) m += factor->numberOfRows(); b = Vector(m); size_t pos = 0; // save last position inserted into the new rhs vector // iterate over all factors BOOST_FOREACH(shared_ptr factor, factors){ // number of rows for factor f const size_t mf = factor->numberOfRows(); // copy the rhs vector from factor to b const Vector bf = factor->get_b(); for (size_t i=0; iset_b(::sub(b,n,m)); // for every separator variable string j; Matrix A; FOREACH_PAIR(j,A,As) { if (j != key) { const size_t nj = A.size2(); // get dimension of variable cg->add(j, sub(A,0,n,0,nj)); // add a parent to conditional Gaussian lf->insert(j,sub(A,n,m,0,nj)); // insert into linear factor } } return make_pair(cg,lf); } /* ************************************************************************* */ namespace gtsam { string symbol(char c, int index) { stringstream ss; ss << c << index; return ss.str(); } } /* ************************************************************************* */